fix signed word value range check error, fix rol2() on array element

This commit is contained in:
Irmen de Jong
2025-04-08 19:56:20 +02:00
parent 69c96ad99b
commit a6835ce3f0
5 changed files with 882 additions and 135 deletions
@@ -547,7 +547,7 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
asmgen.loadScaledArrayIndexIntoRegister(what, CpuRegister.X)
val varname = asmgen.asmVariableName(what.variable)
if(what.splitWords)
asmgen.out(" asl ${varname}_lsb,x | rol ${varname}_msb,x | bcc + | inc ${varname}_lsb |+")
asmgen.out(" asl ${varname}_lsb,x | rol ${varname}_msb,x | bcc + | inc ${varname}_lsb,x |+")
else
asmgen.out(" asl ${varname},x | rol ${varname}+1,x | bcc + | inc ${varname},x |+ ")
}
-50
View File
@@ -267,31 +267,6 @@ main {
print_bool(newcarry)
txt.nl()
}
@($8001)=original
carrycheck = false
if carry
sys.set_carry()
else
sys.clear_carry()
rol(@($8000+value_and_carry(1)))
if_cs
carrycheck=true
if @($8001)!=test or carrycheck!=newcarry {
txt.print("rol_ub mem error ")
txt.print_ub(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_ub(@($8001))
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
}
sub test_ror_ub(ubyte value, bool carry, ubyte test, bool newcarry) {
@@ -344,31 +319,6 @@ main {
print_bool(newcarry)
txt.nl()
}
@($8001) = original
carrycheck = false
if carry
sys.set_carry()
else
sys.clear_carry()
ror(@($8000+value_and_carry(1)))
if_cs
carrycheck=true
if @($8001)!=test or carrycheck!=newcarry {
txt.print("ror_ub mem error ")
txt.print_ub(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_ub(@($8001))
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
}
sub test_rol2_uw(uword value, uword test) {
+73 -73
View File
@@ -23,7 +23,7 @@ main {
; ---------- REGISTER A ---------
count = 0
total = 0
txt.print("a in string: ")
txt.print("a in string: ")
for a in "hello" {
aa=a
count++
@@ -36,7 +36,7 @@ main {
count = 0
total = 0
txt.print("a in arrayliteral: ")
txt.print("a in arrayliteral: ")
for a in [1,3,5,99] {
aa=a
count++
@@ -49,7 +49,7 @@ main {
count = 0
total = 0
txt.print("a in arrayvar: ")
txt.print("a in arrayvar: ")
for a in ubarr {
aa=a
count++
@@ -62,7 +62,7 @@ main {
count = 0
total = 0
txt.print("a in range step 1: ")
txt.print("a in range step 1: ")
for a in 10 to 20 {
aa=a
count++
@@ -75,7 +75,7 @@ main {
count = 0
total = 0
txt.print("a in range step -1: ")
txt.print("a in range step -1: ")
for a in 20 downto 10 {
aa=a
count++
@@ -88,7 +88,7 @@ main {
count = 0
total = 0
txt.print("a in range step 3: ")
txt.print("a in range step 3: ")
for a in 10 to 21 step 3 {
aa=a
count++
@@ -101,7 +101,7 @@ main {
count = 0
total = 0
txt.print("a in rangeincl step 3: ")
txt.print("a in rangeincl step 3: ")
for a in 10 to 22 step 3 {
aa=a
count++
@@ -114,7 +114,7 @@ main {
count = 0
total = 0
txt.print("a in range step -3: ")
txt.print("a in range step -3: ")
for a in 24 to 10 step -3 {
aa=a
count++
@@ -127,7 +127,7 @@ main {
count = 0
total = 0
txt.print("a in rangeincl step -3: ")
txt.print("a in rangeincl step -3: ")
for a in 24 to 9 step -3 {
aa=a
count++
@@ -141,7 +141,7 @@ main {
count = 0
total = 0
endub1=101
txt.print("a in ncrange step 1: ")
txt.print("a in ncrange step 1: ")
for a in 95 to endub1 step 1 {
aa=a
count++
@@ -155,7 +155,7 @@ main {
count = 0
total = 0
endub1=101
txt.print("a in ncrange step -1: ")
txt.print("a in ncrange step -1: ")
for a in endub1 downto 95 {
aa=a
count++
@@ -169,7 +169,7 @@ main {
count = 0
total = 0
endub1=105
txt.print("a in ncrange step 3: ")
txt.print("a in ncrange step 3: ")
for a in 95 to endub1 step 3 {
aa=a
count++
@@ -183,7 +183,7 @@ main {
count = 0
total = 0
endub1=105
txt.print("a in ncrange step -3: ")
txt.print("a in ncrange step -3: ")
for a in endub1 to 95 step -3 {
aa=a
count++
@@ -197,7 +197,7 @@ main {
count = 0
total = 0
endub1=107
txt.print("a in ncrangeinc step 3: ")
txt.print("a in ncrangeinc step 3: ")
for a in 95 to endub1 step 3 {
aa=a
count++
@@ -211,7 +211,7 @@ main {
count = 0
total = 0
endub1=107
txt.print("a in ncrangeinc step -3: ")
txt.print("a in ncrangeinc step -3: ")
for a in endub1 to 95 step -3 {
aa=a
count++
@@ -228,7 +228,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in string: ")
txt.print("ubyte var in string: ")
for ub in "hello" {
count++
total += ub
@@ -240,7 +240,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in arrayliteral: ")
txt.print("ubyte var in arrayliteral: ")
for ub in [1,3,5,99] {
count++
total += ub
@@ -252,7 +252,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in arrayvar: ")
txt.print("ubyte var in arrayvar: ")
for ub in ubarr {
count++
total += ub
@@ -264,7 +264,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in range step 1: ")
txt.print("ubyte var in range step 1: ")
for ub in 10 to 20 {
count++
total += ub
@@ -276,7 +276,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in range step -1: ")
txt.print("ubyte var in range step -1: ")
for ub in 20 downto 10 step -1 {
count++
total += ub
@@ -288,7 +288,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in range step 3: ")
txt.print("ubyte var in range step 3: ")
for ub in 10 to 21 step 3 {
count++
total += ub
@@ -300,7 +300,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in rangeincl step 3: ")
txt.print("ubyte var in rangeincl step 3: ")
for ub in 10 to 22 step 3 {
count++
total += ub
@@ -312,7 +312,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in range step -3: ")
txt.print("ubyte var in range step -3: ")
for ub in 24 to 10 step -3 {
count++
total += ub
@@ -324,7 +324,7 @@ main {
count = 0
total = 0
txt.print("ubyte var in rangeincl step -3: ")
txt.print("ubyte var in rangeincl step -3: ")
for ub in 24 to 9 step -3 {
count++
total += ub
@@ -337,7 +337,7 @@ main {
count = 0
total = 0
endub1=101
txt.print("ubyte var in ncrange step 1: ")
txt.print("ubyte var in ncrange step 1: ")
for ub in 95 to endub1 step 1 {
count++
total += ub
@@ -350,7 +350,7 @@ main {
count = 0
total = 0
endub1=101
txt.print("ubyte var in ncrange step -1: ")
txt.print("ubyte var in ncrange step -1: ")
for ub in endub1 downto 95 {
count++
total += ub
@@ -363,7 +363,7 @@ main {
count = 0
total = 0
endub1=105
txt.print("ubyte var in ncrange step 3: ")
txt.print("ubyte var in ncrange step 3: ")
for ub in 95 to endub1 step 3 {
count++
total += ub
@@ -376,7 +376,7 @@ main {
count = 0
total = 0
endub1=105
txt.print("ubyte var in ncrange step -3: ")
txt.print("ubyte var in ncrange step -3: ")
for ub in endub1 to 95 step -3 {
count++
total += ub
@@ -389,7 +389,7 @@ main {
count = 0
total = 0
endub1=107
txt.print("ubyte var in ncrangeinc step 3: ")
txt.print("ubyte var in ncrangeinc step 3: ")
for ub in 95 to endub1 step 3 {
count++
total += ub
@@ -402,7 +402,7 @@ main {
count = 0
total = 0
endub1=107
txt.print("ubyte var in ncrangeinc step -3: ")
txt.print("ubyte var in ncrangeinc step -3: ")
for ub in endub1 to 95 step -3 {
count++
total += ub
@@ -418,7 +418,7 @@ main {
count = 0
total = 0
txt.print("byte var in arrayliteral: ")
txt.print("byte var in arrayliteral: ")
for bb in [1,3,5,99] {
count++
total += bb
@@ -430,7 +430,7 @@ main {
count = 0
total = 0
txt.print("byte var in arrayvar: ")
txt.print("byte var in arrayvar: ")
for bb in barr {
count++
total += bb
@@ -442,7 +442,7 @@ main {
count = 0
total = 0
txt.print("byte var in range step 1: ")
txt.print("byte var in range step 1: ")
for bb in 10 to 20 {
count++
total += bb
@@ -454,7 +454,7 @@ main {
count = 0
total = 0
txt.print("byte var in range step -1: ")
txt.print("byte var in range step -1: ")
for bb in 20 downto 10 {
count++
total += bb
@@ -466,7 +466,7 @@ main {
count = 0
total = 0
txt.print("byte var in range step 3: ")
txt.print("byte var in range step 3: ")
for bb in 10 to 21 step 3 {
count++
total += bb
@@ -478,7 +478,7 @@ main {
count = 0
total = 0
txt.print("byte var in rangeincl step 3: ")
txt.print("byte var in rangeincl step 3: ")
for bb in 10 to 22 step 3 {
count++
total += bb
@@ -490,7 +490,7 @@ main {
count = 0
total = 0
txt.print("byte var in range step -3: ")
txt.print("byte var in range step -3: ")
for bb in 24 to 10 step -3 {
count++
total += bb
@@ -502,7 +502,7 @@ main {
count = 0
total = 0
txt.print("byte var in rangeincl step -3: ")
txt.print("byte var in rangeincl step -3: ")
for bb in 24 to 9 step -3 {
count++
total += bb
@@ -515,7 +515,7 @@ main {
count = 0
total = 0
endb1=101
txt.print("byte var in ncrange step 1: ")
txt.print("byte var in ncrange step 1: ")
for bb in 95 to endb1 step 1 {
count++
total += bb
@@ -528,7 +528,7 @@ main {
count = 0
total = 0
endb1=101
txt.print("byte var in ncrange step -1: ")
txt.print("byte var in ncrange step -1: ")
for bb in endb1 downto 95 {
count++
total += bb
@@ -541,7 +541,7 @@ main {
count = 0
total = 0
endb1=105
txt.print("byte var in ncrange step 3: ")
txt.print("byte var in ncrange step 3: ")
for bb in 95 to endb1 step 3 {
count++
total += bb
@@ -554,7 +554,7 @@ main {
count = 0
total = 0
endb1=105
txt.print("byte var in ncrange step -3: ")
txt.print("byte var in ncrange step -3: ")
for bb in endb1 to 95 step -3 {
count++
total += bb
@@ -567,7 +567,7 @@ main {
count = 0
total = 0
endb1=107
txt.print("byte var in ncrangeinc step 3: ")
txt.print("byte var in ncrangeinc step 3: ")
for bb in 95 to endb1 step 3 {
count++
total += bb
@@ -580,7 +580,7 @@ main {
count = 0
total = 0
endb1=107
txt.print("byte var in ncrangeinc step -3: ")
txt.print("byte var in ncrangeinc step -3: ")
for bb in endb1 to 95 step -3 {
count++
total += bb
@@ -601,7 +601,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in string: ")
txt.print("uword var in string: ")
for uw in "hello" {
count++
totaluw += uw
@@ -613,7 +613,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in arrayliteral: ")
txt.print("uword var in arrayliteral: ")
for uw in [1111,3333,555,999] {
count++
totaluw += uw
@@ -625,7 +625,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in arrayvar: ")
txt.print("uword var in arrayvar: ")
for uw in uwarr {
count++
totaluw += uw
@@ -637,7 +637,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in range step 1: ")
txt.print("uword var in range step 1: ")
for uw in 1000 to 1100 {
count++
totaluw += uw
@@ -649,7 +649,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in range step -1: ")
txt.print("uword var in range step -1: ")
for uw in 2000 downto 1500 {
count++
totaluw += uw
@@ -661,7 +661,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in range step 333: ")
txt.print("uword var in range step 333: ")
for uw in 1000 to 2200 step 333 {
count++
totaluw += uw
@@ -673,7 +673,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in rangeincl step 333: ")
txt.print("uword var in rangeincl step 333: ")
for uw in 1000 to 2332 step 333 {
count++
totaluw += uw
@@ -685,7 +685,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in range step -333: ")
txt.print("uword var in range step -333: ")
for uw in 17000 to 14500 step -333 {
count++
totaluw += uw
@@ -697,7 +697,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in rangeincl step -333: ")
txt.print("uword var in rangeincl step -333: ")
for uw in 17000 to 14336 step -333 {
count++
totaluw += uw
@@ -710,7 +710,7 @@ main {
count = 0
totaluw = 0
enduw1=17000
txt.print("uword var in ncrange step 1: ")
txt.print("uword var in ncrange step 1: ")
for uw in 16500 to enduw1 step 1 {
count++
totaluw += uw
@@ -722,7 +722,7 @@ main {
count = 0
totaluw = 0
txt.print("uword var in ncrange step -1: ")
txt.print("uword var in ncrange step -1: ")
for uw in enduw1 downto 16500 {
count++
totaluw += uw
@@ -735,7 +735,7 @@ main {
count = 0
totaluw = 0
enduw1=17000
txt.print("uword var in ncrange step 333: ")
txt.print("uword var in ncrange step 333: ")
for uw in 14500 to enduw1 step 333 {
count++
totaluw += uw
@@ -748,7 +748,7 @@ main {
count = 0
totaluw = 0
enduw1=17000
txt.print("uword var in ncrange step -333: ")
txt.print("uword var in ncrange step -333: ")
for uw in enduw1 to 14500 step -333 {
count++
totaluw += uw
@@ -761,7 +761,7 @@ main {
count = 0
totaluw = 0
enduw1=17164
txt.print("uword var in ncrangeinc step 333: ")
txt.print("uword var in ncrangeinc step 333: ")
for uw in 14500 to enduw1 step 333 {
count++
totaluw += uw
@@ -774,7 +774,7 @@ main {
count = 0
totaluw = 0
enduw1=17000
txt.print("uword var in ncrangeinc step -333: ")
txt.print("uword var in ncrangeinc step -333: ")
for uw in enduw1 to 14336 step -333 {
count++
totaluw += uw
@@ -794,7 +794,7 @@ main {
count = 0
total = 0
txt.print("word var in arrayliteral: ")
txt.print("word var in arrayliteral: ")
for ww in [1111,3333,555,999] {
count++
total += ww
@@ -806,7 +806,7 @@ main {
count = 0
total = 0
txt.print("word var in arrayvar: ")
txt.print("word var in arrayvar: ")
for ww in warr {
count++
total += ww
@@ -818,7 +818,7 @@ main {
count = 0
total = 0
txt.print("word var in range step 1: ")
txt.print("word var in range step 1: ")
for ww in -100 to 1000 {
count++
total += ww
@@ -830,7 +830,7 @@ main {
count = 0
total = 0
txt.print("word var in range step -1: ")
txt.print("word var in range step -1: ")
for ww in 1000 downto -500 {
count++
total += ww
@@ -842,7 +842,7 @@ main {
count = 0
total = 0
txt.print("word var in range step 333: ")
txt.print("word var in range step 333: ")
for ww in -1000 to 2200 step 333 {
count++
total += ww
@@ -854,7 +854,7 @@ main {
count = 0
total = 0
txt.print("word var in rangeincl step 333: ")
txt.print("word var in rangeincl step 333: ")
for ww in -1000 to 2330 step 333 {
count++
total += ww
@@ -866,7 +866,7 @@ main {
count = 0
total = 0
txt.print("word var in range step -333: ")
txt.print("word var in range step -333: ")
for ww in 2000 to -2500 step -333 {
count++
total += ww
@@ -878,7 +878,7 @@ main {
count = 0
total = 0
txt.print("word var in rangeincl step -333: ")
txt.print("word var in rangeincl step -333: ")
for ww in 2000 to -2662 step -333 {
count++
total += ww
@@ -891,7 +891,7 @@ main {
count = 0
total = 0
endw1=17000
txt.print("word var in ncrange step 1: ")
txt.print("word var in ncrange step 1: ")
for ww in 16500 to endw1 step 1 {
count++
total += ww
@@ -903,7 +903,7 @@ main {
count = 0
total = 0
txt.print("word var in ncrange step -1: ")
txt.print("word var in ncrange step -1: ")
for ww in endw1 downto 16500 {
count++
total += ww
@@ -916,7 +916,7 @@ main {
count = 0
total = 0
endw1=17000
txt.print("word var in ncrange step 333: ")
txt.print("word var in ncrange step 333: ")
for ww in 14500 to endw1 step 333 {
count++
total += ww
@@ -929,7 +929,7 @@ main {
count = 0
total = 0
endw1=17000
txt.print("word var in ncrange step -333: ")
txt.print("word var in ncrange step -333: ")
for ww in endw1 to 14500 step -333 {
count++
total += ww
@@ -942,7 +942,7 @@ main {
count = 0
total = 0
endw1=17164
txt.print("word var in ncrangeinc step 333: ")
txt.print("word var in ncrangeinc step 333: ")
for ww in 14500 to endw1 step 333 {
count++
total += ww
@@ -955,7 +955,7 @@ main {
count = 0
total = 0
endw1=17000
txt.print("word var in ncrangeinc step -333: ")
txt.print("word var in ncrangeinc step -333: ")
for ww in endw1 to 14336 step -333 {
count++
total += ww
+807 -10
View File
@@ -1,22 +1,819 @@
%import textio
%zeropage basicsafe
%option no_sysinit
main {
sub start() {
unsigned()
signed()
}
sub start() {
sub print_bool(bool b) {
txt.print_ub(b as ubyte)
}
@($a000) = 123
txt.print_ub(@($a000))
txt.nl()
ubyte[2] ubarray
uword[2] uwarray
byte[2] barray
word[2] warray
cx16.push_rambank(10)
txt.print_ub(@($a000))
txt.nl()
cx16.pop_rambank()
sub value_and_carry(ubyte value) -> ubyte {
sys.set_carry()
return value
}
txt.print_ub(@($a000))
txt.nl()
sub unsigned() {
txt.print("rol_ub\n")
test_rol_ub(%00000000, false, %00000000, false)
test_rol_ub(%00000000, true, %00000001, false)
test_rol_ub(%01000000, false, %10000000, false)
test_rol_ub(%01000000, true, %10000001, false)
test_rol_ub(%10000000, false, %00000000, true)
test_rol_ub(%10000000, true, %00000001, true)
txt.print("ror_ub\n")
test_ror_ub(%00000000, false, %00000000, false)
test_ror_ub(%00000000, true, %10000000, false)
test_ror_ub(%01000000, false, %00100000, false)
test_ror_ub(%01000000, true, %10100000, false)
test_ror_ub(%00000001, false, %00000000, true)
test_ror_ub(%00000001, true, %10000000, true)
txt.print("rol2_ub\n")
test_rol2_ub(%00000000, %00000000)
test_rol2_ub(%01000001, %10000010)
test_rol2_ub(%10000010, %00000101)
test_rol2_ub(%11111110, %11111101)
txt.print("ror2_ub\n")
test_ror2_ub(%00000000, %00000000)
test_ror2_ub(%01000001, %10100000)
test_ror2_ub(%10000010, %01000001)
test_ror2_ub(%11111110, %01111111)
txt.print("rol_uw\n")
test_rol_uw(%0000000010000000, false, %0000000100000000, false)
test_rol_uw(%0000000010000000, true, %0000000100000001, false)
test_rol_uw(%0100000010000000, false, %1000000100000000, false)
test_rol_uw(%0100000010000000, true, %1000000100000001, false)
test_rol_uw(%1000000010000000, false, %0000000100000000, true)
test_rol_uw(%1000000010000000, true, %0000000100000001, true)
txt.print("ror_uw\n")
test_ror_uw(%0000000100000000, false, %0000000010000000, false)
test_ror_uw(%0000000100000000, true, %1000000010000000, false)
test_ror_uw(%0100000100000000, false, %0010000010000000, false)
test_ror_uw(%0100000100000000, true, %1010000010000000, false)
test_ror_uw(%0000000100000001, false, %0000000010000000, true)
test_ror_uw(%0000000100000001, true, %1000000010000000, true)
txt.print("rol2_uw\n")
test_rol2_uw(%0000000010000000, %0000000100000000)
test_rol2_uw(%0100000110000000, %1000001100000000)
test_rol2_uw(%1000001010000000, %0000010100000001)
test_rol2_uw(%1111111010000000, %1111110100000001)
txt.print("ror2_uw\n")
test_ror2_uw(%0000000100000000, %0000000010000000)
test_ror2_uw(%0100000100000000, %0010000010000000)
test_ror2_uw(%1000001100000001, %1100000110000000)
test_ror2_uw(%1111111100000011, %1111111110000001)
txt.print("<< ub\n")
test_shiftl_ub(%00000000, %00000000, false)
test_shiftl_ub(%00000001, %00000010, false)
test_shiftl_ub(%01000000, %10000000, false)
test_shiftl_ub(%10000000, %00000000, true)
txt.print(">> ub\n")
test_shiftr_ub(%00000000, %00000000, false)
test_shiftr_ub(%00000001, %00000000, true)
test_shiftr_ub(%10000000, %01000000, false)
test_shiftr_ub(%10000001, %01000000, true)
txt.print("<< uw\n")
test_shiftl_uw(%0000000000000000, %0000000000000000, false)
test_shiftl_uw(%0000000000000001, %0000000000000010, false)
test_shiftl_uw(%0000000010000001, %0000000100000010, false)
test_shiftl_uw(%0100000010000000, %1000000100000000, false)
test_shiftl_uw(%1100000010000000, %1000000100000000, true)
test_shiftl_uw(%1000000000000000, %0000000000000000, true)
txt.print(">> uw\n")
test_shiftr_uw(%0000000000000000, %0000000000000000, false)
test_shiftr_uw(%0000000000000001, %0000000000000000, true)
test_shiftr_uw(%0000001100000010, %0000000110000001, false)
test_shiftr_uw(%0000001100000011, %0000000110000001, true)
test_shiftr_uw(%1000000000000010, %0100000000000001, false)
}
sub signed() {
txt.print("<< b\n")
test_shiftl_b(%00000000 as byte, %00000000 as byte, false)
test_shiftl_b(%00000001 as byte, %00000010 as byte, false)
test_shiftl_b(%01000000 as byte, %10000000 as byte, false)
test_shiftl_b(%10000000 as byte, %00000000 as byte, true)
txt.print(">> b\n")
test_shiftr_b(%00000000 as byte, %00000000 as byte, false)
test_shiftr_b(%00000001 as byte, %00000000 as byte, true)
test_shiftr_b(%10000000 as byte, %11000000 as byte, false)
test_shiftr_b(%10000010 as byte, %11000001 as byte, false)
test_shiftr_b(%10000001 as byte, %11000000 as byte, true)
txt.print("<< w\n")
test_shiftl_w(%0000000000000000 as word, %0000000000000000 as word, false)
test_shiftl_w(%0000000000000001 as word, %0000000000000010 as word, false)
test_shiftl_w(%0000000010000001 as word, %0000000100000010 as word, false)
test_shiftl_w(%0100000010000000 as word, %1000000100000000 as word, false)
test_shiftl_w(%1100000010000000 as word, %1000000100000000 as word, true)
test_shiftl_w(%1000000000000000 as word, %0000000000000000 as word, true)
txt.print(">> w\n")
test_shiftr_w(%0000000000000000 as word, %0000000000000000 as word, false)
test_shiftr_w(%0000000000000001 as word, %0000000000000000 as word, true)
test_shiftr_w(%0000001100000010 as word, %0000000110000001 as word, false)
test_shiftr_w(%0000001100000011 as word, %0000000110000001 as word, true)
test_shiftr_w(%1000000000000010 as word, %1100000000000001 as word, false)
test_shiftr_w(%1000000000000001 as word, %1100000000000000 as word, true)
}
sub test_rol2_ub(ubyte value, ubyte test) {
ubyte original = value
sys.set_carry()
rol2(value)
if value!=test {
txt.print("rol2_ub error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(value)
txt.print(" exp: ")
txt.print_ub(test)
txt.nl()
}
ubarray[1]=original
sys.set_carry()
rol2(ubarray[1])
if ubarray[1]!=test {
txt.print("rol2_ub array error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(ubarray[1])
txt.print(" exp: ")
txt.print_ub(test)
txt.nl()
}
@($8000)=original
sys.set_carry()
rol2(@($8000))
if @($8000)!=test {
txt.print("rol2_ub mem error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(@($8000))
txt.print(" exp: ")
txt.print_ub(test)
txt.nl()
}
}
sub test_ror2_ub(ubyte value, ubyte test) {
ubyte original = value
sys.set_carry()
ror2(value)
if value!=test {
txt.print("ror2_ub error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(value)
txt.print(" exp: ")
txt.print_ub(test)
txt.nl()
}
ubarray[1] = original
sys.set_carry()
ror2(ubarray[1])
if ubarray[1]!=test {
txt.print("ror2_ub array error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(ubarray[1])
txt.print(" exp: ")
txt.print_ub(test)
txt.nl()
}
@($8000) = original
sys.set_carry()
ror2(@($8000))
if @($8000)!=test {
txt.print("ror2_ub mem error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(@($8000))
txt.print(" exp: ")
txt.print_ub(test)
txt.nl()
}
}
sub test_rol_ub(ubyte value, bool carry, ubyte test, bool newcarry) {
bool carrycheck = false
ubyte original = value
if carry
sys.set_carry()
else
sys.clear_carry()
rol(value)
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry{
txt.print("rol_ub error ")
txt.print_ub(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_ub(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
ubarray[1] = original
carrycheck = false
if carry
sys.set_carry()
else
sys.clear_carry()
rol(ubarray[value_and_carry(1)])
if_cs
carrycheck=true
if ubarray[1]!=test or carrycheck!=newcarry{
txt.print("rol_ub array error ")
txt.print_ub(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_ub(ubarray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
}
sub test_ror_ub(ubyte value, bool carry, ubyte test, bool newcarry) {
bool carrycheck = false
ubyte original = value
if carry
sys.set_carry()
else
sys.clear_carry()
ror(value)
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry{
txt.print("ror_ub error ")
txt.print_ub(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_ub(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
ubarray[1] = original
carrycheck = false
if carry
sys.set_carry()
else
sys.clear_carry()
ror(ubarray[value_and_carry(1)])
if_cs
carrycheck=true
if ubarray[1]!=test or carrycheck!=newcarry {
txt.print("ror_ub array error ")
txt.print_ub(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_ub(ubarray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
}
sub test_rol2_uw(uword value, uword test) {
uword original = value
sys.set_carry()
rol2(value)
if value!=test {
txt.print("rol2_uw error ")
txt.print_uw(original)
txt.spc()
txt.print_uw(value)
txt.print(" exp: ")
txt.print_uw(test)
txt.nl()
}
uwarray[1] = original
sys.set_carry()
rol2(uwarray[1])
if uwarray[1]!=test {
txt.print("rol2_uw array error ")
txt.print_uw(original)
txt.spc()
txt.print_uw(uwarray[1])
txt.print(" exp: ")
txt.print_uw(test)
txt.nl()
}
}
sub test_ror2_uw(uword value, uword test) {
uword original = value
sys.set_carry()
ror2(value)
if value!=test {
txt.print("ror2_uw error ")
txt.print_uw(original)
txt.spc()
txt.print_uw(value)
txt.print(" exp: ")
txt.print_uw(test)
txt.nl()
}
uwarray[1] = original
sys.set_carry()
ror2(uwarray[1])
if uwarray[1]!=test {
txt.print("ror2_uw array error ")
txt.print_uw(original)
txt.spc()
txt.print_uw(uwarray[1])
txt.print(" exp: ")
txt.print_uw(test)
txt.nl()
}
}
sub test_rol_uw(uword value, bool carry, uword test, bool newcarry) {
bool carrycheck = false
uword original = value
if carry
sys.set_carry()
else
sys.clear_carry()
rol(value)
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry{
txt.print("rol_uw error ")
txt.print_uw(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_uw(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_uw(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
uwarray[1] = original
carrycheck = false
if carry
sys.set_carry()
else
sys.clear_carry()
rol(uwarray[value_and_carry(1)])
if_cs
carrycheck=true
if uwarray[1]!=test or carrycheck!=newcarry{
txt.print("rol_uw array error ")
txt.print_uw(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_uw(uwarray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_uw(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
}
sub test_ror_uw(uword value, bool carry, uword test, bool newcarry) {
bool carrycheck = false
uword original = value
if carry
sys.set_carry()
else
sys.clear_carry()
ror(value)
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry{
txt.print("ror_uw error ")
txt.print_uw(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_uw(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_uw(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
uwarray[1] = original
carrycheck = false
if carry
sys.set_carry()
else
sys.clear_carry()
ror(uwarray[value_and_carry(1)])
if_cs
carrycheck=true
if uwarray[1]!=test or carrycheck!=newcarry{
txt.print("ror_uw array error ")
txt.print_uw(original)
txt.spc()
print_bool(carry)
txt.spc()
txt.print_uw(uwarray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_uw(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
}
sub test_shiftl_ub(ubyte value, ubyte test, bool newcarry) {
bool carrycheck = false
ubyte original = value
sys.set_carry()
value <<= 1
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry {
txt.print("<< ub error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
ubarray[1] = original
sys.set_carry()
carrycheck = false
ubarray[1] <<= 1
if_cs
carrycheck=true
if ubarray[1]!=test or carrycheck!=newcarry {
txt.print("<< ub array error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(ubarray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
}
sub test_shiftr_ub(ubyte value, ubyte test, bool newcarry) {
bool carrycheck = false
ubyte original = value
sys.set_carry()
value >>= 1
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry {
txt.print(">> ub error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
ubarray[1] = original
sys.set_carry()
carrycheck = false
ubarray[1] >>= 1
if_cs
carrycheck=true
if ubarray[1]!=test or carrycheck!=newcarry {
txt.print(">> ub array error ")
txt.print_ub(original)
txt.spc()
txt.print_ub(ubarray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_ub(test)
txt.spc()
print_bool(newcarry)
txt.nl()
}
}
sub test_shiftl_uw(uword value, uword test, bool newcarry) {
bool carrycheck = false
uword original = value
sys.set_carry()
value <<= 1
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry {
txt.print("<< uw error ")
txt.print_uw(original)
txt.spc()
txt.print_uw(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_uw(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
uwarray[1] = original
sys.set_carry()
carrycheck = false
uwarray[1] <<= 1
if_cs
carrycheck=true
if uwarray[1]!=test or carrycheck!=newcarry {
txt.print("<< uw array error ")
txt.print_uw(original)
txt.spc()
txt.print_uw(uwarray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_uw(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
}
sub test_shiftr_uw(uword value, uword test, bool newcarry) {
bool carrycheck = false
uword original = value
sys.set_carry()
value >>= 1
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry {
txt.print(">> uw error ")
txt.print_uw(original)
txt.spc()
txt.print_uw(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_uw(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
uwarray[1] = original
sys.set_carry()
carrycheck = false
uwarray[1] >>= 1
if_cs
carrycheck=true
if uwarray[1]!=test or carrycheck!=newcarry {
txt.print(">> uw array error ")
txt.print_uw(original)
txt.spc()
txt.print_uw(uwarray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_uw(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
}
sub test_shiftl_b(byte value, byte test, bool newcarry) {
bool carrycheck = false
byte original = value
sys.set_carry()
value <<= 1
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry {
txt.print("<< b error ")
txt.print_b(original)
txt.spc()
txt.print_b(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_b(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
barray[1] = original
sys.set_carry()
carrycheck = false
barray[1] <<= 1
if_cs
carrycheck=true
if barray[1]!=test or carrycheck!=newcarry {
txt.print("<< b array error ")
txt.print_b(original)
txt.spc()
txt.print_b(barray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_b(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
}
sub test_shiftr_b(byte value, byte test, bool newcarry) {
bool carrycheck = false
byte original = value
sys.set_carry()
value >>= 1
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry {
txt.print(">> b error ")
txt.print_b(original)
txt.spc()
txt.print_b(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_b(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
barray[1] = original
sys.set_carry()
carrycheck = false
barray[1] >>= 1
if_cs
carrycheck=true
if barray[1]!=test or carrycheck!=newcarry {
txt.print(">> b array error ")
txt.print_b(original)
txt.spc()
txt.print_b(barray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_b(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
}
sub test_shiftl_w(word value, word test, bool newcarry) {
bool carrycheck = false
word original = value
sys.set_carry()
value <<= 1
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry {
txt.print("<< w error ")
txt.print_w(original)
txt.spc()
txt.print_w(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_w(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
warray[1] = original
sys.set_carry()
carrycheck = false
warray[1] <<= 1
if_cs
carrycheck=true
if warray[1]!=test or carrycheck!=newcarry {
txt.print("<< w array error ")
txt.print_w(original)
txt.spc()
txt.print_w(warray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_w(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
}
sub test_shiftr_w(word value, word test, bool newcarry) {
bool carrycheck = false
word original = value
sys.set_carry()
value >>= 1
if_cs
carrycheck=true
if value!=test or carrycheck!=newcarry {
txt.print(">> w error ")
txt.print_w(original)
txt.spc()
txt.print_w(value)
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_w(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
warray[1] = original
sys.set_carry()
carrycheck = false
warray[1] >>= 1
if_cs
carrycheck=true
if warray[1]!=test or carrycheck!=newcarry {
txt.print(">> w array error ")
txt.print_w(original)
txt.spc()
txt.print_w(warray[1])
txt.spc()
print_bool(carrycheck)
txt.print(" exp: ")
txt.print_w(test)
txt.spc()
print_bool(carrycheck)
txt.nl()
}
}
}
@@ -296,7 +296,7 @@ class PtNumber(type: BaseDataType, val number: Double, position: Position) : PtE
BaseDataType.UBYTE -> require(number in 0.0..255.0)
BaseDataType.BYTE -> require(number in -128.0..127.0)
BaseDataType.UWORD -> require(number in 0.0..65535.0)
BaseDataType.WORD -> require(number in -32728.0..32767.0)
BaseDataType.WORD -> require(number in -32768.0..32767.0)
BaseDataType.LONG -> require(number in -2147483647.0..2147483647.0)
else -> require(type.isNumeric) { "numeric literal type should be numeric: $type" }
}