Casio_asm/test/fib.asm

323 lines
4.0 KiB
NASM

' store 1 in registers 2 and 3
dup,1
store,#2
store,#3
' store the max value in register 4
high,x100
store,#4
.loop
' add registers 2 and 3 twice
add_i,#2,#3
store,#2
add_i,#2,#3
store,#3
' print #2 and #3 to screen
call,.print
' loop if we're not at the max
lt_i,#3,#4
jif,.loop
' wait until we EXIT
inth,.inth
sub,x1
.wait
halt
jmp,.wait
' interrupt handler
.inth
' disable all interrupts temporarily
unsub,x1
' get interrupt number
store,#10
' check if it is hardware
high,x4000
and,#10
' if it isn't, abort (it is an error)
jnt,.abort
' check if the interrupt is a keydown
push,x1
and,#10
jif,.keydown
' pop the key code and continue execution
pop
jmp,.cont
.keydown
' check the key code
eq_i,47
' if it is 47 (EXIT), abort the program
jif,.abort
' if it isn't, continue execution
.cont
' remove interrupt flag and subscribe to interrupt again
push,b0
sub,x1
stat_s,x2
' if it didn't work, abort
jmp,.abort
' kills the program
.abort
' set the abort flag
push,b1
stat_s,x3
' remove interrupt handler and halt
inth,-1
halt
' prints #2 and #3 to screen
.print
' clear VRAM
ext,x0c
' draw #2 at 0,0
dup,0
store,#6
store,#7
push,#2
store,#5
call,.decdraw
' draw #3 at 0,6
push,0
store,#6
push,6
store,#7
push,#3
store,#5
call,.decdraw
' print the VRAM
ext,x01
' return
jmp
' subroutine to draw dec number on screen
' #5 input number
' #6 x coordinate
' #7 y coordinate
' #8 temp
.decdraw
push,#5
store,#8
.decdraw2
' divide temp by 8
push,10
div_i,#8
dup
store,#8
' if it is null, stop
jnt,.decdraw3
' else, add 4 to the x coordinate
push,4
add_i,#6
store,#6
' continue the loop
jmp,.decdraw2
.decdraw3
' get digit
push,10
mod_i,#5
'draw digit to screen
store,#8
call,.decdigit
' add 4 to the y coordinate
push,4
sub_i,#6
store,#6
' get next digit
push,10
div_i,#5
' draw next digit
dup
store,#5
jif,.decdraw3
'return
jmp
' subroutine to draw a dec digit on screen
' #8 input digit
' #6 x coordinate
' #7 y coordinate
.decdigit
' draw C if the number isn't 2
push,2
neq_i,#8
cif,.dispC
' draw A if the number isn't 1 or 4
push,1
neq_i,#8
push,4
neq_i,#8
and_l
cif,.dispA
' draw B if the number isn't 5 or 6
push,5
neq_i,#8
push,6
neq_i,#8
and_l
cif,.dispB
' draw D if the number isn't 1, 4 or 7
push,1
neq_i,#8
push,4
neq_i,#8
push,7
neq_i,#8
and_l
and_l
cif,.dispD
' draw G if the number isn't 0, 1 or 7
push,0
neq_i,#8
push,1
neq_i,#8
push,7
neq_i,#8
and_l
and_l
cif,.dispG
' draw F if the number isn't 1, 2, 3 or 7
push,1
neq_i,#8
push,2
neq_i,#8
push,3
neq_i,#8
push,7
neq_i,#8
and_l
and_l
and_l
cif,.dispF
' draw E if the number is 0, 2, 6 or 8
push,0
eq_i,#8
push,2
eq_i,#8
push,6
eq_i,#8
push,8
eq_i,#8
or_l
or_l
or_l
cif,.dispE
'return
jmp
' subroutine to draw the A part of a segment
.dispA
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y
push,#7
' lineH
ext,x07
' return
jmp
' subroutine to draw the B part of a segment
.dispB
' color COLOR_BLACK
push,1
' y2=y+2
push,2
add_i,#7
' y1=y
push,#7
' x=x+2
push,2
add_i,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the C part of a segment
.dispC
' color COLOR_BLACK
push,1
' y2=y+4
push,4
add_i,#7
' y1=y+2
push,2
add_i,#7
' x=x+2
push,2
add_i,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the D part of a segment
.dispD
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y+4
push,4
add_i,#7
' lineH
ext,x07
' return
jmp
' subroutine to draw the E part of a segment
.dispE
' color COLOR_BLACK
push,1
' y2=y+4
push,4
add_i,#7
' y1=y+2
push,2
add_i,#7
' x=x
push,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the F part of a segment
.dispF
' color COLOR_BLACK
push,1
' y2=y+2
push,2
add_i,#7
' y1=y
push,#7
' x=x
push,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the G part of a segment
.dispG
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y+2
push,2
add_i,#7
' lineH
ext,x07
' return
jmp