got printf working with static string!

master
bx 2021-08-31 22:22:29 +01:00
parent 1047cb9268
commit 943f45dcc3
1 changed files with 38 additions and 14 deletions

View File

@ -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