Move examples to libvm source base and add symlink to root directory

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-03-06 12:18:20 -05:00
parent b1f2de198e
commit 58262eab40
4 changed files with 20 additions and 0 deletions

1
examples Symbolic link
View File

@@ -0,0 +1 @@
src/libvm/examples/

View File

@@ -1,28 +0,0 @@
.section data $0x1000 {
dead: .u16 $0xDEAD
beef: .u16 $0xBEEF
.export dead
.export beef
}
.section code $0x0 {
main:
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'
jnz end
mov %status, $1
end:
halt
.export main
}
.meta {
entry: main
}

View File

@@ -1,28 +0,0 @@
.section data $0x1000 {
factorial:
cmplt %r0, $2
jnz factorial_one
push %r0
sub %r0, $1
call factorial
pop %r0
mul %status, %r0
jmp factorial_end
factorial_one:
mov %status, $1
factorial_end:
ret
main:
mov %r0, $5
call factorial
halt
.export main
}
.meta {
entry: main
}

View File

@@ -1,30 +0,0 @@
.section data $0x1000 .. $0x1100 {
zstr: .zstring "This is a string"
str: .string "This is a string"
.export zstr
.export str
}
.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)
zstrlen:
mov %r2, %r0
ztrlen_loop:
cmpeq (%r2)u8, $0
zstrlen_end:
jmp %r1
main:
halt
.export main
}
.meta {
entry: main
}