Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate the following machine language code (0x2237FFF1) into MIPS assembly

I have translate this code so far and what I'm not understanding is how to figure out (calculate)the amount of 16-bit immediate address.

0x2237FFF1

To binary

0010 0010 0011 0111 1111 1111 1111 0001

Now I'm reading the opcode (001000) and know that it is I-type and addiinstruction

Now I'm grouping the binary into I-type instruction

   op     rs    rt       imm
 001000 10001 10111 1111111111110001
   8      17    23        ?

Looking at the MIPS reference sheet and found out that the instruction must be

 addi $s7,$s1,????

I'm stack here and don't know the method how to determine the 16-bit immediate address in genral.

like image 705
Adam Avatar asked Nov 16 '25 22:11

Adam


1 Answers

You can start by letting the tools do it for you

.word 0x2237FFF1

then assemble and disassemble.

mips-elf-as so.s -o so.o
mips-elf-objdump -D so.o

so.o:     file format elf32-bigmips

Disassembly of section .text:

00000000 <.text>:
   0:   2237fff1    addi    s7,s1,-15

and then do what you were doing, immediates in general are either signed or not (in general within and across instruction sets) in this case it is going to be either 0x0000FFF1 or 0xFFFFFFF1 you can use your calculator or just look at the bits you expanded, twos complement negate invert and add one so your number becomes a binary 1110+1 or 1111 which is 15 so 0xFFFFFFF1 is the signed number -15. Or unsigned 0xFFFFFFF1 whatever that is, a few billion.

EDIT

Unhappy to see my binutils using abi register names, so fixed that:

Disassembly of section .text:

00000000 <.text>:
   0:   2237fff1    addi    $23,$17,-15
like image 117
old_timer Avatar answered Nov 18 '25 21:11

old_timer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!