prog8/compiler/test/arithmetic/builtins.p8

450 lines
10 KiB
Plaintext
Raw Normal View History

2020-11-07 00:08:56 +00:00
%import textio
%import floats
%import string
2020-11-07 00:08:56 +00:00
%import syslib
%import math
2020-11-07 00:08:56 +00:00
%zeropage basicsafe
main {
sub start() {
rotations()
integers()
floatingpoint()
}
sub rotations() {
ubyte[] ubarr = [%11000111]
uword[] uwarr = [%1100111110101010]
repeat(10) {
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
}
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
uwarr[0] = %1100111110101010
ror(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
sys.clear_carry()
2020-11-07 00:08:56 +00:00
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(uwarr[0])
txt.print_uwbin(uwarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(ubarr[0])
txt.print_ubbin(ubarr[0], true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
&ubyte membyte = $c000
2024-01-16 00:23:41 +00:00
uword @shared addr = $c000
2020-11-07 00:08:56 +00:00
@(addr) = %10110101
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
rol(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
@(addr) = %10110101
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
sys.set_carry()
2020-11-07 00:08:56 +00:00
ror(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
@(addr) = %10110101
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
rol2(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
@(addr) = %10110101
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ror2(@(addr))
txt.print_ubbin(@(addr), true)
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2020-11-07 00:08:56 +00:00
}
sub integers() {
ubyte[] ubarr = [1,2,3,4,5,0,4,3,2,1, 255, 255, 255]
byte[] barr = [1,2,3,4,5,-4,0,-3,2,1, -128, -128, -127]
uword[] uwarr = [100,200,300,400,0,500,400,300,200,100]
word[] warr = [100,200,300,400,500,0,-400,-300,200,100,-99, -4096]
2024-01-16 00:23:41 +00:00
ubyte @shared zero=0
ubyte @shared ub
ubyte @shared ub2
byte @shared bb
uword @shared uw
word @shared ww
2020-11-07 00:08:56 +00:00
repeat(20) {
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
}
ub = sys.read_flags()
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
ub = zero+sys.read_flags()*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ub = math.rnd()
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
ub = zero+math.rnd()*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
uw = math.rndw()
2020-11-07 00:08:56 +00:00
txt.print_uw(uw)
2021-01-08 15:56:17 +00:00
txt.nl()
uw = zero+math.rndw()*1+zero
2020-11-07 00:08:56 +00:00
txt.print_uw(uw)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
uw = 50000
2023-04-29 18:59:05 +00:00
ub = sqrt(uw)
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2023-04-29 18:59:05 +00:00
ub = zero+sqrt(uw)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
bb = -100
bb = sgn(bb)
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
bb = -100
bb = zero+sgn(bb)*1+zero
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ub = 100
bb = sgn(ub)
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ub = 100
bb = zero+sgn(ub)*1+zero
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ww = -1000
bb = sgn(ww)
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
bb = zero+sgn(ww)*1+zero
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
uw = 1000
bb = sgn(uw)
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
bb = zero+sgn(uw)*1+zero
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
bb = -100
2022-06-05 12:20:08 +00:00
bb = abs(bb) as byte
2020-11-07 00:08:56 +00:00
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
bb = -100
2022-06-05 12:20:08 +00:00
bb = zero+(abs(bb) as byte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ww = -1000
2022-06-05 12:20:08 +00:00
ww = abs(ww) as word
2020-11-07 00:08:56 +00:00
txt.print_w(ww)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
ww = -1000
2022-06-05 12:20:08 +00:00
ww = zero+(abs(ww) as word)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_w(ww)
2021-01-08 15:56:17 +00:00
txt.nl()
2022-06-05 12:20:08 +00:00
2024-02-21 16:04:39 +00:00
ub = any(ubarr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(any(ubarr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
2024-02-21 16:04:39 +00:00
ub = any(barr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(any(barr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
2024-02-21 16:04:39 +00:00
ub = any(uwarr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(any(uwarr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
2024-02-21 16:04:39 +00:00
ub = any(warr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(any(warr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
2024-02-21 16:04:39 +00:00
ub = all(ubarr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(all(ubarr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
2024-02-21 16:04:39 +00:00
ub = all(barr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(all(barr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
2024-02-21 16:04:39 +00:00
ub = all(uwarr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(all(uwarr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
2024-02-21 16:04:39 +00:00
ub = all(warr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(all(warr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
}
sub floatingpoint() {
float[] flarr = [1.1, 2.2, 3.3, 0.0, -9.9, 5.5, 4.4]
2024-01-16 00:23:41 +00:00
ubyte @shared zero=0
ubyte @shared ub
byte @shared bb
uword @shared uw
float @shared fl
float @shared fzero=0.0
2020-11-07 00:08:56 +00:00
fl = -9.9
bb = sgn(fl)
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
fl = -9.9
bb = zero+sgn(fl)*1+zero
txt.print_b(bb)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
2024-02-21 16:04:39 +00:00
ub = any(flarr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(any(flarr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = all(flarr) as ubyte
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2024-02-21 16:04:39 +00:00
ub = zero+(all(flarr) as ubyte)*1+zero
2020-11-07 00:08:56 +00:00
txt.print_ub(ub)
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
for ub in 0 to len(flarr)-1 {
floats.print(flarr[ub])
2020-11-07 00:08:56 +00:00
txt.chrout(',')
}
2021-01-08 15:56:17 +00:00
txt.nl()
2020-11-07 00:08:56 +00:00
}
}