added or immediate (ori) instruction
parent
53c69e77a9
commit
5221fe45d9
66
assembler.rb
66
assembler.rb
|
@ -21,6 +21,10 @@ def string(s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# # # INSTRUCTIONS # # #
|
||||||
def jmp(addr)
|
def jmp(addr)
|
||||||
# TODO: this probs wont show up since we have < 3mb of ram but
|
# TODO: this probs wont show up since we have < 3mb of ram but
|
||||||
# we can't jump to an address with a different 4 most significant bits
|
# we can't jump to an address with a different 4 most significant bits
|
||||||
|
@ -38,16 +42,13 @@ def jal(addr)
|
||||||
word op
|
word op
|
||||||
end
|
end
|
||||||
|
|
||||||
def nop
|
|
||||||
word 0x00000000
|
|
||||||
end
|
|
||||||
|
|
||||||
# load upper immediate
|
# load upper immediate
|
||||||
def lui(reg, val)
|
# NOTE: val will be shifted left by 16
|
||||||
|
def lui(val, dest)
|
||||||
# oooooo ----- ttttt iiiiiiiiiiiiiiii
|
# oooooo ----- ttttt iiiiiiiiiiiiiiii
|
||||||
op = 0b001111_00000_00000_0000000000000000
|
op = 0b001111_00000_00000_0000000000000000
|
||||||
op |= (0b11111 & reg) << 16
|
|
||||||
op |= 0xffff & val
|
op |= 0xffff & val
|
||||||
|
op |= (0b11111 & dest) << 16
|
||||||
word op
|
word op
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -61,6 +62,26 @@ def srl(src, amt, dest)
|
||||||
word op
|
word op
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# or immediate
|
||||||
|
def ori(src, bits, dest)
|
||||||
|
# oooooo sssss ddddd iiiiiiii iiiiiiii
|
||||||
|
op = 0b001101_00000_00000_00000000_00000000
|
||||||
|
op |= (src & 0b11111) << 21
|
||||||
|
op |= (bits & 0xffff)
|
||||||
|
op |= (dest & 0x11111) << 16
|
||||||
|
word op
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# # # PSEUDO-INSTRUCTIONS # # #
|
||||||
|
def nop
|
||||||
|
word 0x00000000
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# this is a terrible idea and im doing it
|
# this is a terrible idea and im doing it
|
||||||
#$labels = {}
|
#$labels = {}
|
||||||
|
@ -70,11 +91,10 @@ end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# # # CONSTANTS # # #
|
# # # CONSTANTS # # #
|
||||||
$base_addr = 0x80010000 # 0x10000 # 0x80010000
|
$base_addr = 0x80010000 # 0x10000 # 0x80010000
|
||||||
$file_size = 0x800
|
$file_size = 0x800
|
||||||
|
$gp0 = 0x1F801810
|
||||||
|
|
||||||
# # # EXE HEADER # # #
|
# # # EXE HEADER # # #
|
||||||
string "PS-X EXE"
|
string "PS-X EXE"
|
||||||
|
@ -99,22 +119,19 @@ $bytes = []
|
||||||
|
|
||||||
|
|
||||||
# # # PROGRAM CODE # # #
|
# # # PROGRAM CODE # # #
|
||||||
nop
|
nop ; jmp $base_addr + 16 ; nop ; word 0xdeadbeef
|
||||||
nop
|
|
||||||
|
|
||||||
lui 2, 0
|
# ops should always be in format of
|
||||||
lui 3, 0
|
# src [args] -> dest
|
||||||
|
|
||||||
|
lui $gp0 >> 16, 1
|
||||||
|
ori 1, $gp0, 1
|
||||||
|
|
||||||
lui 2, 1
|
nop ; nop ; nop ; nop
|
||||||
nop
|
nop ; nop ; nop ; nop
|
||||||
|
nop ; nop ; nop ; nop
|
||||||
|
nop ; nop ; nop ; nop
|
||||||
|
|
||||||
srl 2, 14, 3
|
|
||||||
srl 2, 1, 6
|
|
||||||
nop
|
|
||||||
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
jmp $base_addr
|
jmp $base_addr
|
||||||
nop
|
nop
|
||||||
|
|
||||||
|
@ -125,15 +142,6 @@ nop
|
||||||
|
|
||||||
|
|
||||||
string "this is a test lol"
|
string "this is a test lol"
|
||||||
word 0xFFAAFFAA
|
|
||||||
word 0b001001_11101_11101_11111111_11111111
|
|
||||||
word 0b001000_11101_11101_11111111_11111111
|
|
||||||
|
|
||||||
word 0xAAFFAAFF
|
|
||||||
word 0b001001_00101_00101_11111111_11111111
|
|
||||||
word 0b001000_00101_00101_11111111_11111111
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue