Mmmm acording to documentation, the L register is used when returning 8-bit values from functions.
And the following code seems to confirm it:
Code: Select all
// zcc +zx --list --c-code-in-asm main.c -o main -create-app
#include <stdint.h>
uint8_t return_twice( uint8_t a ) {
return a*2;
}
void main( void ) {
uint8_t a;
a = return_twice(17);
}
Looking at the .c.lis file generated, the computed value is stored in L at the end of the function:
Code: Select all
5 ; Function return_twice flags 0x00000200 __smallc
5 ; unsigned char uint8_treturn_twice(unsigned char a)
5 ; parameter 'unsigned char a' at sp+2 size(1)
5 C_LINE 5,"main.c::return_twice::0::0"
main.c::return_twice::0::0:
5 ._return_twice
5 C_LINE 5,"main.c::return_twice::0::0"
5 ; return a*2;
5 C_LINE 6,"main.c::return_twice::1::1"
main.c::return_twice::1::1:
6 C_LINE 6,"main.c::return_twice::1::1"
6 0000 210200 ld hl,2 ;const
6 0003 39 add hl,sp
6 0004 6e ld l,(hl)
6 0005 2600 ld h,0
6 0007 29 add hl,hl
6 0008 2600 ld h,0
6 000a c9 ret
And the return value it is received (and used) in main:
Code: Select all
9 ; Function main flags 0x00000000 __stdc
9 ; void main()
9 C_LINE 9,"main.c::main::0::2"
main.c::main::0::2:
9 ._main
9 C_LINE 9,"main.c::main::0::2"
9 ; uint8_t a;
9 C_LINE 10,"main.c::main::1::3"
main.c::main::1::3:
10 C_LINE 10,"main.c::main::1::3"
10 ; a = return_twice(17);
10 C_LINE 11,"main.c::main::1::3"
11 C_LINE 11,"main.c::main::1::3"
11 000b 3b dec sp
11 000c 210000 ld hl,0 ;const
11 000f 39 add hl,sp
11 0010 e5 push hl
11 ;17;
11 C_LINE 12,"main.c::main::1::3"
12 0011 211100 ld hl,17 ;const
12 0014 e5 push hl
12 0015 cd0000 call _return_twice
12 0018 c1 pop bc
12 0019 d1 pop de
12 001a 7d ld a,l
12 001b 12 ld (de),a
12 ;}
12 001c 33 inc sp
12 001d c9 ret
So what is exactly your problem?