1
votes

I'm currently learning MIPS and I'm confused about how to turn assembly language into binary. I understand that the basic format is:

opcode(6 bit)  rs(5 bit)  rd(5 bit)  rd(5 bit)  shamt(5 bit)  funct(6 bit)

The problem is:

sw $t1, 32($t2)

So far, I know:

$t1 = 01001, $t2 = 01010, opcode for sw = 101011, 32 in binary = 100000

The first thing I'm confused about is shamt, or the shift. I learned that it is a 5-bit value, but 32 in binary is represented by 6 bits.

The second thing I'm confused about is the ordering. This is what I have so far, but I don't think it's right because it's not a 32-bit string:

000000 01010 01001 100000 101011

Can someone explain what the correct binary string is for that assembly language instruction?

1

1 Answers

5
votes

Not all instructions use that machine code format, it looks like mostly arithmetic instructions do. You need a better reference manual that lists encodings for other instructions as well. sw in particular looks like: 1010 11ss ssst tttt iiii iiii iiii iiii where s is the target (!), t is the source, and i is the immediate offset. As such your example looks like 1010 1101 0100 1001 0000 0000 0010 0000 which is 0xAD490020 Check with an assembler:

AD490020      sw $t1, 32($t2)