// Register Usage
//---------------------------------------------------------------------
// %rsi Program Counter
-// %rsp Argument Stack Pointer
-// %rbp Stack Frame Pointer
+// %rsp Stack Pointer
+// %rbp Frame Pointer
// %rax Accumulator Register
// %rbx Temporary Register
// Execute next instruction
.macro NEXT
lodsq
- jmpq *(%rax)
+ jmpq *(%rax)
.endm
// Macro to define a primitive
\name :
.quad code_\name
.text
- .globl code_\name
- .p2align 4, 0x90
+ .globl code_\name
+ .p2align 4, 0x90
code_\name :
// ...the code goes here...
.endm
// Main Interpreter Definition
.text
- .globl EXEC_FUN
- .p2align 4, 0x90
+ .globl EXEC_FUN
+ .p2align 4, 0x90
EXEC_FUN:
pushq %rsi
pushq %rbp
// Push the Nth argument onto the stack
defcode OP_ldargn
+ lodsq
+ addq $16, %rax
+ neg %rax
+ movq (%rbp, %rax, 8), %rax
+ pushq %rax
NEXT
// Push the Nth local onto the stack
defcode OP_ldlocn
+ lodsq
+ movq (%rbp, %rax, 8), %rax
+ pushq %rax
NEXT
// Pop top of stack and store to the Nth argument slot
// Main Routine
//---------------------------------------------------------------------
.text
- .global _main
- .global main
- .p2align 4, 0x90
+ .global _main
+ .global main
+ .p2align 4, 0x90
_main:
main:
pushq %rax
movq %rsp, %rbp
- leaq cold_start(%rip), %rsi
- NEXT
+ leaq cold_start(%rip), %rsi
+ NEXT
// First instructions to execute by the interpreter
.data