Professional Documents
Culture Documents
22sp-031-cs Lab3 CO&AL
22sp-031-cs Lab3 CO&AL
SOURCE CODE:
li x1,1
li x2,2
li x3,3
li x4,2
beq x1,x2,label
sub x5,x3,x4
beq x0,x0,else
label:
add x5,x3,x4
else:nop
if(k==0)
f=i+j;
else if(k>=1)
f=g+h;
else if(k>=2)
f=g–h;
else if(k==3)
f=i–j;
else
f=0
SOURCE CODE:
li s0,4
li x1,1
li x2,2
li x3,3
li s1,9
li s2,2
li a1,4
li a2,8
beq s0,x1,true2
beq s0,x2,true3
beq s0,x3,true4
li sp,0
beq x0,x0,else
true1:
add t1,s1,s2
beq x0,x0,else
true2:
add t1,a1,a2
beq x0,x0,else
true3:
sub t1,a1,a2
beq x0,x0,else
true4:
sub t1,s1,s2
else:nop
4. Create loop with branch instructions of RISC V.
5. Write an assembly language program to shift value by 5 logically to left hand side.
SOURCE CODE:
li x1,4
slli x1,x1,5
6. Write an assembly language program to shift value in x4 arithmetically to right hand side.
Also discuss the concept of Shifting arithmetically and what benefit it give. Support your
answer with example
SOURCE CODE:
li x4,4
srai x4,x4,1