From 943f45dcc3cc8bba853256ed6c2b58adea738d09 Mon Sep 17 00:00:00 2001 From: bx Date: Tue, 31 Aug 2021 22:22:29 +0100 Subject: [PATCH] got printf working with static string! --- assembler.rb | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/assembler.rb b/assembler.rb index 8c5a10d..4173c14 100644 --- a/assembler.rb +++ b/assembler.rb @@ -16,6 +16,7 @@ end def string(s) $bytes.push *s.bytes + $bytes.push 0 # null terminate while (($bytes.length % 4) != 0) do $bytes.push 0 end @@ -141,6 +142,15 @@ def addi(src, val, dest) word op end +# jump register +def jr(reg) + # oooooo rrrrr ----- ----- ----- oooooo + op = 0b000000_00000_00000_00000_00000_001000 + op |= (reg & 0b11111) << 21 + word op +end + + # # # PSEUDO-INSTRUCTIONS # # # def nop @@ -199,9 +209,33 @@ $bytes = [] # # # PROGRAM CODE # # # nop +jmp $base_addr + 0x400 +nop + +l_hello_world = label +string "ello wrld!\n" + + + +l_printf = label +addiu r0, 0xa0, at # address of bios func +jr at +addiu r0, 0x3f, t1 # printf number + + + +zero_fill 0x400 - 1 +nop + + + +lwi l_hello_world, a0 +jal l_printf +addiu sp, -16, sp # delay slot +addiu sp, 16, sp + +nop ; nop ; nop ; nop -# ops should always be in format of -# src [args] -> dest # THIS IS NEEDED lwi $gp1, t0 @@ -239,19 +273,9 @@ nop ; nop ; nop ; nop nop ; nop ; nop ; nop l_end_loop = label - -addiu r0, -10, t3 -#addiu t3, 6, t3 -addiu t3, -10, t3 nop - -addi r0, -10, t4 -#addi t4, 6, t4 -addi t4, -10, t4 -nop - -nop -jmp l_end_loop +lwi l_end_loop, t9 +jr t9 nop