fixed bug in ori encoding

master
bx 2021-08-31 10:37:09 +01:00
parent 5221fe45d9
commit b666aa05e9
1 changed files with 27 additions and 2 deletions

View File

@ -25,6 +25,10 @@ end
# # # INSTRUCTIONS # # # # # # INSTRUCTIONS # # #
# ops should always be in format of
# [src] [args] -> [dest]
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
@ -45,7 +49,7 @@ end
# load upper immediate # load upper immediate
# NOTE: val will be shifted left by 16 # NOTE: val will be shifted left by 16
def lui(val, dest) def lui(val, dest)
# oooooo ----- ttttt iiiiiiiiiiiiiiii # oooooo ----- ddddd iiiiiiiiiiiiiiii
op = 0b001111_00000_00000_0000000000000000 op = 0b001111_00000_00000_0000000000000000
op |= 0xffff & val op |= 0xffff & val
op |= (0b11111 & dest) << 16 op |= (0b11111 & dest) << 16
@ -68,10 +72,19 @@ def ori(src, bits, dest)
op = 0b001101_00000_00000_00000000_00000000 op = 0b001101_00000_00000_00000000_00000000
op |= (src & 0b11111) << 21 op |= (src & 0b11111) << 21
op |= (bits & 0xffff) op |= (bits & 0xffff)
op |= (dest & 0x11111) << 16 op |= (dest & 0b11111) << 16
word op word op
end end
# store word
def sw(src, offset, dest)
# oooooo ddddd sssss iiiiiiii iiiiiiii
op = 0b101011_00000_00000_00000000_00000000
op |= (src & 0b11111) << 16
op |= (offset & 0xffff)
op |= (dest & 0b11111) << 21
word op
end
@ -127,6 +140,18 @@ nop ; jmp $base_addr + 16 ; nop ; word 0xdeadbeef
lui $gp0 >> 16, 1 lui $gp0 >> 16, 1
ori 1, $gp0, 1 ori 1, $gp0, 1
nop
#lui 0, 3
#ori 3, 0xffff, 3
#sw 1, 0, 2
32.times do |i|
ori i, 0xf00d, i
end
nop ; nop ; nop ; nop nop ; nop ; nop ; nop
nop ; nop ; nop ; nop nop ; nop ; nop ; nop
nop ; nop ; nop ; nop nop ; nop ; nop ; nop