1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-30 09:57:11 +00:00
kickc/src/test/ref/strip.asm

114 lines
1.7 KiB
NASM
Raw Normal View History

// Tests of strip() function from https://news.ycombinator.com/item?id=12080871
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label screen = 6
main: {
2020-02-23 08:44:36 +00:00
// strip(msg1, ' ')
ldx #' '
lda #<msg1
sta.z strip.dest
lda #>msg1
sta.z strip.dest+1
jsr strip
2020-02-23 08:44:36 +00:00
// print(msg1)
lda #<$400
sta.z screen
lda #>$400
sta.z screen+1
lda #<msg1
sta.z print.msg
lda #>msg1
sta.z print.msg+1
jsr print
2020-02-23 08:44:36 +00:00
// strip(msg2, 'y')
ldx #'y'
lda #<msg2
sta.z strip.dest
lda #>msg2
sta.z strip.dest+1
jsr strip
2020-02-23 08:44:36 +00:00
// print(msg2)
lda #<msg2
sta.z print.msg
lda #>msg2
sta.z print.msg+1
jsr print
2020-02-23 08:44:36 +00:00
// }
rts
}
// strip(byte* zp(8) p, byte register(X) c)
strip: {
.label dest = 2
.label p = 8
.label p_1 = 4
lda.z dest
sta.z p_1
lda.z dest+1
sta.z p_1+1
__b1:
2020-02-23 08:44:36 +00:00
// if(*p!=c)
txa
ldy #0
cmp (p_1),y
beq __b2
2020-02-23 08:44:36 +00:00
// *dest++=*p
lda (p_1),y
sta (dest),y
2020-02-23 08:44:36 +00:00
// *dest++=*p;
inc.z dest
bne !+
inc.z dest+1
!:
__b2:
2020-02-23 08:44:36 +00:00
// while(*p++!=0)
lda.z p_1
clc
adc #1
sta.z p
lda.z p_1+1
adc #0
sta.z p+1
ldy #0
lda (p_1),y
cmp #0
bne __b4
2020-02-23 08:44:36 +00:00
// }
rts
__b4:
lda.z p
sta.z p_1
lda.z p+1
sta.z p_1+1
jmp __b1
}
// print(byte* zp(4) msg)
print: {
.label msg = 4
__b1:
// *screen++ = *msg++
ldy #0
lda (msg),y
sta (screen),y
// *screen++ = *msg++;
inc.z screen
bne !+
inc.z screen+1
!:
inc.z msg
bne !+
inc.z msg+1
!:
// while(*msg!=0)
ldy #0
lda (msg),y
cmp #0
bne __b1
// }
rts
}
msg1: .text "hello world!"
.byte 0
msg2: .text "goodbye blue sky!"
.byte 0