added ADDI and ADDIU

master
bx 2021-08-31 21:37:31 +01:00
parent 481301023e
commit 1047cb9268
1 changed files with 36 additions and 9 deletions

View File

@ -23,6 +23,7 @@ end
# # # REGISTER NAMES # # #
def r0() 0 end # zero
def at() 1 end # assembler temporary
# subroutine return values, may be changed by subroutines
@ -120,6 +121,25 @@ def sw(src, offset, dest)
word op
end
# add immediate unsigned
def addiu(src, val, dest)
# oooooo sssss ddddd iiiiiiii iiiiiiii
op = 0b001001_00000_00000_00000000_00000000
op |= (src & 0b11111) << 21
op |= (val & 0xffff)
op |= (dest & 0b11111) << 16
word op
end
# add immediate
def addi(src, val, dest)
# oooooo sssss ddddd iiiiiiii iiiiiiii
op = 0b001000_00000_00000_00000000_00000000
op |= (src & 0b11111) << 21
op |= (val & 0xffff)
op |= (dest & 0b11111) << 16
word op
end
# # # PSEUDO-INSTRUCTIONS # # #
@ -208,17 +228,28 @@ def line(st, en)
sw t1, 0, t0
end
l_end_loop = label
# l_end_loop = label
line 0x0010_0010, 0x0030_0030
line 0x0030_0030, 0x0060_0000
line 0x0060_0000, 0x00f0_0060
line 0x0060_000a, 0x00f0_0060
nop ; nop ; nop ; nop
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
addi r0, -10, t4
#addi t4, 6, t4
addi t4, -10, t4
nop
nop
jmp l_end_loop
nop
@ -228,12 +259,8 @@ nop
string "this is a test lol"
puts "assembled 0x#{$bytes.length.to_s 16} (#{$bytes.length}) bytes"
raise "CODE IS GREATER THAN FILESIZE" if $bytes.length > $file_size
zero_fill $file_size - 1
f = File.new "LOADTHIS.EXE", "wb"