The z80 has In/out instructions that should be possible to inline with standard c sources in order to develop efficient code.
the __asm command is of reduced use when the port or the value have to be taken by the c environment
Other compilers use special instructions/functions that the compiler replaces by out/in outir/inir
could this be added to sdcc ?
I was trying to implement a macro using #define and ___asm___ but apparently there is no way to pass define parameters into asm code
You can place variables in the named address space __sfr (see section 3.5.2 in the manual). SDCC will use out/in to access them.
Last edit: Philipp Klaus Krause 2022-02-28
Thanks ! Does it support also outir and inir?
Currently, the code generation only uses in and out, no ini, ind, inir, indr, outi, outd, outir or outdr. It does use both variants of in and out, though.
I see also the the sfr solution cannot have the port number as a variable...
This statement
__sfr __at 0x98 DataPort;
does not accept a port number from a C variable
The correct way to handle this would be to have a pointer to I/O-space (so you could cast your variable to that pointer type). Unfortunately, that currently doesn't work:
https://sourceforge.net/p/sdcc/bugs/3160/
When that issue gets fixed, outi / outir / ini / inir might then be used to make the access more efficient.
Last edit: Philipp Klaus Krause 2022-03-01
Would it be possible, in general, to allow inline functions where the pre-compiler is able to replace strings or other parameters in the ASM statement?
I was trying something like this:
The macro fails, as the pre-compiler is not able to replace strings within the __asm__ instructions. I know that the above macro would give errors for non constants parameters, but it would simplify some loops I have now and the overhead of a function call would almost double the CPU cost of the action.
This is another a possible example: I need to access to banked data and I need to use the bank number. In asm it goes like this:
where DataLevelMap is a label in a different bank. I would like to define a small macro where the string "DataLevelMap" can be replaced with any other banked label.
I would define a macro like this:
The above macro fails, as the pre-compiler is not able to replace strings within the __asm__ instructions. The overhead of a function call would almost double the CPU cost of the action.
Are there workarounds?
Last edit: Maarten Brock 2022-03-07
Maybe use assembly macros? That will definitely ruin
jrcalled as
Or put them in an assembly file and include it in a header.
I don’t know if there is a better solution, I usually don’t mix assembly and C.
Diff: