---
# System prepended metadata

title: Lab 6

---

# Lab 6
Name : Bilwani k
Roll No : CS22B013

---
This is the c program 
```
int main() {
    int arr[100];
    int sum = 0;
    int i;
   
    for (i = 0; i < 100; i++) {
        arr[i] = i + 1; 
    }

    for (i = 0; i < 100; i++) {
        sum += arr[i];
    }

    return sum;
}
```
Point 12
---
cat test.s

it will access contents from the file test.s

it is a short form for concatinate it is also used to combine more than two files together but in this 

Point 13
---
yes you can optimise the main code

files are attached later

Point 15
---

133   test1.c
877   test1.s
877   test1_o0.s
545   test1_o1.s
529   test1_o2.s
529   test1_o3.s
529   test1_os.s
529   test1_ofast.s
So, in this code we did not gave anything to print, so optimization performs only for certain level than after some level 
when it has nothing to optimize it does not optimize anything.
This is what we got at different optimization levels 

```
.file "q11.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
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
nop
nop
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"
normal
```

```
.file "q11.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
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
nop
nop
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"
O0
```

```
.file "q11.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
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
nop
nop
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"
O2
```

```
.file "q11.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
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
nop
nop
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"
O3
```

```
.file "q11.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
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
nop
nop
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"O4
```
```
.file "q11.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
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
nop
nop
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"O5
```