# Divide by 2 in mips using sra

#### dh_007

suppose to divide a real number by 2
When I divide by 2 using sra i get 0.000000000 as the result
it works with div $s2,$s1, 1 I get the number i entered printed out

I wondered if I was typing the sra code worng.

Have also tried putting all the numbers in f registers and then trying to divide which comes out the same.

.data # Begin data segment
Tolerence_Msg: .asciiz "Enter tolerence "
Real_Msg: .asciiz "\n\nEnter Real Number: "

.text # Begin code segment
.globl main # first instr must be global

main:

li $v0, 4 # print string code la$a0, Tolerence_Msg # pointer to string
syscall

li $v0, 6 # read float code syscall mfc1$s0,$f0 # move operand tolerence from$f0 to $s0 # Print tolerence results li$v0, 2
mtc1 $s0,$f12 # put tolerence in $f12 for printing syscall li$v0, 4 # print string code
la $a0, Real_Msg # pointer to string syscall li$v0, 6 # read float code
syscall
mfc1 $s1,$f0 # move operand real from $f0 to$s1

# Print real results
li $v0, 2 mtc1$s1,$f12 # put real in$f12 for printing
syscall # prints real number entered

li $v0, 4 # print string code la$a0, Tolerence_Msg # pointer to string
syscall

#addi $s2,$s2,2

#mtc1 $s2,$f2 # f2 = 2
#mtc1 $s1,$f6 # f6 = Real
#div.s $f4,$f6, $f2 # s3 = square_rt #this works div$s2, $s1, 1 sra$t0, $s1, 1 li$v0,2
mtc1 $t0,$f12 # put A in $f12 for printing syscall li$v0,10
syscall

Related Engineering and Comp Sci Homework Help News on Phys.org

"Divide by 2 in mips using sra"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving