//---------------------------------------------------------------------
// Register Usage
//---------------------------------------------------------------------
-// %rsi Program Counter
-// %rsp Stack Pointer
-// %rbp Frame Pointer
-// %rax Accumulator Register
-// %rbx Temporary Register
+.set PC, %rsi
+.set SP, %rsp
+.set FP, %rbp
+.set AC, %rax
+.set T1, %rbx
//---------------------------------------------------------------------
// Main Routine
// Execute next instruction
.macro NEXT
lodsq
- jmpq *(%rax)
+ jmpq *(AC)
.endm
// Macro to define a primitive
.globl EXEC_FUN
.p2align 4, 0x90
EXEC_FUN:
- pushq %rsi
+ pushq PC
pushq %rbp
leaq 8(%rax), %rsi
movq %rsp, %rbp
popq %rdi
call _exit
-// Exit a function, returning to the caller
+// Exit a function, returning to the caller BROKEN!!
defcode OP_return
- lodsq
popq %rbx
- popq %rbp
- popq %rsi
+ movq 8(%rbp), %rsi
+ movq (%rbp), %rbp
+ lodsq
leaq (%rsp, %rax, 8), %rsp
pushq %rbx
NEXT
// Push the Nth argument onto the stack
defcode OP_ldargn
lodsq
- addq $16, %rax
+ addq $2, %rax
neg %rax
movq (%rbp, %rax, 8), %rax
pushq %rax
NEXT
+// Pop top of stack and store to the Nth argument slot
+defcode OP_stargn
+ popq %rbx
+ lodsq
+ addq $2, %rax
+ neg %rax
+ movq %rbx, (%rbp, %rax, 8)
+ NEXT
+
// Push the Nth local onto the stack
defcode OP_ldlocn
lodsq
pushq %rax
NEXT
-// Pop top of stack and store to the Nth argument slot
-defcode OP_stargn
- NEXT
-
// Pop top of stack and store to the Nth local slot
defcode OP_stlocn
+ popq %rbx
+ lodsq
+ movq %rbx, (%rbp, %rax, 8)
NEXT
//---------------------------------------------------------------------
.quad OP_halt
deffun dummy
- .quad OP_imm, 0x2A
+ .quad OP_localsn, 2
+ .quad OP_imm, 0x2B
+ .quad OP_stlocn, 0
+ .quad OP_ldlocn, 0
+ .quad OP_stargn, 0
+ .quad OP_ldargn, 0
.quad OP_return, -2