Files
rasp/tests/test_arithmetic.asm
Alek Ratzloff 551bd2c3f4 Add initial register states to meta section; remove entry directive
It makes sense to allow users to set the initial register values. This
allows someone to e.g. enable interrupts once the VM has started, or set
the initial stack pointer value.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-10 12:18:31 -04:00

115 lines
2.3 KiB
NASM

.section data $0x1000 {
number: .u8 $10
main:
; Test addition
mov %status, $1
add %r0, $1
cmpeq %r0, $1
jz end
; Test addition from a register
mov %status, $2
add %r0, %r0
cmpeq %r0, $2
jz end
; Test addition from a u8 location
mov %status, $3
add %r0, (number)u8
cmpeq %r0, $12
jz end
; Test addition overflow
mov %status, $4
add %r0, $0xFFFFFFFFFFFFFFFF
cmpeq %r0, $11
jz end
; Test subtraction
mov %status, $5
mov %r0, (number)u8
sub %r0, $1
cmpeq %r0, $9
jz end
; Test subtraction from a register
mov %status, $6
mov %r1, $2
sub %r0, %r1
cmpeq %r0, $7
jz end
; Test subtraction overflow
mov %status, $7
sub %r0, $8
cmpeq %r0, $0xFFFFFFFFFFFFFFFF
jz end
; Test multiplication
mov %status, $8
mov %r0, (number)u8
mul %r0, $1
cmpeq %r0, $10
jz end
; Test multiplication from a register
mov %status, $9
mov %r1, $2
mul %r0, %r1
cmpeq %r0, $20
jz end
; Test negative multiplication
mov %status, $10
mul %r0, $0xFFFFFFFFFFFFFFFF ; -1
cmpeq %r0, $0xFFFFFFFFFFFFFFEC ; -20
jz end
; Test division
mov %status, $11
mov %r0, (number)u8
div %r0, $2
cmpeq %r0, $5
jz end
; Test integer division
mov %status, $12
mov %r1, $2
div %r0, %r1
cmpeq %r0, $2
jz end
; Test negative division with idiv
mov %status, $13
idiv %r0, $0xFFFFFFFFFFFFFFFF ; -1
cmpeq %r0, $0xFFFFFFFFFFFFFFFE ; -2
jz end
; Test modulo
mov %status, $14
mov %r0, (number)u8
mod %r0, $4
cmpeq %r0, $2
jz end
; Test mod from a register
mov %status, $15
mod %r0, %r0
cmpeq %r0, $0
jz end
; TODO : Test mod and div by zero
mov %status, $0
end:
halt
.export main
}
.meta {
ip: main
}