From 8d39d79032ad3ddfc81bb21b48325fa25995aba7 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sun, 18 Apr 2021 00:43:39 +0200 Subject: [PATCH] made module runnable --- fibs.asm | 22 ++++++++++++++++++++++ riscemu/{main.py => __main__.py} | 21 ++++++++++++--------- 2 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 fibs.asm rename riscemu/{main.py => __main__.py} (62%) diff --git a/fibs.asm b/fibs.asm new file mode 100644 index 0000000..4080a40 --- /dev/null +++ b/fibs.asm @@ -0,0 +1,22 @@ + .data 0x200 + +fibs: .space 56 + + .text +main: + addi s1, zero, 0 # storage index + addi s2, zero, 56 # last storage index + addi t0, zero, 1 # t0 = F_{i} + addi t1, zero, 1 # t1 = F_{i+1} +loop: + sw t0, fibs(s1) # save + add t2, t1, t0 # t2 = F_{i+2} + addi t0, t1, 0 # t0 = t1 + addi t1, t2, 0 # t1 = t2 + addi s1, s1, 4 # increment storage pointer + blt s1, s2, loop # loop as long as we did not reach array length + # exit gracefully + addi a0, zero, 0 + addi a7, zero, 93 + ebreak # launch debugger + scall # exit with code 0 \ No newline at end of file diff --git a/riscemu/main.py b/riscemu/__main__.py similarity index 62% rename from riscemu/main.py rename to riscemu/__main__.py index f3c53f1..808b0ad 100644 --- a/riscemu/main.py +++ b/riscemu/__main__.py @@ -3,24 +3,27 @@ if __name__ == '__main__': from .helpers import * import argparse - parser = argparse.ArgumentParser(description='RISC-V Userspace parser and emulator') + parser = argparse.ArgumentParser(description='RISC-V Userspace parser and emulator', prog='riscemu') parser.add_argument('file', metavar='file.asm', type=str, help='The assembly file to interpret and run') # RunConfig parameters - parser.add_argument('color', type=bool, help='Colored output', default=True) - parser.add_argument('default_stack_size', type=int, help='Default stack size of loaded programs', default=None, - metavar='default-stack-size') - parser.add_argument('debug_instruction', type=bool, default=True, metavar='debug-instruction', + parser.add_argument('--no-color', type=bool, help='no colored output', default=False, + nargs='?') + parser.add_argument('--default_stack_size', type=int, help='Default stack size of loaded programs', default=None, + metavar='default-stack-size', nargs='?') + parser.add_argument('--debug_instruction', type=bool, default=True, metavar='debug-instruction', help='Switches to an interactive python interpreter when ebreak/sbreak instruction ' - 'is encountered. Otherwise these instructions are treated as nop.') + 'is encountered. Otherwise these instructions are treated as nop.', nargs='?') - parser.add_argument('print_tokens', metavar='print-tokens', type=bool, help='Print tokens after tokenization', - default=False) + parser.add_argument('--print_tokens', metavar='print-tokens', type=bool, help='Print tokens after tokenization', + default=False, nargs='?') args = parser.parse_args() + print(args) + cfg = RunConfig( - color=args.color, + color=not args.no_color, preffered_stack_size=args.default_stack_size, debug_instruction=args.debug_instruction )