• Support PF! Buy your school textbooks, materials and every day products via PF Here!

Divide by 2 in mips using sra

  • Thread starter dh_007
  • Start date
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:

# header message
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
 

Want to reply to this thread?

"Divide by 2 in mips using sra" You must log in or register to reply here.

Related Threads for: Divide by 2 in mips using sra

  • Posted
Replies
4
Views
6K
Replies
3
Views
2K
  • Posted
Replies
10
Views
1K
  • Posted
Replies
8
Views
720
Replies
4
Views
3K

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
Top