Print register names
This commit is contained in:
parent
4c4d7bdbf7
commit
32b37bb374
1 changed files with 29 additions and 8 deletions
37
calc.s
37
calc.s
|
@ -11,9 +11,12 @@
|
|||
.section .rodata
|
||||
str: .ascii "Hello World!\n"
|
||||
.set str_size, .-str
|
||||
|
||||
str2: .ascii "regdump\n"
|
||||
.set str2_size, .-str2
|
||||
|
||||
regnames:
|
||||
.ascii "x0", "ra", "sp", "gp", "tp", "t0", "t1", "t2", "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5"
|
||||
|
||||
.section .bss
|
||||
buf: .skip 20 # room for 20 byte string
|
||||
|
@ -92,19 +95,37 @@ regdump:
|
|||
li a2, str2_size # length of other string
|
||||
ecall # invoke syscall to print the string
|
||||
|
||||
# as a test load something into buf and print it
|
||||
la a1, buf # load address of buf into a1
|
||||
li a0, 'h
|
||||
sb a0, 0(a1)
|
||||
li a0, '\n
|
||||
sb a0, 1(a1)
|
||||
li a2, 2 # length of buf
|
||||
li t1, 0
|
||||
li t2, 16
|
||||
|
||||
regdump_loop:
|
||||
beq t1, t2, regdump_done
|
||||
# a1 = regnames + (2 * t1)
|
||||
# a1 = t1 << 1 + regnames
|
||||
la a1, regnames # load address of regnames
|
||||
slli a2, t1, 1
|
||||
add a1, a1, a2
|
||||
|
||||
# print the register name
|
||||
li t0, SYSWRITE # "write" syscall
|
||||
li a0, 1 # 1 = standard output (stdout)
|
||||
# li a2, buflen # length of hello string
|
||||
# a1 is the address of the string, calculated above
|
||||
li a2, 2 # length of register name string
|
||||
ecall # invoke syscall to print the string
|
||||
|
||||
# add newline
|
||||
la a1, buf # load address of buf into a1
|
||||
li a0, '\n
|
||||
sb a0, 0(a1)
|
||||
li a2, 1 # length of buf
|
||||
li t0, SYSWRITE # "write" syscall
|
||||
li a0, 1 # 1 = standard output (stdout)
|
||||
ecall # invoke syscall to print the string
|
||||
|
||||
addi t1, t1, 1
|
||||
j regdump_loop
|
||||
|
||||
regdump_done:
|
||||
addi sp, sp, 16 # deallocate stack space
|
||||
ret
|
||||
|
||||
|
|
Loading…
Reference in a new issue