# Lab 6
Name: SUDDULA VINEETH RAGHAVENDRA
Roll No.: CS22B045
---
## Question 11
**Command:**
``` riscv-none-elf-gcc -march=rv32i -mabi=ilp32 -S test.c -o test.s```
By using this command we will be getting the assembly code for the following c program.
---
## Question 12
By using the command cat test.s we will be getting the assembly code for the following c program.
**Observation :**
Assembly code:
```
.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 s0,428(sp)
addi s0,sp,432
sw zero,-20(s0)
j .L2
.L3:
lw a5,-20(s0)
slli a5,a5,2
addi a5,a5,-16
add a5,a5,s0
lw a4,-20(s0)
sw a4,-412(a5)
lw a5,-20(s0)
addi a5,a5,1
sw a5,-20(s0)
.L2:
lw a4,-20(s0)
li a5,99
ble a4,a5,.L3
sw zero,-24(s0)
sw zero,-28(s0)
j .L4
.L5:
lw a5,-28(s0)
slli a5,a5,2
addi a5,a5,-16
add a5,a5,s0
lw a5,-412(a5)
lw a4,-24(s0)
add a5,a4,a5
sw a5,-24(s0)
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L4:
lw a4,-28(s0)
li a5,99
ble a4,a5,.L5
li a5,0
mv a0,a5
lw s0,428(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, we can do optimization. which is done in Question 15.
---
## Question 14
By using this command we will get the ELF file from the assembly file.
***command***
```riscv-none-elf-gcc -march=rv32i -mabi=ilp32 -o test.elf test.s```
But the problem is we cant able to read that ELF file.So if we want to read the file use the command
```riscv-none-elf-readelf -a test.elf```
By using this command we will get the following observation.
**Observation:**
```
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: 16092 (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 002234 00 AX 0 0 4
[ 2] .eh_frame PROGBITS 000132c8 0022c8 000004 00 WA 0 0 4
[ 3] .init_array INIT_ARRAY 000132cc 0022cc 000008 04 WA 0 0 4
[ 4] .fini_array FINI_ARRAY 000132d4 0022d4 000004 04 WA 0 0 4
[ 5] .data PROGBITS 000132d8 0022d8 000538 00 WA 0 0 8
[ 6] .sdata PROGBITS 00013810 002810 000014 00 WA 0 0 4
[ 7] .sbss NOBITS 00013824 002824 000040 00 WA 0 0 4
[ 8] .bss NOBITS 00013864 002824 000308 00 WA 0 0 4
[ 9] .comment PROGBITS 00000000 002824 000033 01 MS 0 0 1
[10] .riscv.attributes RISCV_ATTRIBUTE 00000000 002857 00001c 00 0 0 1
[11] .symtab SYMTAB 00000000 002874 000d60 10 12 128 4
[12] .strtab STRTAB 00000000 0035d4 00088f 00 0 0 1
[13] .shstrtab STRTAB 00000000 003e63 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 0x002857 0x00000000 0x00000000 0x0001c 0x00000 R 0x1
LOAD 0x000000 0x00010000 0x00010000 0x022c8 0x022c8 R E 0x1000
LOAD 0x0022c8 0x000132c8 0x000132c8 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: 000132c8 0 SECTION LOCAL DEFAULT 2 .eh_frame
3: 000132cc 0 SECTION LOCAL DEFAULT 3 .init_array
4: 000132d4 0 SECTION LOCAL DEFAULT 4 .fini_array
5: 000132d8 0 SECTION LOCAL DEFAULT 5 .data
6: 00013810 0 SECTION LOCAL DEFAULT 6 .sdata
7: 00013824 0 SECTION LOCAL DEFAULT 7 .sbss
8: 00013864 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: 00010dd8 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: 000132c8 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: 00013824 0 OBJECT LOCAL DEFAULT 7 completed.1
24: 000132d4 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: 00013864 0 OBJECT LOCAL DEFAULT 8 object.0
28: 000132d0 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: 0001021c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
33: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-findfp.o
34: 00010230 28 FUNC LOCAL DEFAULT 1 stdio_exit_handler
35: 00010230 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
36: 0001024c 100 FUNC LOCAL DEFAULT 1 cleanup_stdio
37: 0001024c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
38: 000102b0 64 FUNC LOCAL DEFAULT 1 __fp_lock
39: 000102b0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
40: 000102f0 64 FUNC LOCAL DEFAULT 1 __fp_unlock
41: 000102f0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
42: 00010330 360 FUNC LOCAL DEFAULT 1 global_stdio_ini[...]
43: 00010330 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
44: 00010498 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
45: 000105e0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
46: 00010640 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
47: 00010648 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
48: 00010650 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
49: 00010680 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
50: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-fwalk.o
51: 000106b0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
52: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-stdio.o
53: 00010764 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
54: 000107c0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
55: 000107c8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
56: 00010850 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
57: 000108c8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
58: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-closer.o
59: 000108d0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
60: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-reent.o
61: 00010920 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
62: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-lseekr.o
63: 000109e4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
64: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-readr.o
65: 00010a40 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
66: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-writer.o
67: 00010a9c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
68: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-init.o
69: 00010af8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
70: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-fini.o
71: 00010b8c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
72: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-lock.o
73: 00010be8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
74: 00010bec 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
75: 00010bf0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
76: 00010bf4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
77: 00010bf8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
78: 00010bfc 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
79: 00010c00 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
80: 00010c08 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
81: 00010c10 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
82: 00010c14 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
83: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-memset.o
84: 00010c18 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
85: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-__atexit.o
86: 00010cf4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
87: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-freer.o
88: 00010f28 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
89: 00011060 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
90: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-mallocr.o
91: 00011364 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
92: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-mlock.o
93: 00011b2c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
94: 00011b34 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
95: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-fclose.o
96: 00011b3c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
97: 00011cac 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
98: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-fflush.o
99: 00011cb8 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
100: 00011f04 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
101: 00011fe4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
102: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-sbrkr.o
103: 000120b4 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
104: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...]
105: 00012104 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
106: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...]
107: 00012148 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
108: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...]
109: 00012178 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
110: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...]
111: 000121bc 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
112: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...]
113: 00012200 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
114: 00013860 4 OBJECT LOCAL DEFAULT 7 heap_end.0
115: 00000000 0 FILE LOCAL DEFAULT ABS riscv_libgloss_a[...]
116: 0001227c 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
117: 00000000 0 FILE LOCAL DEFAULT ABS libc_a-errno.o
118: 000122c0 0 NOTYPE LOCAL DEFAULT 1 $xrv32i2p1
119: 00000000 0 FILE LOCAL DEFAULT ABS crtend.o
120: 000132c8 0 OBJECT LOCAL DEFAULT 2 __FRAME_END__
121: 00000000 0 FILE LOCAL DEFAULT ABS
122: 000132d8 0 NOTYPE LOCAL DEFAULT 4 __fini_array_end
123: 000132d4 0 NOTYPE LOCAL DEFAULT 4 __fini_array_start
124: 000132d4 0 NOTYPE LOCAL DEFAULT 3 __init_array_end
125: 000132cc 0 NOTYPE LOCAL DEFAULT 3 __preinit_array_end
126: 000132cc 0 NOTYPE LOCAL DEFAULT 3 __init_array_start
127: 000132cc 0 NOTYPE LOCAL DEFAULT 3 __preinit_array_start
128: 000109e4 92 FUNC GLOBAL DEFAULT 1 _lseek_r
129: 00013ad8 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$
130: 00013848 1 OBJECT GLOBAL DEFAULT 7 __lock___atexit_[...]
131: 00010850 120 FUNC GLOBAL DEFAULT 1 __sseek
132: 000105e0 96 FUNC GLOBAL DEFAULT 1 __sinit
133: 00011b34 8 FUNC GLOBAL DEFAULT 1 __malloc_unlock
134: 00013830 1 OBJECT GLOBAL DEFAULT 7 __lock___arc4ran[...]
135: 00013818 4 OBJECT GLOBAL DEFAULT 6 __atexit_recursi[...]
136: 000122c0 8 FUNC GLOBAL DEFAULT 1 __errno
137: 00010bf0 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_close
138: 00013828 4 OBJECT GLOBAL DEFAULT 7 __stdio_exit_handler
139: 0001382c 4 OBJECT GLOBAL DEFAULT 7 errno
140: 000107c0 8 FUNC GLOBAL DEFAULT 1 __seofread
141: 00013810 0 NOTYPE GLOBAL DEFAULT 6 __SDATA_BEGIN__
142: 0001385c 4 OBJECT GLOBAL DEFAULT 7 __malloc_top_pad
143: 00013810 0 OBJECT GLOBAL HIDDEN 6 __dso_handle
144: 000120b4 80 FUNC GLOBAL DEFAULT 1 _sbrk_r
145: 00010a40 92 FUNC GLOBAL DEFAULT 1 _read_r
146: 00011b3c 368 FUNC GLOBAL DEFAULT 1 _fclose_r
147: 00011fe4 208 FUNC GLOBAL DEFAULT 1 fflush
148: 00013858 4 OBJECT GLOBAL DEFAULT 7 __malloc_max_sbr[...]
149: 0001383c 1 OBJECT GLOBAL DEFAULT 7 __lock___env_rec[...]
150: 00010af8 148 FUNC GLOBAL DEFAULT 1 __libc_init_array
151: 00012200 124 FUNC GLOBAL DEFAULT 1 _sbrk
152: 00010650 48 FUNC GLOBAL DEFAULT 1 __fp_lock_all
153: 00010b8c 92 FUNC GLOBAL DEFAULT 1 __libc_fini_array
154: 00010920 196 FUNC GLOBAL DEFAULT 1 _reclaim_reent
155: 00013840 1 OBJECT GLOBAL DEFAULT 7 __lock___malloc_[...]
156: 0001387c 312 OBJECT GLOBAL DEFAULT 8 __sf
157: 00010c14 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...]
158: 00010c08 8 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...]
159: 00010640 8 FUNC GLOBAL DEFAULT 1 __sfp_lock_acquire
160: 00011060 772 FUNC GLOBAL DEFAULT 1 _free_r
161: 00010dd8 336 FUNC GLOBAL DEFAULT 1 __call_exitprocs
162: 000139b4 400 OBJECT GLOBAL DEFAULT 8 __atexit0
163: 0001381c 4 OBJECT GLOBAL DEFAULT 6 __malloc_sbrk_base
164: 000100d8 64 FUNC GLOBAL DEFAULT 1 _start
165: 00010c00 8 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...]
166: 00012178 68 FUNC GLOBAL DEFAULT 1 _lseek
167: 00010cf4 228 FUNC GLOBAL DEFAULT 1 __register_exitproc
168: 00013b44 40 OBJECT GLOBAL DEFAULT 8 __malloc_current[...]
169: 000108d0 80 FUNC GLOBAL DEFAULT 1 _close_r
170: 00010bf4 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...]
171: 00010498 328 FUNC GLOBAL DEFAULT 1 __sfp
172: 00013b6c 0 NOTYPE GLOBAL DEFAULT 8 __BSS_END__
173: 00013408 1032 OBJECT GLOBAL DEFAULT 5 __malloc_av_
174: 00013850 4 OBJECT GLOBAL DEFAULT 7 __atexit
175: 00010764 92 FUNC GLOBAL DEFAULT 1 __sread
176: 00011b2c 8 FUNC GLOBAL DEFAULT 1 __malloc_lock
177: 00011f04 224 FUNC GLOBAL DEFAULT 1 _fflush_r
178: 00010bfc 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...]
179: 00013824 0 NOTYPE GLOBAL DEFAULT 7 __bss_start
180: 00010c18 220 FUNC GLOBAL DEFAULT 1 memset
181: 00010180 156 FUNC GLOBAL DEFAULT 1 main
182: 00013854 4 OBJECT GLOBAL DEFAULT 7 __malloc_max_tot[...]
183: 00010bec 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...]
184: 000108c8 8 FUNC GLOBAL DEFAULT 1 __sclose
185: 00011cac 12 FUNC GLOBAL DEFAULT 1 fclose
186: 00011364 1992 FUNC GLOBAL DEFAULT 1 _malloc_r
187: 00010f28 312 FUNC GLOBAL DEFAULT 1 _malloc_trim_r
188: 00010be8 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_init
189: 0001021c 20 FUNC GLOBAL DEFAULT 1 atexit
190: 00010a9c 92 FUNC GLOBAL DEFAULT 1 _write_r
191: 00013814 4 OBJECT GLOBAL DEFAULT 6 _impure_ptr
192: 00011cb8 588 FUNC GLOBAL DEFAULT 1 __sflush_r
193: 000106b0 180 FUNC GLOBAL DEFAULT 1 _fwalk_sglue
194: 00010680 48 FUNC GLOBAL DEFAULT 1 __fp_unlock_all
195: 000132d8 0 NOTYPE GLOBAL DEFAULT 5 __DATA_BEGIN__
196: 000132d8 12 OBJECT GLOBAL DEFAULT 5 __sglue
197: 0001227c 68 FUNC GLOBAL DEFAULT 1 _write
198: 00013824 0 NOTYPE GLOBAL DEFAULT 6 _edata
199: 00013b6c 0 NOTYPE GLOBAL DEFAULT 8 _end
200: 00013844 1 OBJECT GLOBAL DEFAULT 7 __lock___at_quic[...]
201: 000107c8 136 FUNC GLOBAL DEFAULT 1 __swrite
202: 00013820 4 OBJECT GLOBAL DEFAULT 6 __malloc_trim_th[...]
203: 00010094 44 FUNC GLOBAL DEFAULT 1 exit
204: 000132e8 288 OBJECT GLOBAL DEFAULT 5 _impure_data
205: 00010648 8 FUNC GLOBAL DEFAULT 1 __sfp_lock_release
206: 000121bc 68 FUNC GLOBAL DEFAULT 1 _read
207: 00010bf8 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...]
208: 00010c10 4 FUNC GLOBAL DEFAULT 1 __retarget_lock_[...]
209: 00012148 48 FUNC GLOBAL DEFAULT 1 _exit
210: 00013834 1 OBJECT GLOBAL DEFAULT 7 __lock___dd_hash[...]
211: 00013838 1 OBJECT GLOBAL DEFAULT 7 __lock___tz_mutex
212: 0001384c 1 OBJECT GLOBAL DEFAULT 7 __lock___sfp_rec[...]
213: 00012104 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 5
**File Sizes**
| File name | Size of the file |
| -------- | -------- |
test.s | 827
test_o0.s | 827
test_o1.s | 370
test_o2.s | 313
test_o3.s | 313
test_ofast.s | 313
test_os.s | 313
**Contents**
**test_o0.s , test.s**
```
.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 s0,428(sp)
addi s0,sp,432
sw zero,-20(s0)
j .L2
.L3:
lw a5,-20(s0)
slli a5,a5,2
addi a5,a5,-16
add a5,a5,s0
lw a4,-20(s0)
sw a4,-412(a5)
lw a5,-20(s0)
addi a5,a5,1
sw a5,-20(s0)
.L2:
lw a4,-20(s0)
li a5,99
ble a4,a5,.L3
sw zero,-24(s0)
sw zero,-28(s0)
j .L4
.L5:
lw a5,-28(s0)
slli a5,a5,2
addi a5,a5,-16
add a5,a5,s0
lw a5,-412(a5)
lw a4,-24(s0)
add a5,a4,a5
sw a5,-24(s0)
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L4:
lw a4,-28(s0)
li a5,99
ble a4,a5,.L5
li a5,0
mv a0,a5
lw s0,428(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**
```
.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 a5,100
.L3:
addi a5,a5,-1
bne a5,zero,.L3
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**
```
.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"
```
---