Compare commits
3 Commits
2810109764
...
0989bd54f0
Author | SHA1 | Date |
---|---|---|
bx | 0989bd54f0 | |
bx | a7979dfeab | |
bx | eb67ac6c5e |
25
assembler.rb
25
assembler.rb
|
@ -6,7 +6,7 @@ def r0() 0 end # zero
|
||||||
def at() 1 end # assembler temporary
|
def at() 1 end # assembler temporary
|
||||||
|
|
||||||
# subroutine return values, may be changed by subroutines
|
# subroutine return values, may be changed by subroutines
|
||||||
def v0() 2 end ; def v0() 3 end
|
def v0() 2 end ; def v1() 3 end
|
||||||
|
|
||||||
# subroutine arguments, may be changed by subroutines
|
# subroutine arguments, may be changed by subroutines
|
||||||
def a0() 4 end ; def a1() 5 end
|
def a0() 4 end ; def a1() 5 end
|
||||||
|
@ -193,13 +193,32 @@ class Assembler
|
||||||
word op
|
word op
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: actually encode "comment" argument
|
||||||
|
def syscall(comment)
|
||||||
|
# iiiiii ccccc ccccc ccccc ccccc iiiiii
|
||||||
|
op = 0b000000_00000_00000_00000_00000_001100
|
||||||
|
word op
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: expose the return address storage register
|
||||||
|
# NOTE: cannot use the same register for both operands
|
||||||
|
def jalr(reg)
|
||||||
|
# jumps to addr in j and stores return adr in r
|
||||||
|
# iiiiii jjjjj ----- rrrrr ----- iiiiii
|
||||||
|
op = 0b000000_00000_00000_00000_00000_001001
|
||||||
|
op |= (reg & 0b11111) << 21
|
||||||
|
op |= (ra) << 11 # ra
|
||||||
|
word op
|
||||||
|
end
|
||||||
|
|
||||||
# # # PSEUDO-INSTRUCTIONS # # #
|
# # # PSEUDO-INSTRUCTIONS # # #
|
||||||
def nop
|
def nop
|
||||||
word 0x00000000
|
word 0x00000000
|
||||||
end
|
end
|
||||||
|
|
||||||
# load word immediate
|
# load immediate
|
||||||
def lwi(val, dest)
|
# TODO: check if we need to use 1 or 2 ops and output that
|
||||||
|
def li(dest, val)
|
||||||
lui val >> 16, dest
|
lui val >> 16, dest
|
||||||
ori dest, val, dest
|
ori dest, val, dest
|
||||||
end
|
end
|
||||||
|
|
29
main.asm.rb
29
main.asm.rb
|
@ -4,6 +4,9 @@
|
||||||
$gp0 = 0x1F801810
|
$gp0 = 0x1F801810
|
||||||
$gp1 = 0x1F801814
|
$gp1 = 0x1F801814
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
# FIND OUT WHAT WE HAVE TO DO TO REGISTER A VSYNC INTERRUPT
|
||||||
|
|
||||||
jmp l_start
|
jmp l_start
|
||||||
nop
|
nop
|
||||||
|
|
||||||
|
@ -17,10 +20,10 @@ label :printf
|
||||||
|
|
||||||
label :draw_line
|
label :draw_line
|
||||||
# todo: draw line function, take args in a0 - a3
|
# todo: draw line function, take args in a0 - a3
|
||||||
# tood: implement shift left so we can use that
|
# tood: implement shift left so we can use that to combine x and y co-ords
|
||||||
lwi $gp0, t0
|
li t0, $gp0
|
||||||
|
|
||||||
lwi 0x40_ffffff, t1 # monochrome line, color ffffff
|
li t1, 0x40_ffffff # monochrome line, color ffffff
|
||||||
sw t1, 0, t0
|
sw t1, 0, t0
|
||||||
|
|
||||||
# lwi st, t1 # line vert 1
|
# lwi st, t1 # line vert 1
|
||||||
|
@ -33,27 +36,27 @@ label :start
|
||||||
nop ; nop ; nop ; nop
|
nop ; nop ; nop ; nop
|
||||||
|
|
||||||
# THIS IS NEEDED
|
# THIS IS NEEDED
|
||||||
lwi $gp1, t0
|
li t0, $gp1
|
||||||
lwi 0x03_00_00_00, t1 # display enable
|
li t1, 0x03_00_00_00 # display enable
|
||||||
sw t1, 0, t0
|
sw t1, 0, t0
|
||||||
|
|
||||||
lwi $gp0, t0
|
li t0, $gp0
|
||||||
|
|
||||||
lwi 0xe1_000000 + 0b0_0_0_1_0_01_00_0_0000, t1
|
li t1, 0xe1_000000 + 0b0_0_0_1_0_01_00_0_0000
|
||||||
sw t1, 0, t0
|
sw t1, 0, t0
|
||||||
|
|
||||||
# THIS IS NEEDED
|
# THIS IS NEEDED
|
||||||
lwi 0xe4_000000 + (640) + (480 << 10), t1 # Drawing Area bottom right
|
li t1, 0xe4_000000 + (640) + (480 << 10) # Drawing Area bottom right
|
||||||
sw t1, 0, t0
|
sw t1, 0, t0
|
||||||
|
|
||||||
def line(st, en)
|
def line(st, en)
|
||||||
lwi 0x40_ffffff, t1 # monochrome line, color ffffff
|
li t1, 0x40_ffffff # monochrome line, color ffffff
|
||||||
sw t1, 0, t0
|
sw t1, 0, t0
|
||||||
|
|
||||||
lwi st, t1 # line vert 1
|
li t1, st # line vert 1
|
||||||
sw t1, 0, t0
|
sw t1, 0, t0
|
||||||
|
|
||||||
lwi en, t1 # line vert 2
|
li t1, en # line vert 2
|
||||||
sw t1, 0, t0
|
sw t1, 0, t0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -61,13 +64,13 @@ label :start
|
||||||
line 0x0030_0030, 0x0060_0000
|
line 0x0030_0030, 0x0060_0000
|
||||||
line 0x0060_000a, 0x00f0_0060
|
line 0x0060_000a, 0x00f0_0060
|
||||||
|
|
||||||
lwi l_hello_world, a0
|
li a0, l_hello_world
|
||||||
jal l_printf
|
jal l_printf
|
||||||
addiu sp, -16, sp # delay slot
|
addiu sp, -16, sp # delay slot
|
||||||
addiu sp, 16, sp
|
addiu sp, 16, sp
|
||||||
|
|
||||||
label :end_loop
|
label :end_loop
|
||||||
lwi l_end_loop, t9
|
li t9, l_end_loop
|
||||||
jr t9
|
jr t9
|
||||||
nop
|
nop
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue