1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Divide by 2 in mips using sra

  1. Mar 15, 2009 #1
    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
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted