---
# System prepended metadata

title: LAB-4 CS22B014

---

**LAB4**
**Answer 1**
```assembly=
.data
array: .word 1,2,3,4,5,6,7,8,9,10,11
.text
addi x1,x0,3 # intialise s to 3
addi x2,x0,10 # initialise i to 10
la x3,array #loading address of x10 into x3
addi x3,x3,36
addi x4,x0,-1

loop:

    lw x5,0(x3)
    add x5,x5,x1
    sw x5,0(x3)
    addi x2,x2,-1
    addi x3,x3,-4
    bge x2,x4,loop
    
```
---
**Answer 2**
``` assembly=
.data
 array: .word 1,2,3,3,5,6,7,8,9,10,11
 .text
la x1,array
addi x2,x0,11
addi x3,x0,0
addi x7,x0,1
addi x8,x0,0
addi x9,x0,0
addi x10,x0,3

loop:
     lw x4,0(x1)
     andi x5,x4,1
     beq x5,x0,notodd
     addi x3,x3,1
     addi x9,x9,1
     addi x1,x1,4
     bge x3,x10,fi
     bgt x9,x2,exit
     ble x9,x2,loop
 notodd:
     add x3,x0,x0
     addi x9,x9,1
     addi x1,x1,4
     bgt x9,x2,exit
     j loop
 fi: 
     addi x8,x0,1
 exit:
     addi x11,x0,1
```
---
**Answer 3**
```assembly=
.data
a: .word 1,2,3,4,5,6
s1: .string "There is no pair such"
s2: .string "Exited"
.text
la x1 a
la x2 a
la x11 a
addi x3 x0 6
addi x4 x0 6
addi x14 x0 4
addi x5 x0 0
addi x6 x0 1
psum:
    lw x7 0(x1)
    lw x8 4(x2)
    add x10 x7 x8
     addi x2 x2 4
    addi x6 x6 1
    beq x10 x3 print
    beq x6 x4 sum

sum:
    addi x1 x1 4
    la x2 a
    addi x5 x5 1
    beq x5 x4 print2
    bne x5 x4 psum
    
print:    
        sub x13 x2 x11
        div x13 x13 x14
        add a0 x13 x0
        li a7 1
        ecall
        li a7 4
        ecall
        sub x13 x1 x11
        div x13 x13 x14
        add a0 x13 x0
        li a7 1
        ecall
        j exit
               
print2:
    la a0 s1
    li a7 4
    ecall    

exit:
    la a0 s2
    li a7 4
    ecall
```
---

    