mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 19:29:50 +00:00
fix byte/word add/sub mixup
This commit is contained in:
parent
3f4050c647
commit
6394841041
@ -1775,8 +1775,20 @@ $endLabel""")
|
||||
throw AssemblyError("remainder of signed integers is not properly defined/implemented, use unsigned instead")
|
||||
out(" jsr prog8_lib.remainder_ub")
|
||||
}
|
||||
"+" -> out(" jsr prog8_lib.add_w")
|
||||
"-" -> out(" jsr prog8_lib.sub_w")
|
||||
"+" -> out("""
|
||||
lda $ESTACK_LO_PLUS2_HEX,x
|
||||
clc
|
||||
adc $ESTACK_LO_PLUS1_HEX,x
|
||||
inx
|
||||
sta $ESTACK_LO_PLUS1_HEX,x
|
||||
""")
|
||||
"-" -> out("""
|
||||
lda $ESTACK_LO_PLUS2_HEX,x
|
||||
sec
|
||||
sbc $ESTACK_LO_PLUS1_HEX,x
|
||||
inx
|
||||
sta $ESTACK_LO_PLUS1_HEX,x
|
||||
""")
|
||||
"<<" -> throw AssemblyError("<< should not operate via stack")
|
||||
">>" -> throw AssemblyError(">> should not operate via stack")
|
||||
"<" -> out(if(types==DataType.UBYTE) " jsr prog8_lib.less_ub" else " jsr prog8_lib.less_b")
|
||||
@ -1805,20 +1817,8 @@ $endLabel""")
|
||||
throw AssemblyError("remainder of signed integers is not properly defined/implemented, use unsigned instead")
|
||||
out(" jsr prog8_lib.remainder_uw")
|
||||
}
|
||||
"+" -> out("""
|
||||
lda $ESTACK_LO_PLUS2_HEX,x
|
||||
clc
|
||||
adc $ESTACK_LO_PLUS1_HEX,x
|
||||
inx
|
||||
sta $ESTACK_LO_PLUS1_HEX,x
|
||||
""")
|
||||
"-" -> out("""
|
||||
lda $ESTACK_LO_PLUS2_HEX,x
|
||||
sec
|
||||
sbc $ESTACK_LO_PLUS1_HEX,x
|
||||
inx
|
||||
sta $ESTACK_LO_PLUS1_HEX,x
|
||||
""")
|
||||
"+" -> out(" jsr prog8_lib.add_w")
|
||||
"-" -> out(" jsr prog8_lib.sub_w")
|
||||
"<<" -> throw AssemblyError("<< should not operate via stack")
|
||||
">>" -> throw AssemblyError(">> should not operate via stack")
|
||||
"<" -> out(if(types==DataType.UWORD) " jsr prog8_lib.less_uw" else " jsr prog8_lib.less_w")
|
||||
|
142
examples/test.p8
142
examples/test.p8
@ -1,136 +1,34 @@
|
||||
%import c64flt
|
||||
%zeropage basicsafe
|
||||
%option enable_floats
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
byte bvar
|
||||
ubyte var2
|
||||
|
||||
ubyte[] barr = [22,33,44,55,66]
|
||||
word[] warr = [-111,222,-333,444]
|
||||
byte b1
|
||||
byte b2
|
||||
word w1
|
||||
word w2
|
||||
ubyte ub1
|
||||
ubyte ub2
|
||||
uword uw1
|
||||
uword uw2
|
||||
|
||||
for A in "hello" {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
b1 = 5
|
||||
b2= 122
|
||||
b1 = b2+b1
|
||||
c64scr.print_b(b1)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in [1,3,5,99] {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
w1 = -1111
|
||||
w2 = 11231
|
||||
w1 = w2+w1
|
||||
c64scr.print_w(w1)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in 10 to 20 {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in 20 to 10 step -1 {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in 10 to 21 step 3 {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in 24 to 10 step -3 {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in barr {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc in "hello" {
|
||||
c64scr.print_ub(cc)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc2 in [1,3,5,99] {
|
||||
c64scr.print_ub(cc2)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc3 in 10 to 20 {
|
||||
c64scr.print_ub(cc3)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc4 in 20 to 10 step -1 {
|
||||
c64scr.print_ub(cc4)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc5 in 10 to 21 step 3 {
|
||||
c64scr.print_ub(cc5)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc6 in 24 to 10 step -3 {
|
||||
c64scr.print_ub(cc6)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc7 in barr {
|
||||
c64scr.print_ub(cc7)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for uword ww1 in [1111, 2222, 3333] {
|
||||
c64scr.print_uw(ww1)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for word ww2 in warr {
|
||||
c64scr.print_w(ww2)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for uword ww3 in 1111 to 1122 {
|
||||
c64scr.print_uw(ww3)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for uword ww3b in 2000 to 1990 step -1 {
|
||||
c64scr.print_uw(ww3b)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for uword ww3c in 1111 to 50000 step 3333 {
|
||||
c64scr.print_uw(ww3c)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for word ww4 in 999 to -999 step -500 {
|
||||
c64scr.print_w(ww4)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
uw1 = 55555
|
||||
uw2 = 1123
|
||||
uw1 = uw2+uw1
|
||||
c64scr.print_uw(uw1)
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
}
|
||||
|
135
examples/testforloops.p8
Normal file
135
examples/testforloops.p8
Normal file
@ -0,0 +1,135 @@
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
byte bvar
|
||||
ubyte var2
|
||||
|
||||
ubyte[] barr = [22,33,44,55,66]
|
||||
word[] warr = [-111,222,-333,444]
|
||||
|
||||
for A in "hello" {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in [1,3,5,99] {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in 10 to 20 {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in 20 to 10 step -1 {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in 10 to 21 step 3 {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in 24 to 10 step -3 {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for A in barr {
|
||||
c64scr.print_ub(A)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc in "hello" {
|
||||
c64scr.print_ub(cc)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc2 in [1,3,5,99] {
|
||||
c64scr.print_ub(cc2)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc3 in 10 to 20 {
|
||||
c64scr.print_ub(cc3)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc4 in 20 to 10 step -1 {
|
||||
c64scr.print_ub(cc4)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc5 in 10 to 21 step 3 {
|
||||
c64scr.print_ub(cc5)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc6 in 24 to 10 step -3 {
|
||||
c64scr.print_ub(cc6)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for ubyte cc7 in barr {
|
||||
c64scr.print_ub(cc7)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for uword ww1 in [1111, 2222, 3333] {
|
||||
c64scr.print_uw(ww1)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for word ww2 in warr {
|
||||
c64scr.print_w(ww2)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for uword ww3 in 1111 to 1117 {
|
||||
c64scr.print_uw(ww3)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for uword ww3b in 2000 to 1995 step -1 {
|
||||
c64scr.print_uw(ww3b)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for uword ww3c in 1111 to 50000 step 4444 {
|
||||
c64scr.print_uw(ww3c)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
for word ww4 in 999 to -999 step -500 {
|
||||
c64scr.print_w(ww4)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user