From: Greg Long (greg_at_maneuveringspeed.com)
Date: 2003-03-08 06:17:03
Playing around to learn using C and Assembly together, it occurred to me it would be nice to have a hexout routine I can call both from C and from Assembly. Note the C code calls the assembly code. The code is not ideal, but that's not the point here. I'm using the c64 cassette buffer as an area to communicate between assembly and C, which works for now. The problem is, in this example, hexoutchr label is not inserted into the assembly code at compile time. I am NOT using -O to optimize. As you can tell, I was able to successfully use labels together, but there are issues: they seem to not completely ignore whitespace...I found deleting tabs after the "bcc hexoutchr1" line enabled it to resolve as local and not external (the latter of which generated an error). .c file first, .s file to follow: //source char hexout_char(unsigned char c) { POKE(998,c); asm("jsr hexoutchr"); return 0; //first digit asm("hexoutchr: nop"); asm(" lda 998 "); asm(" lsr "); asm(" lsr "); asm(" lsr "); asm(" lsr "); asm(" ora #48 "); asm(" cmp #58 "); asm(" bcc hexoutchr1"); asm(" clc "); asm(" adc #7 "); asm("hexoutchr1: jsr $ffd2"); //second digit asm(" lda 998 "); asm(" and #15 "); asm(" ora #48 "); asm(" cmp #58 "); asm(" bcc hexoutchr2"); asm(" clc "); asm(" adc #7 "); asm("hexoutchr2: jsr $ffd2 "); asm(" rts "); } //end source ; --------------------------------------------------------------- ; unsigned char hexout_char (unsigned char) ; --------------------------------------------------------------- .segment "CODE" .proc _hexout_char ldy #$00 lda (sp),y sta $03E6 jsr hexoutchr ldx #$00 lda #$00 jmp L0166 nop ;NOTE MISSING LABEL 'hexoutchr' here. lda 998 lsr lsr lsr lsr ora #48 cmp #58 bcc hexoutchr1 clc adc #7 hexoutchr1: jsr $ffd2 lda 998 and #15 ora #48 cmp #58 bcc hexoutchr2 clc adc #7 hexoutchr2: jsr $ffd2 rts L0166: jsr incsp1 rts .endproc ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2003-03-08 06:18:03 CET