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,46 +1,46 @@
.section data $0x1000 {
dead: .u16 $0xDEAD
beef: .u16 $0xBEEF
.section data 0x1000 {
dead: .u16 0xDEAD
beef: .u16 0xBEEF
.export dead
.export beef
}
.section code $0x0 {
.section code 0x0 {
main:
mov %ivt, ivt
or %flags, $0b100
mov %r0, $0xDEAD
shl %r0, $16
or %flags, 0b100
mov %r0, 0xDEAD
shl %r0, 16
; move 32 bits at 'beef' to %r01
; TODO(syntax)
mov %r1, (beef)u32
or %r0, %r01
cmpeq %r0, $0xDEADBEEF
cmpeq %r0, 0xDEADBEEF
; jump to the address 'end'
jnz end
mov %status, $1
mov %status, 1
end:
int $0, $0
int 0, 0
halt
.export main
.align u64
dz:
mov %status, $255
mov %status, 255
halt
.export dz
}
.section ivt $0x2000 .. $0x2800 {
.section ivt 0x2000 .. 0x2800 {
ivt:
.interrupt $1, dz ; Divide by zero
.interrupt 1, dz ; Divide by zero
.export ivt
}
.section stack $0x4000 .. $0x5000 {
.section stack 0x4000 .. 0x5000 {
stack_base:
.export stack_base
}

View File

@@ -1,22 +1,22 @@
.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, $5
mov %r0, 5
call factorial
halt

View File

@@ -1,4 +1,4 @@
.section data $0x1000 .. $0x1100 {
.section data 0x1000 .. 0x1100 {
zstr: .zstring "This is a string"
str: .string "This is a string"
@@ -6,7 +6,7 @@
.export str
}
.section code $0x0 {
.section code 0x0 {
; Take the length of a zstr without those fancy "function calls" and "stack frames"
; %r0: the input string (in)
; %r1: the return address (in)
@@ -15,7 +15,7 @@
zstrlen:
mov %r2, %r0
ztrlen_loop:
cmpeq (%r2)u8, $0
cmpeq (%r2)u8, 0
zstrlen_end:
jmp %r1

View File

@@ -1,7 +1,7 @@
%%
\$[0-9]+ "DEC_INT"
\$0[Xx][0-9a-fA-F]+ "HEX_INT"
\$0[Bb][01]+ "BIN_INT"
[0-9]+ "DEC_INT"
0[Xx][0-9a-fA-F]+ "HEX_INT"
0[Bb][01]+ "BIN_INT"
\.meta "DIR_META"
\.section "DIR_SECTION"
\.export "DIR_EXPORT"

View File

@@ -143,17 +143,17 @@ Name -> String:
Int -> u64:
'DEC_INT' {
let span = $1.expect("could not parse dec_int").span();
let s = &$lexer.span_str(span)[1..];
let s = $lexer.span_str(span);
s.parse().unwrap()
}
| 'HEX_INT' {
let span = $1.expect("could not parse hex_int").span();
let s = &$lexer.span_str(span)[3..];
let s = &$lexer.span_str(span)[2..];
u64::from_str_radix(s, 16).unwrap()
}
| 'BIN_INT' {
let span = $1.expect("could not parse bin_int").span();
let s = &$lexer.span_str(span)[3..];
let s = &$lexer.span_str(span)[2..];
u64::from_str_radix(s, 2).unwrap()
}
;

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
}