Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#asm/#endasm cannot be used in a macro #1804

Closed
Oleg-N-Cher opened this issue Jun 6, 2021 · 7 comments
Closed

#asm/#endasm cannot be used in a macro #1804

Oleg-N-Cher opened this issue Jun 6, 2021 · 7 comments

Comments

@Oleg-N-Cher
Copy link

Dear z88dk developers,
When working on zcc, I came across its difference from SDCC. In particular, zcc has constructs #asm/#endasm, whereas in SDCC they are designated __asm/__endasm

There is nothing wrong with this difference, but let's say I need to develop a macro that will implement a single machine command (for example, HALT). In SDCC I can wrote:

#define WAITSYNC __asm halt __endasm

And it will work.

Whereas, a similar macro containing a service symbol # will not work in zcc:

#define WAITSYNC #asm halt #endasm

Maybe I certainly do not understand something or have not studied the documentation well. In that case, correct me. However, if I am right, I would like to request such possibility. The simplest thing is to make the __asm/__endasm directives available in zcc as synonyms of #asm/#endasm.

Thank you.

@zx70
Copy link
Member

zx70 commented Jun 6, 2021

I think this hint will work for your needs:

#define M_INP(port) asm("ld\tbc,"#port"\nin\tl,(c)\nld\th,0\n");

@suborb
Copy link
Member

suborb commented Jun 6, 2021

sdcc uses a bit of nasty "hack" to get __asm/__endasm to work in macros: #1268

Thankfully as Stefano pointed out there's an alternative which is using the asm("") function style invocation. Although the tree is using asm(), __asm__() works with both compilers. There's a multi-line example of the usage here: https://github.com/z88dk/z88dk/blob/master/include/_DEVELOPMENT/proto/im2.h#L23

@Oleg-N-Cher
Copy link
Author

Thank you, guys. Yes, it will really help me.

Why is the \t symbol so widely used inside? Can there be a space? (this will be more visual).

@Oleg-N-Cher
Copy link
Author

P.S. zcc doesn't compile this:

do{ __asm defb 12h __endasm; }while(0) ;

Bolder16K.c:75:20: fatal error: Unknown symbol: __asm
Compilation aborted

suborb, you wrote here (#1268 (comment)) that it must works for -compiler=sccz80

Where am I wrong? Or do I just need to update the z88dk?

@Oleg-N-Cher
Copy link
Author

Please, answer: can I declare an aligned array in zcc?
SDCC allows such construction. but zcc looks like not.

unsigned char __at(0xFF00) Rsrc_field [256];

@suborb
Copy link
Member

suborb commented Jun 7, 2021

Please, answer: can I declare an aligned array in zcc?
SDCC allows such construction. but zcc looks like not.

unsigned char __at(0xFF00) Rsrc_field [256];

sccz80 is a bit picky about the order it seems, try moving the __at:

extern __at(0x4000) char x[200];

@Oleg-N-Cher
Copy link
Author

Thank you very much for the useable hint, suborb.
I think I can close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants