Remove dollar sign ($) from front of number tokens

Number tokens with a dollar sign are kind of cumbersome and don't really
serve a purpose, so I'm removing them.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-03-10 15:59:36 -04:00
parent 7c9d4fe908
commit 28edfb6933
9 changed files with 133 additions and 126 deletions

View File

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

View File

@@ -1,72 +1,72 @@
.section data $0x0 {
flags: .u8 $0b1001
.section data 0x0 {
flags: .u8 0b1001
main:
; Test bit and
mov %status, $1
mov %r0, $0b1000
mov %status, 1
mov %r0, 0b1000
and %r0, (flags)u8
cmpeq %r0, $0b1000
cmpeq %r0, 0b1000
jz end
; Test shift right
mov %status, $2
shr %r0, $2
cmpeq %r0, $0b0010
mov %status, 2
shr %r0, 2
cmpeq %r0, 0b0010
jz end
; Test bit and
mov %status, $3
mov %status, 3
and %r0, (flags)u8
cmpeq %r0, $0
cmpeq %r0, 0
jz end
; Test bit or
mov %status, $4
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
mov %status, 5
or %r0, 0b10
cmpeq %r0, 0b1011
jz end
; Test shift left
mov %status, $6
shl %r0, $1
cmpeq %r0, $0b10110
mov %status, 6
shl %r0, 1
cmpeq %r0, 0b10110
jz end
; Test xor
mov %status, $7
mov %status, 7
xor %r0, %r0
cmpeq %r0, $0
cmpeq %r0, 0
jz end
; Test xor
mov %status, $8
mov %r0, $0b1000
mov %status, 8
mov %r0, 0b1000
xor %r0, (flags)u8
cmpeq %r0, $1
cmpeq %r0, 1
jz end
; Test inv
mov %status, $9
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
cmpeq (flags)u8, 0b11110110
jz end
; Test inv again (reset flags to their previous value)
mov %status, $10
mov %status, 10
inv (flags)u8, (flags)u8
cmpeq (flags)u8, $0b00001001
cmpeq (flags)u8, 0b00001001
jz end
mov %status, $0
mov %status, 0
end:
halt

View File

@@ -1,29 +1,29 @@
.section data $0x1000 {
.section data 0x1000 {
factorial:
cmplt %r0, $2
cmplt %r0, 2
jnz factorial_one
push %r0
sub %r0, $1
sub %r0, 1
call factorial
pop %r0
mul %status, %r0
jmp factorial_end
factorial_one:
mov %status, $1
mov %status, 1
factorial_end:
ret
main:
mov %r0, $6
mov %r0, 6
call factorial
cmpeq %status, $720
cmpeq %status, 720
jz fail
mov %status, $0
mov %status, 0
jmp end
fail:
mov %status, $1
mov %status, 1
end:
halt

View File

@@ -1,52 +1,59 @@
.section code $0x0 {
.section code 0x1000 {
main:
; Test that interrupts will not called when enabled flag is not set
int 0, 0
cmpeq (count), 0
jnz end
; Test divide by zero interrupts
; div
mov %status, $1
mov %r0, $1
div %r0, $0
cmpeq (count), $1
add %status, 1
mov %r0, 1
div %r0, 0
cmpeq (count), 1
jz end
; idiv
mov %status, $2
idiv %r0, $0
cmpeq (count), $2
add %status, 1
idiv %r0, 0
cmpeq (count), 2
jz end
mov %status, $0
mov %status, 0
end:
halt
.align u64
divide_by_zero:
add (count), $1
generic_handler:
add (count), 1
iret
.export main
.export divide_by_zero
.export generic_handler
}
.section ivt $0x1000 {
.section ivt 0x1800 {
ivt:
.interrupt $1, divide_by_zero
.interrupt 0, 0
.interrupt 0, 0
.interrupt 0, 0
.interrupt 1, generic_handler
.export ivt
}
.section shared $0x2000 {
count: .u64 $0
.section shared 0x2000 {
count: .u64 0
.export count
}
.section stack $0x4000 .. $0x5000 {
.section stack 0x4000 .. 0x5000 {
stack_base:
.export stack_base
}
.meta {
ip: main
flags: $0b100
sp: stack_base
ivt: ivt
}