Save sp
This commit is contained in:
+15
-2
@@ -1,9 +1,22 @@
|
||||
.globl fetch_argc, fetch_argv
|
||||
.data
|
||||
sp_start: .space 8
|
||||
|
||||
.section .text
|
||||
.globl save_sp, fetch_argc, fetch_argv
|
||||
|
||||
save_sp:
|
||||
sd sp, sp_start, t0 # save the stack pointer
|
||||
ret
|
||||
|
||||
# Fetch argument count
|
||||
# @param[in] a0: unused.
|
||||
# @param[out] a0: number of arguments.
|
||||
fetch_argc:
|
||||
ld a0, 0(sp)
|
||||
ld t0, sp_start # dereference the buffer
|
||||
ld a0, 0(t0) # dereference the address
|
||||
ret
|
||||
|
||||
# Fetch argument value
|
||||
# @param[in] a0: argv[a0].
|
||||
# @param[out] a0: address of arg.
|
||||
fetch_argv:
|
||||
|
||||
+4
-1
@@ -10,12 +10,15 @@ _start:
|
||||
la gp, __global_pointer$
|
||||
.option pop
|
||||
|
||||
|
||||
call save_sp
|
||||
call fetch_argc
|
||||
|
||||
li t0, 48
|
||||
add a0, a0, t0
|
||||
sd a0, argc, t0
|
||||
|
||||
# li a0, 1
|
||||
# call fetch_argv
|
||||
|
||||
li a0, 1
|
||||
la a1, argc
|
||||
|
||||
Reference in New Issue
Block a user