[cc65] Using asm inline assembly as part of expression

From: Stefan <vorsichtphysiker1gmx.net>
Date: 2013-01-13 21:21:40
I have a for loop in my program (Used for a variable amount of nested 
loops):
for(*indexarr=0;(++(*indexarr))<=(*max); ){..}

which results in the following code when compiled with -Oirs:

000066r 1  B1 rr            lda     (sp),y
000068r 1  85 rr            sta     ptr1+1
00006Ar 1  88               dey
00006Br 1  B1 rr            lda     (sp),y
00006Dr 1  85 rr            sta     ptr1
00006Fr 1  98               tya
000070r 1  A8               tay
000071r 1  91 rr            sta     (ptr1),y
000073r 1  C8               iny
000074r 1  91 rr            sta     (ptr1),y
000076r 1  A0 01        L0009:    ldy     #$01
000078r 1  B1 rr            lda     (sp),y
00007Ar 1  AA               tax
00007Br 1  88               dey
00007Cr 1  B1 rr            lda     (sp),y
00007Er 1  20 rr rr         jsr     pushax
000081r 1  85 rr            sta     ptr1
000083r 1  86 rr            stx     ptr1+1
000085r 1  A0 01            ldy     #$01
000087r 1  B1 rr            lda     (ptr1),y
000089r 1  AA               tax
00008Ar 1  88               dey
00008Br 1  B1 rr            lda     (ptr1),y
00008Dr 1  18               clc
00008Er 1  69 01            adc     #$01
000090r 1  90 01            bcc     L0042
000092r 1  E8               inx
000093r 1  20 rr rr     L0042:    jsr     staxspidx
000096r 1  20 rr rr         jsr     pushax
000099r 1  A0 05            ldy     #$05
00009Br 1  B1 rr            lda     (sp),y
00009Dr 1  85 rr            sta     ptr1+1
00009Fr 1  88               dey
0000A0r 1  B1 rr            lda     (sp),y
0000A2r 1  85 rr            sta     ptr1
0000A4r 1  A0 01            ldy     #$01
0000A6r 1  B1 rr            lda     (ptr1),y
0000A8r 1  AA               tax
0000A9r 1  88               dey
0000AAr 1  B1 rr            lda     (ptr1),y
0000ACr 1  20 rr rr         jsr     tosicmp
0000AFr 1  90 03            bcc     L0043
0000B1r 1  4C rr rr         jmp     incsp4
0000B4r 1  A0 03        L0043:    ldy     #$03
0000B6r 1  

This works in principle, but the compiled code is very ineffective.

Using the inline assembler i want to avoid the unnecessary transfer of *sp 
to *ptr1 like for example:

asm("ldy #%o", indexarr),
asm("lda #0"),
asm("sta (sp),y"),
asm("iny"),
asm("sta (sp),y");

to set *indexarr to zero.

Up to this point it works out. When trying to do that with the comparison, 
i get 
the error message "cannot convert from void to something else".

(unsigned int*) ( asm("ldy #%o", indexarr),
asm("inc (sp),y"),
asm("bne @l0"),
asm("iny"),
asm("inc (sp),y"),
asm("@l0:"),
asm("lda (sp),y"),
asm("tax"),
asm("dey"),
asm("lda (sp),y") /* Result is now in __AX__*/
<(*max); )

As far i understand from the manual, an asm statement is always of type 
void and can be part of an expression. This is, what i don't understand:

- If the asm statement is of type void and i cannot convert it to another 
type, how can it be part of an expression ? Is this a contradiction or am i 
wrong?
- What is the right ways of using asm statements as an part of an 
expression?

Yours Monte Carlos

    

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Jan 13 21:26:55 2013

This archive was generated by hypermail 2.1.8 : 2013-01-13 21:27:00 CET