Add bitwise tests, squash all arithmetic tests into test_arithmetic

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-02-25 14:10:21 -05:00
parent 362590292a
commit bc4f59ecad
7 changed files with 194 additions and 174 deletions

View File

@@ -1,38 +0,0 @@
.section data $0x0 {
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
mov %status, $0
end:
halt
.export main
}
.meta {
entry: main
}

114
tests/test_arithmetic.asm Normal file
View File

@@ -0,0 +1,114 @@
.section data $0x0 {
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 {
entry: main
}

80
tests/test_bitwise.asm Normal file
View File

@@ -0,0 +1,80 @@
.section data $0x0 {
flags: .u8 $0b1001
main:
; Test bit and
mov %status, $1
mov %r0, $0b1000
and %r0, (flags)u8
cmpeq %r0, $0b1000
jz end
; Test shift right
mov %status, $2
shr %r0, $2
cmpeq %r0, $0b0010
jz end
; Test bit and
mov %status, $3
and %r0, (flags)u8
cmpeq %r0, $0
jz end
; Test bit or
mov %status, $4
or %r0, (flags)u8
cmpeq %r0, (flags)u8
jz end
; Test bit or
mov %status, $5
or %r0, $0b10
cmpeq %r0, $0b1011
jz end
; Test shift left
mov %status, $6
shl %r0, $1
cmpeq %r0, $0b10110
jz end
; Test xor
mov %status, $7
xor %r0, %r0
cmpeq %r0, $0
jz end
; Test xor
mov %status, $8
mov %r0, $0b1000
xor %r0, (flags)u8
cmpeq %r0, $1
jz end
; Test inv
mov %status, $9
; TODO : destination size - the line below inverts all 64 bits instead of the source 8 bits
; inv %r0, (flags)u8
inv (flags)u8, (flags)u8
cmpeq (flags)u8, $0b11110110
jz end
; Test inv again (reset flags to their previous value)
mov %status, $10
inv (flags)u8, (flags)u8
cmpeq (flags)u8, $0b00001001
jz end
mov %status, $0
end:
halt
.export main
}
.meta {
entry: main
}

View File

@@ -1,34 +0,0 @@
.section data $0x0 {
number: .u8 $10
main:
; Test division
mov %status, $1
mov %r0, (number)u8
div %r0, $2
cmpeq %r0, $5
jz end
; Test integer division
mov %status, $2
mov %r1, $2
div %r0, %r1
cmpeq %r0, $2
jz end
; Test negative division with idiv
mov %status, $3
idiv %r0, $0xFFFFFFFFFFFFFFFF ; -1
cmpeq %r0, $0xFFFFFFFFFFFFFFFE ; -2
jz end
mov %status, $0
end:
halt
.export main
}
.meta {
entry: main
}

View File

@@ -1,34 +0,0 @@
.section data $0x0 {
number: .u8 $10
main:
; Test modulo
mov %status, $1
mov %r0, (number)u8
mod $r0, $4
cmpeq %r0, $2
jz end
; Test modulo from a register
mov %status, $2
add %r0, %r0
cmpeq %r0, $2
jz end
; Test mod by zero
mov %status, $4
add %r0, $0xFFFFFFFFFFFFFFFF
cmpeq %r0, $11
jz end
mov %status, $0
end:
halt
.export main
}
.meta {
entry: main
}

View File

@@ -1,34 +0,0 @@
.section data $0x0 {
number: .u8 $10
main:
; Test multiplication
mov %status, $1
mov %r0, (number)u8
mul %r0, $1
cmpeq %r0, $10
jz end
; Test multiplication from a register
mov %status, $2
mov %r1, $2
mul %r0, %r1
cmpeq %r0, $20
jz end
; Test negative multiplication
mov %status, $3
mul %r0, $0xFFFFFFFFFFFFFFFF ; -1
cmpeq %r0, $0xFFFFFFFFFFFFFFEC ; -20
jz end
mov %status, $0
end:
halt
.export main
}
.meta {
entry: main
}

View File

@@ -1,34 +0,0 @@
.section data $0x0 {
number: .u8 $10
main:
; Test subtraction
mov %status, $1
mov %r0, (number)u8
sub %r0, $1
cmpeq %r0, $9
jz end
; Test subtraction from a register
mov %status, $2
mov %r1, $2
sub %r0, %r1
cmpeq %r0, $7
jz end
; Test subtraction overflow
mov %status, $3
sub %r0, $8
cmpeq %r0, $0xFFFFFFFFFFFFFFFF
jz end
mov %status, $0
end:
halt
.export main
}
.meta {
entry: main
}