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) def string(s)
$bytes.push *s.bytes $bytes.push *s.bytes
$bytes.push 0 # null terminate
while (($bytes.length % 4) != 0) do while (($bytes.length % 4) != 0) do
$bytes.push 0 $bytes.push 0
end end
@ -141,6 +142,15 @@ def addi(src, val, dest)
word op word op
end 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 # # # # # # PSEUDO-INSTRUCTIONS # # #
def nop def nop
@ -199,9 +209,33 @@ $bytes = []
# # # PROGRAM CODE # # # # # # PROGRAM CODE # # #
nop 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 # THIS IS NEEDED
lwi $gp1, t0 lwi $gp1, t0
@ -239,19 +273,9 @@ nop ; nop ; nop ; nop
nop ; nop ; nop ; nop nop ; nop ; nop ; nop
l_end_loop = label l_end_loop = label
addiu r0, -10, t3
#addiu t3, 6, t3
addiu t3, -10, t3
nop nop
lwi l_end_loop, t9
addi r0, -10, t4 jr t9
#addi t4, 6, t4
addi t4, -10, t4
nop
nop
jmp l_end_loop
nop nop