---
# System prepended metadata

title: Lab 6

---

# Lab 6
Name:Dhanush M
Roll No.:CS22B053

---
## Points 11 to 15

```assembly=
int main(){
        int a[100];
        int s = 0;
        for(int i = 0;i<100;i++){
                s=s+a[i]*i;
        }
}

```
O0 optimisation -
Size - 734 bytes
```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"

```

O1 optimisation -
Size - 326 bytes
```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"

```

O2 optimisation -
Size - 313 bytes

```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"

```
O3 optimisation -
Size - 313 bytes

```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"
```


Os optimisation -
Size - 313 bytes

```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"

```

Ofast optimisation -
Size - 313 bytes.

```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"

```

---
