将以下机器语言代码(0x2237FFF1)翻译成 MIPS 程序集 [英] Translate the following machine language code (0x2237FFF1) into MIPS assembly
问题描述
到目前为止,我已经翻译了这段代码,但我不明白的是如何计算(计算)16 位立即地址的数量.
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
转二进制
0010 0010 0011 0111 1111 1111 1111 0001
现在我正在阅读操作码 (001000) 并且知道它是 I 类型并且addi
指令
Now I'm reading the opcode (001000) and know that it is I-type and
addi
instruction
现在我将二进制分组为 I 型指令
Now I'm grouping the binary into I-type instruction
op rs rt imm
001000 10001 10111 1111111111110001
8 17 23 ?
查看MIPS参考表,发现指令必须是
Looking at the MIPS reference sheet and found out that the instruction must be
addi $s7,$s1,????
我在这里堆栈,不知道一般情况下如何确定16位立即数的方法.
I'm stack here and don't know the method how to determine the 16-bit immediate address in genral.
推荐答案
你可以先让工具帮你做
.word 0x2237FFF1
然后组装和拆卸.
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
然后做你正在做的事情,通常立即数要么有符号要么没有(通常在指令集内和跨指令集)在这种情况下它将是 0x0000FFF1 或 0xFFFFFFF1 你可以使用你的计算器或只是看看您扩展的位,二进制补码取反并加一,因此您的数字成为二进制 1110+1 或 1111,即 15,因此 0xFFFFFFF1 是有符号数 -15.或者无符号 0xFFFFFFF1 无论如何,几十亿.
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.
编辑
不幸的使用ABI寄存器名见我的binutils,这样固定的:
Unhappy to see my binutils using abi register names, so fixed that:
Disassembly of section .text:
00000000 <.text>:
0: 2237fff1 addi $23,$17,-15
这篇关于将以下机器语言代码(0x2237FFF1)翻译成 MIPS 程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!