Z88DK — Mixing C Asm — How to
Some incredibly short notes to remind me how to mix C and ASM together in the same project using Z88DK for my RC2014. I have yet to work out how to pass parameters or return data.
Some of this information came from the RC2014 Z88DK wiki page.
The C File
You need this code at the top to set ORG to 0x8000
#pragma output CRT_ORG_CODE = 0x8000
#pragma output CRT_REGISTER_SP = 0xFC00
And the Asm function you want to call needs an extern like this
extern void oled_init();
The ASM File
The top of the ASM file needs to look like this. I found this mentioned in this example file.
SECTION code_userPUBLIC _oled_init
Followed by the function
_oled_init:
call reset
ld HL, SEQUENCE
... etc ...
They need the leading underscores, I don’t yet know why.
Compiling
Compiling is like this
zcc +rc2014 -subtype=basic -clib=sdcc_iy -v -m -SO3 --max-allocs-per-node200000 --c-code-in-asm --list @sources.lst -o whatever -create-app
- +rc2014 for the RC2014
- -subtype=basic for the BASIC or SCM ROM
- -clib=sdcc_iy for stdio
- -SO3 –max-allocs-per-node200000 is optimisation stuff
- –c-code-in-asm does something that can be removed
- @sources.lst is a file containing each source file to be compiled
- -create-app creates an Intel HEX dump, paste it into the RC2014 terminal
Here’s my RC2014 enabling the Quazar OLED Interface using ASM routines, but called from a C program