aboutsummaryrefslogtreecommitdiffstats
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rwxr-xr-xtest.py41
1 files changed, 17 insertions, 24 deletions
diff --git a/test.py b/test.py
index 987535f..9934f7a 100755
--- a/test.py
+++ b/test.py
@@ -2,28 +2,21 @@
from riscv import format_u, format_i, format_s, format_j
from subx import format_instr
-def neg(val, bits):
- """compute the 2's complement of int value val"""
- # if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
- val = val - (1 << bits) # compute negative value
- return -val
-
if __name__ == "__main__":
- t0 = 0x5
- t1 = 0x6
- print("== code 0x80000000")
- print(format_instr(format_u(0x37, t0, 0x10010), "lui t0, 0x10010"))
- print(format_instr(format_i(0x13, t1, 0, 72, 0x0), "addi t1, x0, 72"))
- print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
- print(format_instr(format_i(0x13, t1, 0, 101, 0x0), "addi t1, x0, 101"))
- print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
- print(format_instr(format_i(0x13, t1, 0, 108, 0x0), "addi t1, x0, 108"))
- print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
- print(format_instr(format_i(0x13, t1, 0, 108, 0x0), "addi t1, x0, 108"))
- print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
- print(format_instr(format_i(0x13, t1, 0, 111, 0x0), "addi t1, x0, 111"))
- print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
- print(format_instr(format_i(0x13, t1, 0, 10, 0x0), "addi t1, x0, 10"))
- print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
- print(format_instr(format_j(0x6f, 0, neg(26, 20)), "jal x0, -26"))
-
+ t0 = 0x5
+ t1 = 0x6
+ print("== code 0x80000000")
+ print(format_instr(format_u(0x37, t0, 0x10010), "lui t0, 0x10010"))
+ print(format_instr(format_i(0x13, t1, 0, 72, 0x0), "addi t1, x0, 72"))
+ print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
+ print(format_instr(format_i(0x13, t1, 0, 101, 0x0), "addi t1, x0, 101"))
+ print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
+ print(format_instr(format_i(0x13, t1, 0, 108, 0x0), "addi t1, x0, 108"))
+ print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
+ print(format_instr(format_i(0x13, t1, 0, 108, 0x0), "addi t1, x0, 108"))
+ print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
+ print(format_instr(format_i(0x13, t1, 0, 111, 0x0), "addi t1, x0, 111"))
+ print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
+ print(format_instr(format_i(0x13, t1, 0, 10, 0x0), "addi t1, x0, 10"))
+ print(format_instr(format_s(0x23, t0, t1, 0, 0x2), "sw t1, 0(t0)"))
+ print(format_instr(format_j(0x6f, 0, -26), "jal x0, -26"))