cc65 - mixing C and assembler

2 posts / 0 new
Last post
Last seen: 7 years 6 months ago
Joined: Jul 16 2006 - 17:30
Posts: 81
cc65 - mixing C and assembler

I have some questions about the cc65 compiler, and how to mix C and assembler. I have taken a routine written in assembler, and "encapsulated" it in a C function. But some things are a bit tricky...

1) according to the documentation for the inline assembler, one can use the format specifier %o to reference a local variable in the stack. But it does not mention how to access that variable. I looked at the assembler code from a compiled C function, and saw that this C code:

char Temp2, Temp3;
void myfunc(char arg1, char arg2) {
Temp2 = arg1;
Temp3 = arg2;

generates the following assembler code:

ldy #$01
ldx #$00
lda (sp),y
sta _Temp2
ldy #$00
ldx #$00
lda (sp),y
sta _Temp3

Now, first of all, where did this "sp" variable come from? And second, how come the X register must be loaded? Isn't the effective address of the operator simply (sp)+Y in this mode?

2) In my assembler code, I want to declare a global pointer in the zero page, so that I can use indirect addressing with it, like this:

asm("ora (%b, X)", Temp_l);

How do I do that? If I just declare the pointer, I get an error message from the cc65 compiler saying that the addressing mode is illegal (which is true if the pointer isn't in the zero page).

Any help is apppreciated, and will be generously rewarded... Wink

Last seen: 8 years 3 months ago
Joined: Apr 10 2006 - 20:01
Posts: 1013
You may wish to ask your ques

You may wish to ask your question on comp.sys.apple2.programmer - Ullrich von Bassewitz has been answering questions there recently.

Log in or register to post comments