---
# System prepended metadata

title: Lab 6_CS22B036

---

# Lab 6
Name: M V Sonith
Roll No.: CS22B036

---
# Codes #
**C - Code**
```c=
#include<stdio.h>

int main(){
	int t[100]= {1};
	int sum=0;
	for (int i=0;i<100;++i){
		sum+=t[i];
	}
return 0;
}
```
**No Optimization 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"
```

**O0 Optimization 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"
```
    
    
**O1 Optimization 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:
	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 Optimization Code**
```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 Optimization Code**
```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 Optimization Code**
```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 Optimization Code**
```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"
```

|Files | Sizes|Runtimes|
|-----|-------|--------|
|test.s|744 bytes| 0.000003 sec|
|test_O0.s|744 bytes|0.000003 sec|
|test_O1.s|322 bytes|0.000002 sec|
|test_O2.s|313 bytes|0.000002 sec|
|test_O3.s|313 bytes|0.000002 sec|
|test_Os.s|313 bytes|0.000002 sec|
|test_Ofast.s|313 bytes|0.000002 sec|

**Link to Files**

[Link to files](https://drive.google.com/drive/folders/1Sz8jWz9_9IP0J4v-k7O3BxSnR3dS_hOb?usp=sharing)

---
