Add address deref, syntax, and deref sizes

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-02-25 12:07:24 -05:00
parent bdd08c6c5b
commit 5619c9dc87
11 changed files with 308 additions and 99 deletions

View File

@@ -1,31 +1,32 @@
code $0x0 {
.section data $0x1000 {
beef: .u16 $0xBEEF
; TODO(syntax)
; bytes: .u8 [
; $0xEF,
; $0xBE,
; $0xAD,
; $0xDE,
; ]
.export beef
}
.section code $0x0 {
main:
storeimm32 %r00, $0xDEAD
storeimm64 %r01, $16
shl %r00, %r01
storeimm32 %r01, $0xBEEF
or %r00, %r01
storeimm64 %r01, $0xDEADBEEF
cmpeq %r00, %r01
storeimm32 %r00, failure
storeimm64 %r01, ok
jz %r00
jmp %r01
failure:
storeimm32 %status, $1
ok: halt
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
; jump to the address 'end'
jz end
mov %status, $1
end:
halt
.export main
}
meta {
.meta {
entry: main
}

View File

@@ -1,45 +1,30 @@
data $0x1000 .. $0x1100 {
zstr: .zstring "This is a zero-terminated string"
.section data $0x1000 .. $0x1100 {
zstr: .zstring "This is a string"
str: .string "This is a string"
.export zstr
.export str
}
code $0x0 {
zstr_len:
storeimm32 %r15, $0xFF
storeimm32 %r16, $1
storeimm64 %r20, zstr_next
storeimm64 %r21, exit_zstr
.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)
; %r2: the length of the string (out)
regcopy %r10, %r00
zstr_next:
load %r11, %r10
and %r11, %r15
cmpeq %r11, %null
jnz %r21
add %r10, %r16
jmp %r20
zstrlen:
mov %r2, %r0
ztrlen_loop:
cmpeq (%r2)u8, $0
zstrlen_end:
jmp %r1
main:
storeimm64 %r05, zstr_len
storeimm64 %r00, zstr
jmp %r05
exit_zstr:
regcopy %status, %r10
halt
ineg %r00
add %r10, %r00
regcopy %status, %r10
end:
halt
.export main
}
meta {
.meta {
entry: main
}