aboutsummaryrefslogtreecommitdiffstats
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rwxr-xr-xtest.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/test.py b/test.py
index ba6ffd6..987535f 100755
--- a/test.py
+++ b/test.py
@@ -1,7 +1,13 @@
#!/usr/bin/env python3
-from riscv import format_u, format_i, format_s
+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
@@ -19,3 +25,5 @@ if __name__ == "__main__":
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"))
+