I am unfortunately not familiar enough with inline assembly in SDCC to know whether there is a convenient way to read C arguments from asm blocks, but when in doubt, you can always look up where the calling convention puts that argument and read it from there, i.e from the appropriate register or stack location.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Registers vs. stack vs. other ways depends on the target architecture (and the use of the --sdcccall option, and keywords that modify the calling convention; see the manual sections about the calling conventions).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So I found out that the argument is passed through the A register, at least the first one, if 8 bits.
Variables can be access by adding an underscore to their name.
Only if it's a global variable.
charvar=0b000001000;voidfon(chararg){arg;/*justtoskipthemessage:"warning 85: in function fon unreferencedfunctionargument:'arg'" */__asm;registerAalreadycontains"arg";"var"iscopiedintoit.ldA,_var__endasm;}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
How can I read a C argument in ASM ? And vice versa.
I get this error:
Version:
Last edit: joe 2023-09-27
I am unfortunately not familiar enough with inline assembly in SDCC to know whether there is a convenient way to read C arguments from asm blocks, but when in doubt, you can always look up where the calling convention puts that argument and read it from there, i.e from the appropriate register or stack location.
It's not via registers like in GNU C. Looking at the examples in the SDDC manual you just have to add a underscore to the argument. "arg" => "_arg".
But it doesn't work. Perhaps something to add in the compilation line ?
Registers vs. stack vs. other ways depends on the target architecture (and the use of the --sdcccall option, and keywords that modify the calling convention; see the manual sections about the calling conventions).
So I found out that the argument is passed through the A register, at least the first one, if 8 bits.
Variables can be access by adding an underscore to their name.
Only if it's a global variable.
The simplest way to find this out is to create a dummy function that uses the argument and look at the generated asm.