Blob
1 .section .rodata2 fmt: .asciz "Hello World\n"3 ifmt: .asciz "%d\n"5 .section .data6 arr: .dword 1, 2, 3, 4, 58 .section .text9 .global main10 main:11 addi sp, sp, -1612 sd s0, 8(sp)13 sd ra, 0(sp)15 jal hello17 jal printarr18 jal nl20 la a0, arr21 li a1, 122 jal swap24 jal printarr26 jal nl28 la a0, arr29 li a1, 030 jal avg31 mv s0, a032 jal print34 mv a0, s035 jal even36 jal print38 mv a0, zero39 ld ra, 0(sp)40 ld s0, 8(sp)41 addi sp, sp, 1642 ret44 // void hello (void);45 hello:46 la a0, fmt47 j printf49 // void nl (void);50 nl:51 li a0, 1052 j putchar54 // void print (int);55 print:56 addi sp, sp, -857 sd ra, 0(sp)59 mv a1, a060 la a0, ifmt61 jal printf63 ld ra, 0(sp)64 addi sp, sp, 865 ret67 // void printarr (void);68 printarr:69 addi sp, sp, -3270 sd ra, 16(sp)71 sd s0, 8(sp)72 sd s1, 0(sp)74 la s0, arr75 mv s1, zero77 ploop:78 add a0, s0, s179 ld a0, 0(a0)80 jal print82 addi s1, s1, 883 li t0, (5 * 8)84 bne s1, t0, ploop87 ld s1, 0(sp)88 ld s0, 8(sp)89 ld ra, 16(sp)90 addi sp, sp, 3291 ret93 // void swap (long *v, size_t n);94 swap:95 slli a1, a1, 396 add t0, a0, a197 ld t1, 0(t0)98 ld t2, 8(t0)99 sd t2, 0(t0)100 sd t1, 8(t0)101 ret103 // long avg(long *v, size_t n);104 avg:105 slli a1, a1, 3106 add a0, a0, a1107 ld t0, 0(a0)108 ld t1, 8(a0)109 add a0, t0, t1110 srli a0, a0, 1111 ret113 // bool even(long);114 even:115 andi a0, a0, 1116 xor a0, a0, 1117 ret