MIPS/Assembly - Output in binary
BarataPT
Rio-Meão, Portugal
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
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
0
Comments
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.
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