2025-02-09 05:09:53 +00:00
|
|
|
# RISC-V assembly program implementing a calculator.
|
|
|
|
|
|
|
|
.org 0
|
|
|
|
# Provide program starting address to linker
|
|
|
|
.global _start
|
|
|
|
|
2025-02-10 05:51:18 +00:00
|
|
|
.extern regdump
|
2025-02-11 12:08:32 +00:00
|
|
|
.extern add64
|
2025-02-10 04:00:44 +00:00
|
|
|
|
2025-02-09 05:09:53 +00:00
|
|
|
/* newlib system calls */
|
|
|
|
.set SYSEXIT, 93
|
|
|
|
.set SYSWRITE, 64
|
|
|
|
|
2025-02-10 05:51:18 +00:00
|
|
|
# .section .rodata
|
2025-02-09 05:09:53 +00:00
|
|
|
|
2025-02-10 05:51:18 +00:00
|
|
|
# .section .bss
|
2025-02-09 05:09:53 +00:00
|
|
|
|
|
|
|
.text
|
|
|
|
_start:
|
|
|
|
# do some adding
|
|
|
|
li a0, 0x80000000 # 0.5
|
|
|
|
li a1, 1 # 1
|
|
|
|
li a2, 0x80000000 # 0.5
|
|
|
|
li a3, 1 # 1
|
2025-02-10 05:51:18 +00:00
|
|
|
jal add64
|
2025-02-09 05:09:53 +00:00
|
|
|
#add t1, a0, 0 # copy a0 to t0 as end with overwrite it
|
|
|
|
jal regdump
|
|
|
|
|
|
|
|
li t0, SYSEXIT # "exit" syscall
|
|
|
|
add a0, x0, 0 # Use 0 return code
|
|
|
|
ecall # invoke syscall to terminate the program
|