---
# System prepended metadata

title: Lab x

---

# Lab 6
Name: Lavkush Kumar
Roll No.: CS22B034
---
## Question 1

**C Code** 

```c=
#include <stdio.h>
int main(){
        int sum=0;
        int arr[100];
        for(int i=0;i<100;i++)
        {
                arr[i]=i;
                sum+=arr[i];
        }
        return 0;
}
```
 **O0 optimization-**
```assembly=
.file "test.c"
.option nopic
.attribute arch, "rv32i2p1"
.attribute unaligned_access, 0
.attribute stack_align, 16
.text
.globl __mulsi3
.align 2
.globl main
.type main, @function
main:
    addi sp,sp,-432
    sw ra,428(sp)
    sw s0,424(sp)
    addi s0,sp,432
    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 a1,-24(s0)
    mv a0,a5
    call __mulsi3
    mv a5,a0
    mv a4,a5
    lw a5,-20(s0)
    add a5,a5,a4
    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"

```

**Observation:** 
* Execution time : 2625002 nanosecond
* size : 709 bytes


---

**O1 optimization-** 
```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:
     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"

```
**Observation:** 
* Execution time : 2467858 nanosecond
* size: 322 bytes


---
**O2 optimization-**
```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"

```
**Observation:** 
* Execution time : 2443121 nanosecond
* size: 313 bytes


**O3 optimization-**
```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"
```
**Observation:** 

* Execution time : 1962059 nanosecond
* size: 313 bytes


**Os optimization-**
```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"
```
**Observation:** 

* Execution time : 2344797 nanosecond
* size: 313 bytes


**Ofast optimization-**
```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"
```
**Observation:** 

* Execution time : 2956164 nanosecond
* size: 313 bytes

