---
# System prepended metadata

title: Lab 7

---

# Lab 7
Name: Anuj Sharma
Roll No.: CS22B007

---
## QUESTION 1
$(0.1)_{10}$ to binary

0.1 * 2 = 0.2
0.2 * 2 = 0.4
0.4 * 2 = 0.8
0.8 * 2 = 1 + 0.6
0.6 * 2 = 1 + 0.2
0.2 * 2 = 0.4
0.4 * 2 = 0.8
0.8 * 2 = 1 + 0.6
0.6 * 2 = 1 + 0.2

0.110's binary representation is 0.0001100110011001011

## QUESTION 2
$(0.1)_{10}$ to IEEE 754

$(0.0\overline0\overline0\overline1\overline1) _{2}$ = $(0.00011\overline0\overline0\overline1\overline1) _{2}$
$(0.00011\overline0\overline0\overline1\overline1) _{2}$ =$(1.1\overline0\overline0\overline1\overline1 * 2^{-4}) _{2}$

Exponent is :
- 127 - 4 = 123

In IEEE 754 format :
- 0 01111011 10011001100110011001100

## QUESTION 3
$(0.2)_{10}$ to binary

0.2 * 2 = 0 + 0.4
0.4 * 2 = 0 + 0.8
0.8 * 2 = 1 + 0.6
0.6 * 2 = 1 + 0.2
0.2 * 2 = 0 + 0.4


$(0.2)_{10}$ = $(0.\overline0\overline0\overline1\overline1) _{2}$
$(0.\overline0\overline0\overline1\overline1) _{2}$ = $(0.0011\overline0\overline0\overline1\overline1) _{2}$
$(0.0011\overline0\overline0\overline1\overline1) _{2}$ = $(1.1\overline0\overline0\overline1\overline1 * 2^{-3}) _{2}$

In IEEE 754 format :

- 0 01111100 10011001100110011001100

## QUESTION 4

**Representation**
- Here  one decimal is stored in two registers one register stores the part before decimal point and other after it. If the decimal past in second register after addition is greater then or equal to 1000000000 we substract 1000000000 from second register and add carry one to first register, thus this representation can store smallest upto 10^-9^ accuracy.

- First bit of first register represent sign.

```assembly=
.data
.word 5, 391000000, 3, 012000000
base: .word 0x10000000
wrd: .word 1000000000
dot: .string "."

.text
lw x2 base
lw x31 wrd

lw x4 0(x2)   # first number
lw x5 4(x2)   

lw x6 8(x2)   # second number
lw x7 12(x2)

add x14 x4 x6 # addition
add x15 x5 x7

bge x31 x15 nocarry 
sub x15 x15 x31  # if there is carry
addi x14 x14 1

nocarry:

# Printing

li a7 1
addi a0 x14 0
ecall

li a7 4
la a0 dot
ecall

li a7 1
addi a0 x15 0
ecall
```

## QUESTION 5


``` assembly=
.data
.word 0b00111111100111010111000010100100 0b01000000000111010111000010100100
.word 0x80000000
base: .word 0x10000000
#x3=sign1 x13=sign2
#x4=exp1 x5=mant1 x14=exp2 x15=mant2
.text
lw x6 base
lw x12 4(x6)
lw x2 0(x6)
lw x8 8(x6)

addi x10 x0 1
sll x4 x2 x10
sll x14 x12 x10

bge x4 x14 NoSwap
#swapping
addi x30 x2 0
addi x2 x12 0
addi x12 x30 0

NoSwap:



addi x10 x0 31
srl x13 x12 x10
srl x3 x2 x10


addi x10 x0 9
sll x5 x2 x10
sll x15 x12 x10

addi x10 x0 1
srl x5 x5 x10
srl x15 x15 x10
or x5 x8 x5
or x15 x8 x15

addi x10 x0 9
srl x5 x5 x10
srl x15 x15 x10



addi x10 x0 24
srl x4 x4 x10
srl x14 x14 x10

sub x9 x14 x4
addi x19 x9 0
#blt x10 x9 end
sll x15 x15 x9

addi x10 x0 -1
beq x3 x0 skp1
mul x5 x5 x10
skp1:
beq x3 x0 skp2
mul x15 x15 x10
skp2:

add x5 x5 x15
addi x2 x0 0
blt x0 x5 skp
addi x2 x0 1
skp:
addi x10 x0 31
sll x2 x2 x10
addi x10 x0 7
sll x5 x5 x10
and x28 x8 x5
beq x28 x0 skp3
addi x10 x0 1
srl x5 x5 x10
addi x14 x14 1
skp3:
addi x10 x0 1
srl x8 x8 x10
loop1:
    bge x5 x8 end
    bge x0 x14 end
    sll x5 x5 x10
    add x14 x14 x10
    j loop1


end:
    xor x5 x5 x8
    addi x10 x0 23
    sll x14 x14 x10
    addi x10 x0 1
    #sll x5 x5 x10
    addi x10 x0 7
    srl x5 x5 x10
    or x12 x5 x14
    or x12 x2 x12
    sw x12 12(x6) #answer

```