BigEd wrote:
Welcome!
It looks like the answers can be found in the cc65 wiki:
which has an example, and explains that the callee must clean up the parameter stack.
You need to use the zeropage pointer 'sp', as explained:
Quote:
The runtime zeropage locations used by the compiler are declared in the assembler include file zeropage.inc.
-
Using runtime zeropage locations in assembly language(BTW you wrote 'cc65 simulator' but meant to write 'cc65 compiler')
Thanks for your answer I tried implementing that snippet before too but I did not get the expected result.
My C code:
#include<stdio.h>
#include<stdint.h>
uint8_t cdecl foo(uint8_t bar);
int main() {
uint8_t p = foo(5);
printf("%u\n",p);
return 0;
}
My 6502 code:
.export _foo
.importzp sp, sreg, regsave
LDY #2
LDA (sp),Y
TAX
DEY
LDA (sp),Y
I always get the result as
255Maybe something wrong in my C code?