@@ 3,32 3,27 @@ use64
format ELF64
public start as '_start'
+; RSP = data stack
+; RSI = virtual instruction stream
+
;; system calls
SYS_WRITE = 1
SYS_EXIT = 60
+;; standard file handles
STDIN = 0
STDOUT = 1
-;;;
-
-ADDR_SIZE = 8 ; addr size in bytes
+;;
-macro dstack { rsp } ; data stack
-; rsi points to virtual instructions
+ADDR_SIZE = 8
macro defcode name {
- public l_#name
-l_#name:
- ;dd link
- ;set link, name_#label
- ;mstr db `name
align ADDR_SIZE
name:
}
-; ASMWORD = array of instructions (aka a label)
-
+;; push/pop data stack
macro pushd r {
lea rsp, [rsp + ADDR_SIZE]
mov [rsp], r
@@ 39,9 34,9 @@ macro popd r {
lea rsp, [rsp - ADDR_SIZE]
}
+;; interpret next instruction pointed to by RSI
macro next {
- ; rsi has type ASMWORD*;
- mov rax, qword [rsi] ; rax = ASMWORD[0] (or *ASMWORD)
+ mov rax, qword [rsi]
lea rsi, [rsi + ADDR_SIZE]
jmp qword rax
}
@@ 94,6 89,31 @@ section '.text' ; readable executable
mov rsi, r8 ; restore rsi
next
+ defcode mstore
+ popd rbx ; addr to store at
+ popd rax ; value to store at addr
+ mov [rbx], rax
+ next
+
+ defcode mfetch
+ popd rbx
+ mov rax, [rbx]
+ pushd rax
+ next
+
+ defcode mstoreb
+ popd rbx
+ popd rax
+ mov [ebx], byte al
+ next
+
+ defcode mfetchb
+ popd rbx
+ xor rax, rax
+ mov al, byte [ebx]
+ pushd rax
+ next
+
defcode exit
mov rax, SYS_EXIT
mov rdi, 0
@@ 113,4 133,3 @@ instrs:
dq emit
dq branch, -32
dq exit
-