hi guys:
I just need help in how the srl instruction works in my program. I would like to know the interpretation. Like if I input de decimal number 8, which is 1000 in binary. I would like to know how it works.
this is the code, it converts decimal to hexadecimal numbers:
main:

la $a0, en # query user to enter a decimal number

li $v0, 4

syscall

li $v0, 5 # read in integer

syscall

add $v1, $v0, $zero

addi $s1, $zero, 28

Compute: add $t0, $zero, $v1 # move the decimal to a temp register


srl $s2, $t0, $s1

andi $s2, $s2, 15

addi $s1, $s1, -4

slti $t3, $s2, 10

bne $t3, $zero, L1 # $t3<10, branch to L1

addi $a0, $s2, 55 # add 55 to gain ascii value of the letter

PRINT: la $v0, 11 #print the ascii value

syscall

#We need to loop through the rest of the bits until we have read through entire number

slt $t4, $s1, $zero

beq $t4, $zero, Compute

j EXIT

L1: addi $a0, $s2, 48

j PRINT

EXIT: li $v0, 10

syscall # end the program

SRL (Shift Right Logical). This instruction shifts all the bits to the right from a given number of positions. For example, if I do SRL on 0011100 with 3 positions, the result will be 0000011.

You should see the documentation of the processor you use to know if the shifted bits are returned or other details like that.

This article has been dead for over six months. Start a new discussion instead.