.globl _start .option rvc # enable compressed instructions .section .rodata newline: .ascii "\n" # TODO: sort env, buffer output .text _start: # arguments are passed on the stack: # --bottom of stack-- # dd argc # dd argv[0] # dd ... # dd 0 # dd envp[0] # dd ... # dd 0 ld s0, 0(sp) # get argc addi s1, sp, 16 # add 8 for argc, 8 for the NULL at the end of argv # compute start of envp # we could use a sh3add instruction # but the tools i'm using don't support the bitmanip extension #sh3add s1, sp, s0 sll t0, s0, 3 # argc*8 add s1, s1, t0 loop: # check for null pointer, which signals the end of envp ld a1, 0(s1) beqz a1, end # compute length of string mv t1, a1 strlen: lbu t0, 0(t1) addi t1, t1, 1 bnez t0, strlen sub a2, t1, a1 # print string li a7, 64 li a0, 1 # a1 already set to start of string # a2 already set to string length ecall # print newline li a7, 64 li a0, 1 la a1, newline li a2, 1 ecall # increment envp and loop addi s1, s1, 8 j loop end: li a7, 93 # exit li a0, 0 ecall write_error: li a7, 93 # exit li a0, 1 ecall