How to convert from 2-complement to base 10? MIPS

0

I know how to convert from two's complement to base 10 by hand.

http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html

as shown by the link. You can tell if a number is negative or positive by the first bit, so my idea was since the number is 8 bit i would divide by 1000 0000 in binary or hex 0x00000080.

Does anyone have a better solution because right now this is not really working for me, my code is at the bottom. Register 1 is where the two's complement number is.

lis $8
.word 0x00000080

div $1, $8

mflo $9

jr $31
mips
asked on Stack Overflow Jan 27, 2013 by Masterminder • edited Feb 9, 2020 by BasilBrush

1 Answer

2

First what you can do is to create the NOT of the variable. MIPS doesn't have a built in NOT but you can use the XOR to get it (setting a register's value to -1 with addi, using XOR on the register to be negated with the register with -1 in it, which is storing all 1's)

After that it's easy, just add 1 to it.

answered on Stack Overflow Feb 26, 2013 by kousha • edited Feb 9, 2020 by BasilBrush

User contributions licensed under CC BY-SA 3.0