1
所以,我有我像02324020這是從MIPS指令的機器代碼以數字的txt文件:add $t0, $s1, $s2
我如何掩蓋我不想從我的機器碼中得到的位?
當它在二進制和切成6,5,5,5,5節,6所採取的數字是:0,17,18,8,0,20
這給出了指令的概念:R [rd] = R [rs] + R [rt]和26- 31是操作碼0意味着R格式,rd = 8,rs = 17,rt = 18
我試圖掩蓋位,所以我只看到21-25之間的位,然後收到它們的數字: 0,17,18,8,0,20因爲向右移動:printf("\n%x\n", code >>26);
給我t他操作碼0並告訴我它的R格式。
所以現在我試圖找到17,但我不知道該怎麼放置後& 0b
在:
printf("\n%x\n", code >>21 & 0b____);
我真的可以用一個例子來從我的電話號碼02324020
找到剩餘的號碼這是我到目前爲止的代碼:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
unsigned int code = 0;
FILE *fp;
fp = fopen(argv[1], "r+");
int result = fscanf(fp, "%x", &code);
printf("\n hex-1: %08X, decimal-1: %d \n", code, code);
printf("\n%x\n", code >>26);
printf("\n%x\n", code >>21 & 0x0b00000011111); //what can i do to change this
while (result != EOF)
{
result = fscanf(fp, "%x", &code);
printf("\n read hex: %08X, decimal: %d \n", code, code);
if(feof(fp))
{
puts("EOF");
break;
}//if
}//while
}
做'代碼>> 21 0b11111'應該給你你正在尋找的17。這不行嗎? – frslm
!!!這確實有效,但爲什麼ob11111?當我試圖獲得下一個18時,它會如何改變? – KunaiBunsen
編輯:等我試了與其他部分,他們的工作哦,我的上帝,這是如此簡單,我不能相信它,謝謝! – KunaiBunsen