부호없는 정수 (2 베이트 길이)에서 비트 타이어 연산자를 사용하여 서명되지 않은 숯 변수로 값을 저장 하시겠습니까?
-
06-07-2019 - |
문제
레지스터 4에 0x04의 값을 어떻게 넣습니까? 지침 1RXY 였나요? 메모리 주소 XY의 값과 함께 1RXY-LOAD 레지스터 R
#include <stdio.h>
unsigned char r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,ra,rb,rc,rd,re,rf;
void reg_check(unsigned char reg);
void rxy1(unsigned char reg, unsigned char val);
int main(){
unsigned char memloc1=0x14;
unisgned char memloc2=0x04;
unsigned char temp,reg,val_add;
temp=(x && 0xFF00) >> 8;
if (temp = 0xB){
reg=(memloc1 &0x0F);
val_add=memloc2;
rxy1(reg,val_add);
}
return 0;
}
void reg_check(unsigned char reg){
}
void rxy1(unsigned char reg, unsigned char val){
실제 명령은 0x1404이며, 이는 두 바이트, MEMLOC1 및 MEMLOC2로 분할됩니다. 1RXY의 형식에 따르면, "메모리 위치 XY에 value를 넣는 것을 의미합니다.
그래서 여기에 레지스터 4 또는 unsigned char r4
다른 숫자를 보유하는 메모리 위치 0x04에서 값을 유지해야합니다.
내 질문은 "r"또는 1 "4"04의 "r"또는 1 "r"xy를 테스트하고 xy에 xy에있는 값을 부호되지 않은 char 변수에 배치하여 레지스터 변수를 테스트하는 방법입니다. r4
예를 들어 메모리 위치 인 경우 0x04
유지된 0xFB
.
나는 이것이 의미가 있기를 바랍니다.
편집하다 예시
#include <stdio.h>
int main(){
unsigned char r0,r2,r3,r4;
unsigned char mem1=0x14; //at lmemory address 00
unsigned char mem2=0x04; //at lmemory address 01
unsigned char reg_val_store=mem1 & 0x0F;
if( ((mem1= & 0xF0) >> 4) == 0x1){
if (reg_val_store == 0x4){
//then put value store at memory address "04" into register 4.
//and just say for example "0xFD" was at memory location "04"
//since register value is 4 from the instruction read in 0x1"4"04
//i want to put 0xFD in the r4 unsigned char variable, how do i do this?
r4=0xFD; // this is of course correct but the instruction read in changes and
// so does the register variable. how do i modify my code for this change?
}
}
return 0;
}
해결책
내가 올바르게 이해하면 B4를 메모리 [0]과 04에 메모리 [1]에 넣으려고합니다. 내가 맞아?
이것은 그렇게 할 것입니다.
memory[0] = ((x & 0xFF00) >> 8 ); //Will put B4 in memory[0]
memory[1] = (x & 0xFF); //Will put 04 in memory[1]
다음은 메모리에서 B와 4를 별도로 확인한 다음 다음 단계로 진행하고 싶다고 생각합니다. 오른쪽?
(memory[0] & 0xF0) >> 4 // will give you 0xB
(memory[0] & 0x0F) //will give you 0x4
이것이 당신이 찾고있는 것입니까?
업데이트: 읽기 문제의 경우 이것을 사용해야합니다.
while (!feof(f))
{
fscanf(f,"%X",&inst[i]);
i++;
}
이것은 EOF까지 읽히고이 루프 후 i 값을 사용하여 몇 개의 지시 사항을 읽고 N_INSTR이라는 변수에 넣을 수 있습니다. 그런 다음 '지침을 루핑하려면 이것을 사용할 수 있습니다.
while(loop<n_instr) //instead of just loop<80
{
memory[j] = ((inst[loop] & 0xFF00) >> 8 );
j=j+2;
memory[k] = (inst[loop] & 0x00FF);
k=k+2;
loop++;
}
제휴하지 않습니다 StackOverflow