# Lab 6 Name: SHIVADHARSHAN S Roll No.: CS22B057 --- ## Question 11 **Code:** ```shell= riscv-none-elf-gcc -march=rv32i -mabi=ilp32 -S test.c -o test.s ``` **Observation:** The compilation created a test.s file ___ ## Question 12 **Observation:** ```assembly= .file "test.c" .option nopic .attribute arch, "rv32i2p1" .attribute unaligned_access, 0 .attribute stack_align, 16 .text .align 2 .globl main .type main, @function main: addi sp,sp,-432 sw ra,428(sp) sw s0,424(sp) addi s0,sp,432 addi a5,s0,-424 li a4,400 mv a2,a4 li a1,0 mv a0,a5 call memset li a5,1 sw a5,-424(s0) sw zero,-20(s0) sw zero,-24(s0) j .L2 .L3: lw a5,-24(s0) slli a5,a5,2 addi a5,a5,-16 add a5,a5,s0 lw a5,-408(a5) lw a4,-20(s0) add a5,a4,a5 sw a5,-20(s0) lw a5,-24(s0) addi a5,a5,1 sw a5,-24(s0) .L2: lw a4,-24(s0) li a5,99 ble a4,a5,.L3 li a5,0 mv a0,a5 lw ra,428(sp) lw s0,424(sp) addi sp,sp,432 jr ra .size main, .-main .ident "GCC: (xPack GNU RISC-V Embedded GCC x86_64) 13.2.0" ``` ___ ## Question 13 Yes the code can be optimized, the fact that we need to notice is that although the code is computing the sum, the sum is never being used. So taking away the whole loop still has the same behaviour. **Code:** ```assembly= .file "test.c" .option nopic .attribute arch, "rv32i2p1" .attribute unaligned_access, 0 .attribute stack_align, 16 .text .section .text.startup,"ax",@progbits .align 2 .globl main .type main, @function main: li a0,0 ret .size main, .-main .ident "GCC: (xPack GNU RISC-V Embedded GCC x86_64) 13.2.0" ``` ___ ## Question 14 **Code:** ```= riscv-none-elf-gcc -march=rv32i -mabi=ilp32 -o test.elf test.s ``` **Output:** ![Screenshot from 2024-03-22 17-46-06](https://hackmd.io/_uploads/HJv58eoCa.png) Using elf reader to read the elf file. ``` ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: RISC-V Version: 0x1 Entry point address: 0x100d8 Start of program headers: 52 (bytes into file) Start of section headers: 16076 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 3 Size of section headers: 40 (bytes) Number of section headers: 14 Section header string table index: 13 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00010094 000094 002224 00 AX 0 0 4 [ 2] .eh_frame PROGBITS 000132b8 0022b8 000004 00 WA 0 0 4 [ 3] .init_array INIT_ARRAY 000132bc 0022bc 000008 04 WA 0 0 4 [ 4] .fini_array FINI_ARRAY 000132c4 0022c4 000004 04 WA 0 0 4 [ 5] .data PROGBITS 000132c8 0022c8 000538 00 WA 0 0 8 [ 6] .sdata PROGBITS 00013800 002800 000014 00 WA 0 0 4 [ 7] .sbss NOBITS 00013814 002814 000040 00 WA 0 0 4 [ 8] .bss NOBITS 00013854 002814 000308 00 WA 0 0 4 [ 9] .comment PROGBITS 00000000 002814 000033 01 MS 0 0 1 [10] .riscv.attributes RISCV_ATTRIBUTE 00000000 002847 00001c 00 0 0 1 [11] .symtab SYMTAB 00000000 002864 000d60 10 12 128 4 [12] .strtab STRTAB 00000000 0035c4 00088f 00 0 0 1 [13] .shstrtab STRTAB 00000000 003e53 000076 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), D (mbind), p (processor specific) There are no section groups in this file. Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align RISCV_ATTRIBUT 0x002847 0x00000000 0x00000000 0x0001c 0x00000 R 0x1 LOAD 0x000000 0x00010000 0x00010000 0x022b8 0x022b8 R E 0x1000 LOAD 0x0022b8 0x000132b8 0x000132b8 0x0055c 0x008a4 RW 0x1000 Section to Segment mapping: Segment Sections... 00 .riscv.attributes 01 .text 02 .eh_frame .init_array .fini_array .data .sdata .sbss .bss There is no dynamic section in this file. There are no relocations in this file. The decoding of unwind sections for machine type RISC-V is not currently supported. Symbol table '.symtab' contains 214 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00010094 0 SECTION LOCAL DEFAULT 1 .text 2: 000132b8 0 SECTION LOCAL DEFAULT 2 .eh_frame 3: 000132bc 0 SECTION LOCAL DEFAULT 3 .init_array 4: 000132c4 0 SECTION LOCAL DEFAULT 4 .fini_array 5: 000132c8 0 SECTION LOCAL DEFAULT 5 .data 6: 00013800 0 SECTION LOCAL DEFAULT 6 .sdata 7: 00013814 0 SECTION LOCAL DEFAULT 7 .sbss 8: 00013854 0 SECTION LOCAL DEFAULT 8 .bss 9: 00000000 0 SECTION LOCAL DEFAULT 9 .comment 10: 00000000 0 SECTION LOCAL DEFAULT 10 .riscv.attributes 11: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-exit.o 12: 00010094 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 13: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-__call_at[...] 14: 000100c0 24 FUNC LOCAL DEFAULT 1 register_fini 15: 000100c0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 16: 00010dc8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 17: 00000000 0 FILE LOCAL DEFAULT ABS crt0.o 18: 000100d8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 19: 00000000 0 FILE LOCAL DEFAULT ABS crtbegin.o 20: 000132b8 0 OBJECT LOCAL DEFAULT 2 __EH_FRAME_BEGIN__ 21: 00010118 0 FUNC LOCAL DEFAULT 1 __do_global_dtors_aux 22: 00010118 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 23: 00013814 0 OBJECT LOCAL DEFAULT 7 completed.1 24: 000132c4 0 OBJECT LOCAL DEFAULT 4 __do_global_dtor[...] 25: 00010160 0 FUNC LOCAL DEFAULT 1 frame_dummy 26: 00010160 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 27: 00013854 0 OBJECT LOCAL DEFAULT 8 object.0 28: 000132c0 0 OBJECT LOCAL DEFAULT 3 __frame_dummy_in[...] 29: 00000000 0 FILE LOCAL DEFAULT ABS test.c 30: 00010180 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 31: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-atexit.o 32: 0001020c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 33: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-findfp.o 34: 00010220 28 FUNC LOCAL DEFAULT 1 stdio_exit_handler 35: 00010220 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 36: 0001023c 100 FUNC LOCAL DEFAULT 1 cleanup_stdio 37: 0001023c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 38: 000102a0 64 FUNC LOCAL DEFAULT 1 __fp_lock 39: 000102a0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 40: 000102e0 64 FUNC LOCAL DEFAULT 1 __fp_unlock 41: 000102e0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 42: 00010320 360 FUNC LOCAL DEFAULT 1 global_stdio_ini[...] 43: 00010320 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 44: 00010488 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 45: 000105d0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 46: 00010630 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 47: 00010638 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 48: 00010640 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 49: 00010670 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 50: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-fwalk.o 51: 000106a0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 52: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-stdio.o 53: 00010754 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 54: 000107b0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 55: 000107b8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 56: 00010840 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 57: 000108b8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 58: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-closer.o 59: 000108c0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 60: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-reent.o 61: 00010910 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 62: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-lseekr.o 63: 000109d4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 64: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-readr.o 65: 00010a30 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 66: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-writer.o 67: 00010a8c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 68: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-init.o 69: 00010ae8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 70: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-fini.o 71: 00010b7c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 72: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-lock.o 73: 00010bd8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 74: 00010bdc 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 75: 00010be0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 76: 00010be4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 77: 00010be8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 78: 00010bec 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 79: 00010bf0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 80: 00010bf8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 81: 00010c00 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 82: 00010c04 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 83: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-memset.o 84: 00010c08 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 85: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-__atexit.o 86: 00010ce4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 87: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-freer.o 88: 00010f18 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 89: 00011050 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 90: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-mallocr.o 91: 00011354 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 92: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-mlock.o 93: 00011b1c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 94: 00011b24 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 95: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-fclose.o 96: 00011b2c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 97: 00011c9c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 98: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-fflush.o 99: 00011ca8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 100: 00011ef4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 101: 00011fd4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 102: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-sbrkr.o 103: 000120a4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 104: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...] 105: 000120f4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 106: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...] 107: 00012138 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 108: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...] 109: 00012168 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 110: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...] 111: 000121ac 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 112: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...] 113: 000121f0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 114: 00013850 4 OBJECT LOCAL DEFAULT 7 heap_end.0 115: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...] 116: 0001226c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 117: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-errno.o 118: 000122b0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1 119: 00000000 0 FILE LOCAL DEFAULT ABS crtend.o 120: 000132b8 0 OBJECT LOCAL DEFAULT 2 __FRAME_END__ 121: 00000000 0 FILE LOCAL DEFAULT ABS 122: 000132c8 0 NOTYPE LOCAL DEFAULT 4 __fini_array_end 123: 000132c4 0 NOTYPE LOCAL DEFAULT 4 __fini_array_start 124: 000132c4 0 NOTYPE LOCAL DEFAULT 3 __init_array_end 125: 000132bc 0 NOTYPE LOCAL DEFAULT 3 __preinit_array_end 126: 000132bc 0 NOTYPE LOCAL DEFAULT 3 __init_array_start 127: 000132bc 0 NOTYPE LOCAL DEFAULT 3 __preinit_array_start 128: 000109d4 92 FUNC GLOBAL DEFAULT 1 _lseek_r 129: 00013ac8 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$ 130: 00013838 1 OBJECT GLOBAL DEFAULT 7 __lock___atexit_[...] 131: 00010840 120 FUNC GLOBAL DEFAULT 1 __sseek 132: 000105d0 96 FUNC GLOBAL DEFAULT 1 __sinit 133: 00011b24 8 FUNC GLOBAL DEFAULT 1 __malloc_unlock 134: 00013820 1 OBJECT GLOBAL DEFAULT 7 __lock___arc4ran[...] 135: 00013808 4 OBJECT GLOBAL DEFAULT 6 __atexit_recursi[...] 136: 000122b0 8 FUNC GLOBAL DEFAULT 1 __errno 137: 00010be0 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_close 138: 00013818 4 OBJECT GLOBAL DEFAULT 7 __stdio_exit_handler 139: 0001381c 4 OBJECT GLOBAL DEFAULT 7 errno 140: 000107b0 8 FUNC GLOBAL DEFAULT 1 __seofread 141: 00013800 0 NOTYPE GLOBAL DEFAULT 6 __SDATA_BEGIN__ 142: 0001384c 4 OBJECT GLOBAL DEFAULT 7 __malloc_top_pad 143: 00013800 0 OBJECT GLOBAL HIDDEN 6 __dso_handle 144: 000120a4 80 FUNC GLOBAL DEFAULT 1 _sbrk_r 145: 00010a30 92 FUNC GLOBAL DEFAULT 1 _read_r 146: 00011b2c 368 FUNC GLOBAL DEFAULT 1 _fclose_r 147: 00011fd4 208 FUNC GLOBAL DEFAULT 1 fflush 148: 00013848 4 OBJECT GLOBAL DEFAULT 7 __malloc_max_sbr[...] 149: 0001382c 1 OBJECT GLOBAL DEFAULT 7 __lock___env_rec[...] 150: 00010ae8 148 FUNC GLOBAL DEFAULT 1 __libc_init_array 151: 000121f0 124 FUNC GLOBAL DEFAULT 1 _sbrk 152: 00010640 48 FUNC GLOBAL DEFAULT 1 __fp_lock_all 153: 00010b7c 92 FUNC GLOBAL DEFAULT 1 __libc_fini_array 154: 00010910 196 FUNC GLOBAL DEFAULT 1 _reclaim_reent 155: 00013830 1 OBJECT GLOBAL DEFAULT 7 __lock___malloc_[...] 156: 0001386c 312 OBJECT GLOBAL DEFAULT 8 __sf 157: 00010c04 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...] 158: 00010bf8 8 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...] 159: 00010630 8 FUNC GLOBAL DEFAULT 1 __sfp_lock_acquire 160: 00011050 772 FUNC GLOBAL DEFAULT 1 _free_r 161: 00010dc8 336 FUNC GLOBAL DEFAULT 1 __call_exitprocs 162: 000139a4 400 OBJECT GLOBAL DEFAULT 8 __atexit0 163: 0001380c 4 OBJECT GLOBAL DEFAULT 6 __malloc_sbrk_base 164: 000100d8 64 FUNC GLOBAL DEFAULT 1 _start 165: 00010bf0 8 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...] 166: 00012168 68 FUNC GLOBAL DEFAULT 1 _lseek 167: 00010ce4 228 FUNC GLOBAL DEFAULT 1 __register_exitproc 168: 00013b34 40 OBJECT GLOBAL DEFAULT 8 __malloc_current[...] 169: 000108c0 80 FUNC GLOBAL DEFAULT 1 _close_r 170: 00010be4 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...] 171: 00010488 328 FUNC GLOBAL DEFAULT 1 __sfp 172: 00013b5c 0 NOTYPE GLOBAL DEFAULT 8 __BSS_END__ 173: 000133f8 1032 OBJECT GLOBAL DEFAULT 5 __malloc_av_ 174: 00013840 4 OBJECT GLOBAL DEFAULT 7 __atexit 175: 00010754 92 FUNC GLOBAL DEFAULT 1 __sread 176: 00011b1c 8 FUNC GLOBAL DEFAULT 1 __malloc_lock 177: 00011ef4 224 FUNC GLOBAL DEFAULT 1 _fflush_r 178: 00010bec 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...] 179: 00013814 0 NOTYPE GLOBAL DEFAULT 7 __bss_start 180: 00010c08 220 FUNC GLOBAL DEFAULT 1 memset 181: 00010180 140 FUNC GLOBAL DEFAULT 1 main 182: 00013844 4 OBJECT GLOBAL DEFAULT 7 __malloc_max_tot[...] 183: 00010bdc 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...] 184: 000108b8 8 FUNC GLOBAL DEFAULT 1 __sclose 185: 00011c9c 12 FUNC GLOBAL DEFAULT 1 fclose 186: 00011354 1992 FUNC GLOBAL DEFAULT 1 _malloc_r 187: 00010f18 312 FUNC GLOBAL DEFAULT 1 _malloc_trim_r 188: 00010bd8 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_init 189: 0001020c 20 FUNC GLOBAL DEFAULT 1 atexit 190: 00010a8c 92 FUNC GLOBAL DEFAULT 1 _write_r 191: 00013804 4 OBJECT GLOBAL DEFAULT 6 _impure_ptr 192: 00011ca8 588 FUNC GLOBAL DEFAULT 1 __sflush_r 193: 000106a0 180 FUNC GLOBAL DEFAULT 1 _fwalk_sglue 194: 00010670 48 FUNC GLOBAL DEFAULT 1 __fp_unlock_all 195: 000132c8 0 NOTYPE GLOBAL DEFAULT 5 __DATA_BEGIN__ 196: 000132c8 12 OBJECT GLOBAL DEFAULT 5 __sglue 197: 0001226c 68 FUNC GLOBAL DEFAULT 1 _write 198: 00013814 0 NOTYPE GLOBAL DEFAULT 6 _edata 199: 00013b5c 0 NOTYPE GLOBAL DEFAULT 8 _end 200: 00013834 1 OBJECT GLOBAL DEFAULT 7 __lock___at_quic[...] 201: 000107b8 136 FUNC GLOBAL DEFAULT 1 __swrite 202: 00013810 4 OBJECT GLOBAL DEFAULT 6 __malloc_trim_th[...] 203: 00010094 44 FUNC GLOBAL DEFAULT 1 exit 204: 000132d8 288 OBJECT GLOBAL DEFAULT 5 _impure_data 205: 00010638 8 FUNC GLOBAL DEFAULT 1 __sfp_lock_release 206: 000121ac 68 FUNC GLOBAL DEFAULT 1 _read 207: 00010be8 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...] 208: 00010c00 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...] 209: 00012138 48 FUNC GLOBAL DEFAULT 1 _exit 210: 00013824 1 OBJECT GLOBAL DEFAULT 7 __lock___dd_hash[...] 211: 00013828 1 OBJECT GLOBAL DEFAULT 7 __lock___tz_mutex 212: 0001383c 1 OBJECT GLOBAL DEFAULT 7 __lock___sfp_rec[...] 213: 000120f4 68 FUNC GLOBAL DEFAULT 1 _close No version information found in this file. Attribute Section: riscv File Attributes Tag_RISCV_stack_align: 16-bytes Tag_RISCV_arch: "rv32i2p1" ``` ___ ## Question 15 **Observation** File Size: (Bytes) ![Screenshot from 2024-03-22 17-53-40](https://hackmd.io/_uploads/ryEDOgjAT.png) Running all files just returns as there is nothing to be printed only csr count is available **Content:** test_o0.s ```assembly= .file "test.c" .option nopic .attribute arch, "rv32i2p1" .attribute unaligned_access, 0 .attribute stack_align, 16 .text .align 2 .globl main .type main, @function main: addi sp,sp,-432 sw ra,428(sp) sw s0,424(sp) addi s0,sp,432 addi a5,s0,-424 li a4,400 mv a2,a4 li a1,0 mv a0,a5 call memset li a5,1 sw a5,-424(s0) sw zero,-20(s0) sw zero,-24(s0) j .L2 .L3: lw a5,-24(s0) slli a5,a5,2 addi a5,a5,-16 add a5,a5,s0 lw a5,-408(a5) lw a4,-20(s0) add a5,a4,a5 sw a5,-20(s0) lw a5,-24(s0) addi a5,a5,1 sw a5,-24(s0) .L2: lw a4,-24(s0) li a5,99 ble a4,a5,.L3 li a5,0 mv a0,a5 lw ra,428(sp) lw s0,424(sp) addi sp,sp,432 jr ra .size main, .-main .ident "GCC: (xPack GNU RISC-V Embedded GCC x86_64) 13.2.0" ``` test_o1.s ```assembly= .file "test.c" .option nopic .attribute arch, "rv32i2p1" .attribute unaligned_access, 0 .attribute stack_align, 16 .text .align 2 .globl main .type main, @function main: li a5,100 .L2: addi a5,a5,-1 bne a5,zero,.L2 li a0,0 ret .size main, .-main .ident "GCC: (xPack GNU RISC-V Embedded GCC x86_64) 13.2.0" ``` test_o2.s, test_o3.s, test_ofast.s, test_os.s ```assembly= .file "test.c" .option nopic .attribute arch, "rv32i2p1" .attribute unaligned_access, 0 .attribute stack_align, 16 .text .section .text.startup,"ax",@progbits .align 2 .globl main .type main, @function main: li a0,0 ret .size main, .-main .ident "GCC: (xPack GNU RISC-V Embedded GCC x86_64) 13.2.0" ``` **Time:** | Optimization | time | | -------- | -------- | | O0 | .000003 sec| | O1 | .000002 sec| | O2 | .000002 sec| | O3 | .000002 sec| | Os | .000002 sec| | Ofast | .000002 sec| **Output:** O0 ![Screenshot from 2024-04-07 21-02-48](https://hackmd.io/_uploads/r10a24eg0.png) O1 ![Screenshot from 2024-04-07 21-02-40](https://hackmd.io/_uploads/SJI0h4ggC.png) O2,O3,Os,Ofast ![Screenshot from 2024-04-07 21-02-31](https://hackmd.io/_uploads/BJ8ya4ee0.png) ___