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:
@@ -1,46 +1,46 @@
|
|||||||
.section data $0x1000 {
|
.section data 0x1000 {
|
||||||
dead: .u16 $0xDEAD
|
dead: .u16 0xDEAD
|
||||||
beef: .u16 $0xBEEF
|
beef: .u16 0xBEEF
|
||||||
|
|
||||||
.export dead
|
.export dead
|
||||||
.export beef
|
.export beef
|
||||||
}
|
}
|
||||||
|
|
||||||
.section code $0x0 {
|
.section code 0x0 {
|
||||||
main:
|
main:
|
||||||
mov %ivt, ivt
|
mov %ivt, ivt
|
||||||
or %flags, $0b100
|
or %flags, 0b100
|
||||||
mov %r0, $0xDEAD
|
mov %r0, 0xDEAD
|
||||||
shl %r0, $16
|
shl %r0, 16
|
||||||
; move 32 bits at 'beef' to %r01
|
; move 32 bits at 'beef' to %r01
|
||||||
; TODO(syntax)
|
; TODO(syntax)
|
||||||
mov %r1, (beef)u32
|
mov %r1, (beef)u32
|
||||||
or %r0, %r01
|
or %r0, %r01
|
||||||
cmpeq %r0, $0xDEADBEEF
|
cmpeq %r0, 0xDEADBEEF
|
||||||
; jump to the address 'end'
|
; jump to the address 'end'
|
||||||
jnz end
|
jnz end
|
||||||
mov %status, $1
|
mov %status, 1
|
||||||
end:
|
end:
|
||||||
int $0, $0
|
int 0, 0
|
||||||
halt
|
halt
|
||||||
.export main
|
.export main
|
||||||
|
|
||||||
.align u64
|
.align u64
|
||||||
dz:
|
dz:
|
||||||
mov %status, $255
|
mov %status, 255
|
||||||
halt
|
halt
|
||||||
|
|
||||||
.export dz
|
.export dz
|
||||||
}
|
}
|
||||||
|
|
||||||
.section ivt $0x2000 .. $0x2800 {
|
.section ivt 0x2000 .. 0x2800 {
|
||||||
ivt:
|
ivt:
|
||||||
.interrupt $1, dz ; Divide by zero
|
.interrupt 1, dz ; Divide by zero
|
||||||
|
|
||||||
.export ivt
|
.export ivt
|
||||||
}
|
}
|
||||||
|
|
||||||
.section stack $0x4000 .. $0x5000 {
|
.section stack 0x4000 .. 0x5000 {
|
||||||
stack_base:
|
stack_base:
|
||||||
.export stack_base
|
.export stack_base
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
.section data $0x1000 {
|
.section data 0x1000 {
|
||||||
factorial:
|
factorial:
|
||||||
cmplt %r0, $2
|
cmplt %r0, 2
|
||||||
jnz factorial_one
|
jnz factorial_one
|
||||||
|
|
||||||
push %r0
|
push %r0
|
||||||
sub %r0, $1
|
sub %r0, 1
|
||||||
call factorial
|
call factorial
|
||||||
pop %r0
|
pop %r0
|
||||||
mul %status, %r0
|
mul %status, %r0
|
||||||
jmp factorial_end
|
jmp factorial_end
|
||||||
|
|
||||||
factorial_one:
|
factorial_one:
|
||||||
mov %status, $1
|
mov %status, 1
|
||||||
factorial_end:
|
factorial_end:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
main:
|
main:
|
||||||
mov %r0, $5
|
mov %r0, 5
|
||||||
call factorial
|
call factorial
|
||||||
halt
|
halt
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.section data $0x1000 .. $0x1100 {
|
.section data 0x1000 .. 0x1100 {
|
||||||
zstr: .zstring "This is a string"
|
zstr: .zstring "This is a string"
|
||||||
str: .string "This is a string"
|
str: .string "This is a string"
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
.export str
|
.export str
|
||||||
}
|
}
|
||||||
|
|
||||||
.section code $0x0 {
|
.section code 0x0 {
|
||||||
; Take the length of a zstr without those fancy "function calls" and "stack frames"
|
; Take the length of a zstr without those fancy "function calls" and "stack frames"
|
||||||
; %r0: the input string (in)
|
; %r0: the input string (in)
|
||||||
; %r1: the return address (in)
|
; %r1: the return address (in)
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
zstrlen:
|
zstrlen:
|
||||||
mov %r2, %r0
|
mov %r2, %r0
|
||||||
ztrlen_loop:
|
ztrlen_loop:
|
||||||
cmpeq (%r2)u8, $0
|
cmpeq (%r2)u8, 0
|
||||||
zstrlen_end:
|
zstrlen_end:
|
||||||
jmp %r1
|
jmp %r1
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
%%
|
%%
|
||||||
\$[0-9]+ "DEC_INT"
|
[0-9]+ "DEC_INT"
|
||||||
\$0[Xx][0-9a-fA-F]+ "HEX_INT"
|
0[Xx][0-9a-fA-F]+ "HEX_INT"
|
||||||
\$0[Bb][01]+ "BIN_INT"
|
0[Bb][01]+ "BIN_INT"
|
||||||
\.meta "DIR_META"
|
\.meta "DIR_META"
|
||||||
\.section "DIR_SECTION"
|
\.section "DIR_SECTION"
|
||||||
\.export "DIR_EXPORT"
|
\.export "DIR_EXPORT"
|
||||||
|
|||||||
@@ -143,17 +143,17 @@ Name -> String:
|
|||||||
Int -> u64:
|
Int -> u64:
|
||||||
'DEC_INT' {
|
'DEC_INT' {
|
||||||
let span = $1.expect("could not parse dec_int").span();
|
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()
|
s.parse().unwrap()
|
||||||
}
|
}
|
||||||
| 'HEX_INT' {
|
| 'HEX_INT' {
|
||||||
let span = $1.expect("could not parse hex_int").span();
|
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()
|
u64::from_str_radix(s, 16).unwrap()
|
||||||
}
|
}
|
||||||
| 'BIN_INT' {
|
| 'BIN_INT' {
|
||||||
let span = $1.expect("could not parse bin_int").span();
|
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()
|
u64::from_str_radix(s, 2).unwrap()
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -1,107 +1,107 @@
|
|||||||
.section data $0x1000 {
|
.section data 0x1000 {
|
||||||
number: .u8 $10
|
number: .u8 10
|
||||||
|
|
||||||
main:
|
main:
|
||||||
; Test addition
|
; Test addition
|
||||||
mov %status, $1
|
mov %status, 1
|
||||||
add %r0, $1
|
add %r0, 1
|
||||||
cmpeq %r0, $1
|
cmpeq %r0, 1
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test addition from a register
|
; Test addition from a register
|
||||||
mov %status, $2
|
mov %status, 2
|
||||||
add %r0, %r0
|
add %r0, %r0
|
||||||
cmpeq %r0, $2
|
cmpeq %r0, 2
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test addition from a u8 location
|
; Test addition from a u8 location
|
||||||
mov %status, $3
|
mov %status, 3
|
||||||
add %r0, (number)u8
|
add %r0, (number)u8
|
||||||
cmpeq %r0, $12
|
cmpeq %r0, 12
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test addition overflow
|
; Test addition overflow
|
||||||
mov %status, $4
|
mov %status, 4
|
||||||
add %r0, $0xFFFFFFFFFFFFFFFF
|
add %r0, 0xFFFFFFFFFFFFFFFF
|
||||||
cmpeq %r0, $11
|
cmpeq %r0, 11
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test subtraction
|
; Test subtraction
|
||||||
mov %status, $5
|
mov %status, 5
|
||||||
mov %r0, (number)u8
|
mov %r0, (number)u8
|
||||||
sub %r0, $1
|
sub %r0, 1
|
||||||
cmpeq %r0, $9
|
cmpeq %r0, 9
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test subtraction from a register
|
; Test subtraction from a register
|
||||||
mov %status, $6
|
mov %status, 6
|
||||||
mov %r1, $2
|
mov %r1, 2
|
||||||
sub %r0, %r1
|
sub %r0, %r1
|
||||||
cmpeq %r0, $7
|
cmpeq %r0, 7
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test subtraction overflow
|
; Test subtraction overflow
|
||||||
mov %status, $7
|
mov %status, 7
|
||||||
sub %r0, $8
|
sub %r0, 8
|
||||||
cmpeq %r0, $0xFFFFFFFFFFFFFFFF
|
cmpeq %r0, 0xFFFFFFFFFFFFFFFF
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test multiplication
|
; Test multiplication
|
||||||
mov %status, $8
|
mov %status, 8
|
||||||
mov %r0, (number)u8
|
mov %r0, (number)u8
|
||||||
mul %r0, $1
|
mul %r0, 1
|
||||||
cmpeq %r0, $10
|
cmpeq %r0, 10
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test multiplication from a register
|
; Test multiplication from a register
|
||||||
mov %status, $9
|
mov %status, 9
|
||||||
mov %r1, $2
|
mov %r1, 2
|
||||||
mul %r0, %r1
|
mul %r0, %r1
|
||||||
cmpeq %r0, $20
|
cmpeq %r0, 20
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test negative multiplication
|
; Test negative multiplication
|
||||||
mov %status, $10
|
mov %status, 10
|
||||||
mul %r0, $0xFFFFFFFFFFFFFFFF ; -1
|
mul %r0, 0xFFFFFFFFFFFFFFFF ; -1
|
||||||
cmpeq %r0, $0xFFFFFFFFFFFFFFEC ; -20
|
cmpeq %r0, 0xFFFFFFFFFFFFFFEC ; -20
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test division
|
; Test division
|
||||||
mov %status, $11
|
mov %status, 11
|
||||||
mov %r0, (number)u8
|
mov %r0, (number)u8
|
||||||
div %r0, $2
|
div %r0, 2
|
||||||
cmpeq %r0, $5
|
cmpeq %r0, 5
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test integer division
|
; Test integer division
|
||||||
mov %status, $12
|
mov %status, 12
|
||||||
mov %r1, $2
|
mov %r1, 2
|
||||||
div %r0, %r1
|
div %r0, %r1
|
||||||
cmpeq %r0, $2
|
cmpeq %r0, 2
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test negative division with idiv
|
; Test negative division with idiv
|
||||||
mov %status, $13
|
mov %status, 13
|
||||||
idiv %r0, $0xFFFFFFFFFFFFFFFF ; -1
|
idiv %r0, 0xFFFFFFFFFFFFFFFF ; -1
|
||||||
cmpeq %r0, $0xFFFFFFFFFFFFFFFE ; -2
|
cmpeq %r0, 0xFFFFFFFFFFFFFFFE ; -2
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test modulo
|
; Test modulo
|
||||||
mov %status, $14
|
mov %status, 14
|
||||||
mov %r0, (number)u8
|
mov %r0, (number)u8
|
||||||
mod %r0, $4
|
mod %r0, 4
|
||||||
cmpeq %r0, $2
|
cmpeq %r0, 2
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test mod from a register
|
; Test mod from a register
|
||||||
mov %status, $15
|
mov %status, 15
|
||||||
mod %r0, %r0
|
mod %r0, %r0
|
||||||
cmpeq %r0, $0
|
cmpeq %r0, 0
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; TODO : Test mod and div by zero
|
; TODO : Test mod and div by zero
|
||||||
|
|
||||||
mov %status, $0
|
mov %status, 0
|
||||||
end:
|
end:
|
||||||
halt
|
halt
|
||||||
|
|
||||||
|
|||||||
@@ -1,72 +1,72 @@
|
|||||||
.section data $0x0 {
|
.section data 0x0 {
|
||||||
flags: .u8 $0b1001
|
flags: .u8 0b1001
|
||||||
|
|
||||||
main:
|
main:
|
||||||
; Test bit and
|
; Test bit and
|
||||||
mov %status, $1
|
mov %status, 1
|
||||||
mov %r0, $0b1000
|
mov %r0, 0b1000
|
||||||
and %r0, (flags)u8
|
and %r0, (flags)u8
|
||||||
cmpeq %r0, $0b1000
|
cmpeq %r0, 0b1000
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test shift right
|
; Test shift right
|
||||||
mov %status, $2
|
mov %status, 2
|
||||||
shr %r0, $2
|
shr %r0, 2
|
||||||
cmpeq %r0, $0b0010
|
cmpeq %r0, 0b0010
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test bit and
|
; Test bit and
|
||||||
mov %status, $3
|
mov %status, 3
|
||||||
and %r0, (flags)u8
|
and %r0, (flags)u8
|
||||||
cmpeq %r0, $0
|
cmpeq %r0, 0
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test bit or
|
; Test bit or
|
||||||
mov %status, $4
|
mov %status, 4
|
||||||
or %r0, (flags)u8
|
or %r0, (flags)u8
|
||||||
cmpeq %r0, (flags)u8
|
cmpeq %r0, (flags)u8
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test bit or
|
; Test bit or
|
||||||
mov %status, $5
|
mov %status, 5
|
||||||
or %r0, $0b10
|
or %r0, 0b10
|
||||||
cmpeq %r0, $0b1011
|
cmpeq %r0, 0b1011
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test shift left
|
; Test shift left
|
||||||
mov %status, $6
|
mov %status, 6
|
||||||
shl %r0, $1
|
shl %r0, 1
|
||||||
cmpeq %r0, $0b10110
|
cmpeq %r0, 0b10110
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test xor
|
; Test xor
|
||||||
mov %status, $7
|
mov %status, 7
|
||||||
xor %r0, %r0
|
xor %r0, %r0
|
||||||
cmpeq %r0, $0
|
cmpeq %r0, 0
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test xor
|
; Test xor
|
||||||
mov %status, $8
|
mov %status, 8
|
||||||
mov %r0, $0b1000
|
mov %r0, 0b1000
|
||||||
xor %r0, (flags)u8
|
xor %r0, (flags)u8
|
||||||
cmpeq %r0, $1
|
cmpeq %r0, 1
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test inv
|
; Test inv
|
||||||
mov %status, $9
|
mov %status, 9
|
||||||
; TODO : destination size - the line below inverts all 64 bits instead of the source 8 bits
|
; TODO : destination size - the line below inverts all 64 bits instead of the source 8 bits
|
||||||
; inv %r0, (flags)u8
|
; inv %r0, (flags)u8
|
||||||
inv (flags)u8, (flags)u8
|
inv (flags)u8, (flags)u8
|
||||||
cmpeq (flags)u8, $0b11110110
|
cmpeq (flags)u8, 0b11110110
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; Test inv again (reset flags to their previous value)
|
; Test inv again (reset flags to their previous value)
|
||||||
mov %status, $10
|
mov %status, 10
|
||||||
inv (flags)u8, (flags)u8
|
inv (flags)u8, (flags)u8
|
||||||
cmpeq (flags)u8, $0b00001001
|
cmpeq (flags)u8, 0b00001001
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
mov %status, $0
|
mov %status, 0
|
||||||
end:
|
end:
|
||||||
halt
|
halt
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
.section data $0x1000 {
|
.section data 0x1000 {
|
||||||
factorial:
|
factorial:
|
||||||
cmplt %r0, $2
|
cmplt %r0, 2
|
||||||
jnz factorial_one
|
jnz factorial_one
|
||||||
|
|
||||||
push %r0
|
push %r0
|
||||||
sub %r0, $1
|
sub %r0, 1
|
||||||
call factorial
|
call factorial
|
||||||
pop %r0
|
pop %r0
|
||||||
mul %status, %r0
|
mul %status, %r0
|
||||||
jmp factorial_end
|
jmp factorial_end
|
||||||
|
|
||||||
factorial_one:
|
factorial_one:
|
||||||
mov %status, $1
|
mov %status, 1
|
||||||
factorial_end:
|
factorial_end:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
main:
|
main:
|
||||||
mov %r0, $6
|
mov %r0, 6
|
||||||
call factorial
|
call factorial
|
||||||
cmpeq %status, $720
|
cmpeq %status, 720
|
||||||
jz fail
|
jz fail
|
||||||
mov %status, $0
|
mov %status, 0
|
||||||
jmp end
|
jmp end
|
||||||
fail:
|
fail:
|
||||||
mov %status, $1
|
mov %status, 1
|
||||||
end:
|
end:
|
||||||
halt
|
halt
|
||||||
|
|
||||||
|
|||||||
@@ -1,52 +1,59 @@
|
|||||||
.section code $0x0 {
|
.section code 0x1000 {
|
||||||
main:
|
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
|
; Test divide by zero interrupts
|
||||||
|
|
||||||
; div
|
; div
|
||||||
mov %status, $1
|
add %status, 1
|
||||||
mov %r0, $1
|
mov %r0, 1
|
||||||
div %r0, $0
|
div %r0, 0
|
||||||
cmpeq (count), $1
|
cmpeq (count), 1
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
; idiv
|
; idiv
|
||||||
mov %status, $2
|
add %status, 1
|
||||||
idiv %r0, $0
|
idiv %r0, 0
|
||||||
cmpeq (count), $2
|
cmpeq (count), 2
|
||||||
jz end
|
jz end
|
||||||
|
|
||||||
mov %status, $0
|
mov %status, 0
|
||||||
end:
|
end:
|
||||||
halt
|
halt
|
||||||
|
|
||||||
.align u64
|
.align u64
|
||||||
divide_by_zero:
|
generic_handler:
|
||||||
add (count), $1
|
add (count), 1
|
||||||
iret
|
iret
|
||||||
|
|
||||||
.export main
|
.export main
|
||||||
.export divide_by_zero
|
.export generic_handler
|
||||||
}
|
}
|
||||||
|
|
||||||
.section ivt $0x1000 {
|
.section ivt 0x1800 {
|
||||||
ivt:
|
ivt:
|
||||||
.interrupt $1, divide_by_zero
|
.interrupt 0, 0
|
||||||
|
.interrupt 0, 0
|
||||||
|
.interrupt 0, 0
|
||||||
|
.interrupt 1, generic_handler
|
||||||
.export ivt
|
.export ivt
|
||||||
}
|
}
|
||||||
|
|
||||||
.section shared $0x2000 {
|
.section shared 0x2000 {
|
||||||
count: .u64 $0
|
count: .u64 0
|
||||||
.export count
|
.export count
|
||||||
}
|
}
|
||||||
|
|
||||||
.section stack $0x4000 .. $0x5000 {
|
.section stack 0x4000 .. 0x5000 {
|
||||||
stack_base:
|
stack_base:
|
||||||
.export stack_base
|
.export stack_base
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta {
|
.meta {
|
||||||
ip: main
|
ip: main
|
||||||
flags: $0b100
|
|
||||||
sp: stack_base
|
sp: stack_base
|
||||||
ivt: ivt
|
ivt: ivt
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user