# Lab 6
Name: G Jaswanth
Roll No.: CS22B020
---
## Question 11
**Compiled Code**
```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 12
**Compiled Code**
```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
**Code**
* yes we can optimise it.
* we can use different optimisers like oO, o1, o2, o3, os, ofast and compile it.
---
## Question 14
**ELF File Code**
```
ELF header
==========
Name Offset NumValue Value
EI_MAG: 0x00000000 0x7F454C46 ELF
EI_CLASS 0x00000004 0x01 32 BIT
EI_DATA 0x00000005 0x01 DATA2LSB (Little-Endian)
EI_VERSION 0x00000006 0x01 EV_CURRENT
EI_OSABI 0x00000007 0x00 UNIX System V ABI
EI_OSABIVER 0x00000008 0x00
E_TYPE 0x00000010 0x0002 ET_EXEC (Executable file)
E_MACHINE 0x00000012 0x00F3 Unknown
E_VERSION 0x00000014 0x00000001 EV_CURRENT
E_ENTRY 0x00000018 0x000100D8
E_PHOFF 0x0000001C 0x00000034
E_SHOFF 0x00000020 0x00003ECC
E_FLAGS 0x00000024 0x00000000
E_EHSIZE 0x00000028 0x0034
E_PHENTSIZE 0x0000002A 0x0020
E_PHNUM 0x0000002C 0x0003
E_SHENTSIZE 0x0000002E 0x0028
E_SHNUM 0x00000030 0x000E
E_SHSTRNDX 0x00000032 0x000D
Program header tables
=====================
Type Offset VAddr PAddr FileSz MemSz Align Flags
Unknown 0x00002847 0x00000000 0x00000000 0x0000001C 0x00000000 0x00000001 Read
PT_LOAD 0x00000000 0x00010000 0x00010000 0x000022B8 0x000022B8 0x00001000 Execute|Read
PT_LOAD 0x000022B8 0x000132B8 0x000132B8 0x0000055C 0x000008A4 0x00001000 Write|Read
Section header tables
=====================
Nr Name Type Address Offset Size Link Info AddrAlign EntSize Flags
0 SHT_NULL 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
1 .text SHT_PROGBITS 0x00010094 0x00000094 0x00002224 0x00000000 0x00000000 0x00000004 0x00000000 Alloc|Exec
2 .eh_frame SHT_PROGBITS 0x000132B8 0x000022B8 0x00000004 0x00000000 0x00000000 0x00000004 0x00000000 Write|Alloc
3 .init_array SHT_INIT_ARRAY 0x000132BC 0x000022BC 0x00000008 0x00000000 0x00000000 0x00000004 0x00000004 Write|Alloc
4 .fini_array SHT_FINI_ARRAY 0x000132C4 0x000022C4 0x00000004 0x00000000 0x00000000 0x00000004 0x00000004 Write|Alloc
5 .data SHT_PROGBITS 0x000132C8 0x000022C8 0x00000538 0x00000000 0x00000000 0x00000008 0x00000000 Write|Alloc
6 .sdata SHT_PROGBITS 0x00013800 0x00002800 0x00000014 0x00000000 0x00000000 0x00000004 0x00000000 Write|Alloc
7 .sbss SHT_NOBITS 0x00013814 0x00002814 0x00000040 0x00000000 0x00000000 0x00000004 0x00000000 Write|Alloc
8 .bss SHT_NOBITS 0x00013854 0x00002814 0x00000308 0x00000000 0x00000000 0x00000004 0x00000000 Write|Alloc
9 .comment SHT_PROGBITS 0x00000000 0x00002814 0x00000033 0x00000000 0x00000000 0x00000001 0x00000001 Merge|Strings
10 .riscv.attributes Unknown 0x00000000 0x00002847 0x0000001C 0x00000000 0x00000000 0x00000001 0x00000000
11 .symtab SHT_SYMTAB 0x00000000 0x00002864 0x00000D60 0x0000000C 0x00000080 0x00000004 0x00000010
12 .strtab SHT_STRTAB 0x00000000 0x000035C4 0x0000088F 0x00000000 0x00000000 0x00000001 0x00000000
13 .shstrtab SHT_STRTAB 0x00000000 0x00003E53 0x00000076 0x00000000 0x00000000 0x00000001 0x00000000
Symbol tables
==============
Symbol table of section table .symtab (Index 11) with 214 entries
-----------------------
Nr Value Size Info (Binding|Type) Other Shndx Name
0 0x00000000 0x00000000 LOCAL | NOTYPE DEFAULT 0x0000
1 0x00010094 0x00000000 LOCAL | SECTION DEFAULT 0x0001
2 0x000132B8 0x00000000 LOCAL | SECTION DEFAULT 0x0002
3 0x000132BC 0x00000000 LOCAL | SECTION DEFAULT 0x0003
4 0x000132C4 0x00000000 LOCAL | SECTION DEFAULT 0x0004
5 0x000132C8 0x00000000 LOCAL | SECTION DEFAULT 0x0005
6 0x00013800 0x00000000 LOCAL | SECTION DEFAULT 0x0006
7 0x00013814 0x00000000 LOCAL | SECTION DEFAULT 0x0007
8 0x00013854 0x00000000 LOCAL | SECTION DEFAULT 0x0008
9 0x00000000 0x00000000 LOCAL | SECTION DEFAULT 0x0009
10 0x00000000 0x00000000 LOCAL | SECTION DEFAULT 0x000A
11 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-exit.o
12 0x00010094 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
13 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-__call_atexit.o
14 0x000100C0 0x00000018 LOCAL | FUNC DEFAULT 0x0001 register_fini
15 0x000100C0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
16 0x00010DC8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
17 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 crt0.o
18 0x000100D8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
19 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 crtbegin.o
20 0x000132B8 0x00000000 LOCAL | OBJECT DEFAULT 0x0002 _EH_FRAME_BEGIN_
21 0x00010118 0x00000000 LOCAL | FUNC DEFAULT 0x0001 __do_global_dtors_aux
22 0x00010118 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
23 0x00013814 0x00000000 LOCAL | OBJECT DEFAULT 0x0007 completed.1
24 0x000132C4 0x00000000 LOCAL | OBJECT DEFAULT 0x0004 __do_global_dtors_aux_fini_array_entry
25 0x00010160 0x00000000 LOCAL | FUNC DEFAULT 0x0001 frame_dummy
26 0x00010160 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
27 0x00013854 0x00000000 LOCAL | OBJECT DEFAULT 0x0008 object.0
28 0x000132C0 0x00000000 LOCAL | OBJECT DEFAULT 0x0003 __frame_dummy_init_array_entry
29 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 test.c
30 0x00010180 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
31 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-atexit.o
32 0x0001020C 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
33 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-findfp.o
34 0x00010220 0x0000001C LOCAL | FUNC DEFAULT 0x0001 stdio_exit_handler
35 0x00010220 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
36 0x0001023C 0x00000064 LOCAL | FUNC DEFAULT 0x0001 cleanup_stdio
37 0x0001023C 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
38 0x000102A0 0x00000040 LOCAL | FUNC DEFAULT 0x0001 __fp_lock
39 0x000102A0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
40 0x000102E0 0x00000040 LOCAL | FUNC DEFAULT 0x0001 __fp_unlock
41 0x000102E0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
42 0x00010320 0x00000168 LOCAL | FUNC DEFAULT 0x0001 global_stdio_init.part.0
43 0x00010320 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
44 0x00010488 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
45 0x000105D0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
46 0x00010630 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
47 0x00010638 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
48 0x00010640 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
49 0x00010670 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
50 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-fwalk.o
51 0x000106A0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
52 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-stdio.o
53 0x00010754 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
54 0x000107B0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
55 0x000107B8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
56 0x00010840 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
57 0x000108B8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
58 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-closer.o
59 0x000108C0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
60 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-reent.o
61 0x00010910 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
62 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-lseekr.o
63 0x000109D4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
64 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-readr.o
65 0x00010A30 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
66 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-writer.o
67 0x00010A8C 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
68 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-init.o
69 0x00010AE8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
70 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-fini.o
71 0x00010B7C 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
72 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-lock.o
73 0x00010BD8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
74 0x00010BDC 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
75 0x00010BE0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
76 0x00010BE4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
77 0x00010BE8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
78 0x00010BEC 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
79 0x00010BF0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
80 0x00010BF8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
81 0x00010C00 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
82 0x00010C04 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
83 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-memset.o
84 0x00010C08 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
85 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-__atexit.o
86 0x00010CE4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
87 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-freer.o
88 0x00010F18 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
89 0x00011050 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
90 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-mallocr.o
91 0x00011354 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
92 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-mlock.o
93 0x00011B1C 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
94 0x00011B24 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
95 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-fclose.o
96 0x00011B2C 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
97 0x00011C9C 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
98 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-fflush.o
99 0x00011CA8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
100 0x00011EF4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
101 0x00011FD4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
102 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-sbrkr.o
103 0x000120A4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
104 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 riscv_libgloss_a-sys_close.o
105 0x000120F4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
106 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 riscv_libgloss_a-sys_exit.o
107 0x00012138 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
108 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 riscv_libgloss_a-sys_lseek.o
109 0x00012168 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
110 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 riscv_libgloss_a-sys_read.o
111 0x000121AC 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
112 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 riscv_libgloss_a-sys_sbrk.o
113 0x000121F0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
114 0x00013850 0x00000004 LOCAL | OBJECT DEFAULT 0x0007 heap_end.0
115 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 riscv_libgloss_a-sys_write.o
116 0x0001226C 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
117 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 libc_a-errno.o
118 0x000122B0 0x00000000 LOCAL | NOTYPE DEFAULT 0x0001 $xrv32i2p1
119 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1 crtend.o
120 0x000132B8 0x00000000 LOCAL | OBJECT DEFAULT 0x0002 _FRAME_END_
121 0x00000000 0x00000000 LOCAL | FILE DEFAULT 0xFFF1
122 0x000132C8 0x00000000 LOCAL | NOTYPE DEFAULT 0x0004 __fini_array_end
123 0x000132C4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0004 __fini_array_start
124 0x000132C4 0x00000000 LOCAL | NOTYPE DEFAULT 0x0003 __init_array_end
125 0x000132BC 0x00000000 LOCAL | NOTYPE DEFAULT 0x0003 __preinit_array_end
126 0x000132BC 0x00000000 LOCAL | NOTYPE DEFAULT 0x0003 __init_array_start
127 0x000132BC 0x00000000 LOCAL | NOTYPE DEFAULT 0x0003 __preinit_array_start
128 0x000109D4 0x0000005C GLOBAL | FUNC DEFAULT 0x0001 _lseek_r
129 0x00013AC8 0x00000000 GLOBAL | NOTYPE DEFAULT 0xFFF1 __global_pointer$
130 0x00013838 0x00000001 GLOBAL | OBJECT DEFAULT 0x0007 _lock__atexit_recursive_mutex
131 0x00010840 0x00000078 GLOBAL | FUNC DEFAULT 0x0001 __sseek
132 0x000105D0 0x00000060 GLOBAL | FUNC DEFAULT 0x0001 __sinit
133 0x00011B24 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __malloc_unlock
134 0x00013820 0x00000001 GLOBAL | OBJECT DEFAULT 0x0007 _lock__arc4random_mutex
135 0x00013808 0x00000004 GLOBAL | OBJECT DEFAULT 0x0006 __atexit_recursive_mutex
136 0x000122B0 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __errno
137 0x00010BE0 0x00000004 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_close
138 0x00013818 0x00000004 GLOBAL | OBJECT DEFAULT 0x0007 __stdio_exit_handler
139 0x0001381C 0x00000004 GLOBAL | OBJECT DEFAULT 0x0007 errno
140 0x000107B0 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __seofread
141 0x00013800 0x00000000 GLOBAL | NOTYPE DEFAULT 0x0006 _SDATA_BEGIN_
142 0x0001384C 0x00000004 GLOBAL | OBJECT DEFAULT 0x0007 __malloc_top_pad
143 0x00013800 0x00000000 GLOBAL | OBJECT HIDDEN 0x0006 __dso_handle
144 0x000120A4 0x00000050 GLOBAL | FUNC DEFAULT 0x0001 _sbrk_r
145 0x00010A30 0x0000005C GLOBAL | FUNC DEFAULT 0x0001 _read_r
146 0x00011B2C 0x00000170 GLOBAL | FUNC DEFAULT 0x0001 _fclose_r
147 0x00011FD4 0x000000D0 GLOBAL | FUNC DEFAULT 0x0001 fflush
148 0x00013848 0x00000004 GLOBAL | OBJECT DEFAULT 0x0007 __malloc_max_sbrked_mem
149 0x0001382C 0x00000001 GLOBAL | OBJECT DEFAULT 0x0007 _lock__env_recursive_mutex
150 0x00010AE8 0x00000094 GLOBAL | FUNC DEFAULT 0x0001 __libc_init_array
151 0x000121F0 0x0000007C GLOBAL | FUNC DEFAULT 0x0001 _sbrk
152 0x00010640 0x00000030 GLOBAL | FUNC DEFAULT 0x0001 __fp_lock_all
153 0x00010B7C 0x0000005C GLOBAL | FUNC DEFAULT 0x0001 __libc_fini_array
154 0x00010910 0x000000C4 GLOBAL | FUNC DEFAULT 0x0001 _reclaim_reent
155 0x00013830 0x00000001 GLOBAL | OBJECT DEFAULT 0x0007 _lock__malloc_recursive_mutex
156 0x0001386C 0x00000138 GLOBAL | OBJECT DEFAULT 0x0008 __sf
157 0x00010C04 0x00000004 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_release_recursive
158 0x00010BF8 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_try_acquire_recursive
159 0x00010630 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __sfp_lock_acquire
160 0x00011050 0x00000304 GLOBAL | FUNC DEFAULT 0x0001 _free_r
161 0x00010DC8 0x00000150 GLOBAL | FUNC DEFAULT 0x0001 __call_exitprocs
162 0x000139A4 0x00000190 GLOBAL | OBJECT DEFAULT 0x0008 __atexit0
163 0x0001380C 0x00000004 GLOBAL | OBJECT DEFAULT 0x0006 __malloc_sbrk_base
164 0x000100D8 0x00000040 GLOBAL | FUNC DEFAULT 0x0001 _start
165 0x00010BF0 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_try_acquire
166 0x00012168 0x00000044 GLOBAL | FUNC DEFAULT 0x0001 _lseek
167 0x00010CE4 0x000000E4 GLOBAL | FUNC DEFAULT 0x0001 __register_exitproc
168 0x00013B34 0x00000028 GLOBAL | OBJECT DEFAULT 0x0008 __malloc_current_mallinfo
169 0x000108C0 0x00000050 GLOBAL | FUNC DEFAULT 0x0001 _close_r
170 0x00010BE4 0x00000004 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_close_recursive
171 0x00010488 0x00000148 GLOBAL | FUNC DEFAULT 0x0001 __sfp
172 0x00013B5C 0x00000000 GLOBAL | NOTYPE DEFAULT 0x0008 _BSS_END_
173 0x000133F8 0x00000408 GLOBAL | OBJECT DEFAULT 0x0005 _malloc_av
174 0x00013840 0x00000004 GLOBAL | OBJECT DEFAULT 0x0007 __atexit
175 0x00010754 0x0000005C GLOBAL | FUNC DEFAULT 0x0001 __sread
176 0x00011B1C 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __malloc_lock
177 0x00011EF4 0x000000E0 GLOBAL | FUNC DEFAULT 0x0001 _fflush_r
178 0x00010BEC 0x00000004 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_acquire_recursive
179 0x00013814 0x00000000 GLOBAL | NOTYPE DEFAULT 0x0007 __bss_start
180 0x00010C08 0x000000DC GLOBAL | FUNC DEFAULT 0x0001 memset
181 0x00010180 0x0000008C GLOBAL | FUNC DEFAULT 0x0001 main
182 0x00013844 0x00000004 GLOBAL | OBJECT DEFAULT 0x0007 __malloc_max_total_mem
183 0x00010BDC 0x00000004 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_init_recursive
184 0x000108B8 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __sclose
185 0x00011C9C 0x0000000C GLOBAL | FUNC DEFAULT 0x0001 fclose
186 0x00011354 0x000007C8 GLOBAL | FUNC DEFAULT 0x0001 _malloc_r
187 0x00010F18 0x00000138 GLOBAL | FUNC DEFAULT 0x0001 _malloc_trim_r
188 0x00010BD8 0x00000004 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_init
189 0x0001020C 0x00000014 GLOBAL | FUNC DEFAULT 0x0001 atexit
190 0x00010A8C 0x0000005C GLOBAL | FUNC DEFAULT 0x0001 _write_r
191 0x00013804 0x00000004 GLOBAL | OBJECT DEFAULT 0x0006 _impure_ptr
192 0x00011CA8 0x0000024C GLOBAL | FUNC DEFAULT 0x0001 __sflush_r
193 0x000106A0 0x000000B4 GLOBAL | FUNC DEFAULT 0x0001 _fwalk_sglue
194 0x00010670 0x00000030 GLOBAL | FUNC DEFAULT 0x0001 __fp_unlock_all
195 0x000132C8 0x00000000 GLOBAL | NOTYPE DEFAULT 0x0005 _DATA_BEGIN_
196 0x000132C8 0x0000000C GLOBAL | OBJECT DEFAULT 0x0005 __sglue
197 0x0001226C 0x00000044 GLOBAL | FUNC DEFAULT 0x0001 _write
198 0x00013814 0x00000000 GLOBAL | NOTYPE DEFAULT 0x0006 _edata
199 0x00013B5C 0x00000000 GLOBAL | NOTYPE DEFAULT 0x0008 _end
200 0x00013834 0x00000001 GLOBAL | OBJECT DEFAULT 0x0007 _lock__at_quick_exit_mutex
201 0x000107B8 0x00000088 GLOBAL | FUNC DEFAULT 0x0001 __swrite
202 0x00013810 0x00000004 GLOBAL | OBJECT DEFAULT 0x0006 __malloc_trim_threshold
203 0x00010094 0x0000002C GLOBAL | FUNC DEFAULT 0x0001 exit
204 0x000132D8 0x00000120 GLOBAL | OBJECT DEFAULT 0x0005 _impure_data
205 0x00010638 0x00000008 GLOBAL | FUNC DEFAULT 0x0001 __sfp_lock_release
206 0x000121AC 0x00000044 GLOBAL | FUNC DEFAULT 0x0001 _read
207 0x00010BE8 0x00000004 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_acquire
208 0x00010C00 0x00000004 GLOBAL | FUNC DEFAULT 0x0001 __retarget_lock_release
209 0x00012138 0x00000030 GLOBAL | FUNC DEFAULT 0x0001 _exit
210 0x00013824 0x00000001 GLOBAL | OBJECT DEFAULT 0x0007 _lock__dd_hash_mutex
211 0x00013828 0x00000001 GLOBAL | OBJECT DEFAULT 0x0007 _lock__tz_mutex
212 0x0001383C 0x00000001 GLOBAL | OBJECT DEFAULT 0x0007 _lock__sfp_recursive_mutex
213 0x000120F4 0x00000044 GLOBAL | FUNC DEFAULT 0x0001 _close
Note tables
==============
- Note table does not exist -
```
---
## Question 15
**Code**
(using: riscv-none-elf-gcc -march=rv32i -mabi=ilp32 -O0 -S test.c -o 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"
```
**code**
(using: risv-none-elf-gcc -march=rv32i -mabi=ilp32 -O1 -S test.c -o 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"
```
**code**
(using: risv-none-elf-gcc -march=rv32i -mabi=ilp32 -O2 -S test.c -o test_o2.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"
```
**code**
(using: risv-none-elf-gcc -march=rv32i -mabi=ilp32 -O3 -S test.c -o test_o3.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"
```
**code**
(using: riscv-none-elf-gcc -march=rv32i -mabi=ilp32 -Os -S test.c -o 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"
```
**code**
(using: riscv-none-elf-gcc -march=rv32i -mabi=ilp32 -Ofast -S test.c -o test_ofast.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"
```
