MIPS/Assembly - Output in binary

BarataPTBarataPT Rio-Meão, Portugal
edited December 2006 in Internet & Media
Hi there,

I have to make a program in Assembly using the MIPS architecture to multiply two single floating point numbers. This was very simple if i was not told to NOT use floating point insctructions.

I started to store in co-processor 1 and then move the value to a register in main processor. Here it is what i have done so far:

.data
mask: 0x7F800000

.text

# Reads the number for $f0 (single floating point) and then i move it for a main processor register

read :li $v0, 6
syscall
mfc1 $a0, $f0

#this code is to extract from the floating point number only the exponent using the and insctrution i create a mask with "1" with 8 bits (as you should know single floating point representation is 32 bits - 1 bit for signal, 8 for exponent and the last 23 for significand)

exp: lw $t0, mask
and $a1, $t0, $a0
srl $t1, $a1, 23

This works all fine, cause i checked the Hexa-Decimal values and it were correct, but now my problem is how can i output that values in binary format.

For example in the register $a0 is F8, i want to output 1111 1000

Thanks in advice, and sorry for my bad english, i'm from Portugal :wink:

Comments

  • KyleKyle Lafayette, LA New
    edited December 2006
    I don't know of a one-line way to use syscall to output a value in binary, but here's an idea:
    • Shift the value right 7 times (so that most significant bit is at the least significant spot, fill with zeros)
    • Apply a mask to isolate the least significant bit ($t2 = $a0 AND 0x01)
    • Output the resulting byte (should just be 0 or 1)
    • Repeat, shifting only 6 times, then 5, and so on

    Wouldn't that work? I don't remember how outputting works and if it drops down to a new line after each syscall or not. If it doesn't make a new line you should just be able to output each bit sequentially like that.
  • BarataPTBarataPT Rio-Meão, Portugal
    edited December 2006
    Very good idea man, now it works perfect :D

    Only one thing when you say to shift 7 times for exponent, is not 7 but 30 cause you have to read from right to left the number and then i continue shifthing til 22 (8 bits for exponent) and doing the "and" to extract the "1" or "0", and then it works perfect...

    Many thanks
Sign In or Register to comment.