From c8c918f5b59b2a34663ff84f24b0783fb9fce725 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 4 Mar 2021 16:56:36 -0500 Subject: [PATCH] tried finishing local and argument storing and fetching. Pretty sure those and/or the return primitive are busted --- main.s | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/main.s b/main.s index f93ae8a..d6514de 100644 --- a/main.s +++ b/main.s @@ -1,11 +1,11 @@ //--------------------------------------------------------------------- // 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 @@ -14,7 +14,7 @@ // Execute next instruction .macro NEXT lodsq - jmpq *(%rax) + jmpq *(AC) .endm // Macro to define a primitive @@ -46,7 +46,7 @@ code_\name : .globl EXEC_FUN .p2align 4, 0x90 EXEC_FUN: - pushq %rsi + pushq PC pushq %rbp leaq 8(%rax), %rsi movq %rsp, %rbp @@ -61,12 +61,12 @@ defcode OP_halt 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 @@ -98,12 +98,21 @@ defcode OP_localsn // 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 @@ -111,12 +120,11 @@ defcode OP_ldlocn 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 //--------------------------------------------------------------------- @@ -144,5 +152,10 @@ cold_start: .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 -- 2.49.0