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,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
}