ビット単位演算子を使用して、符号なし整数(長さ2バイト)から符号なしchar変数に値を保存しますか?

StackOverflow https://stackoverflow.com/questions/1414555

質問

命令は1rxyでしたか? 1RXY-レジスタRにメモリアドレスXYの値をロードします

#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の2バイトに分割されます。 1rxyの形式によると、「at」という値を置くことを意味します。レジスタrのメモリ位置xy。

レジスタ4または unsigned char r4 は、他の数値を保持するメモリ位置0x04に値を保持する必要があります。

質問は、「r」を決定してレジスタ変数をテストする方法です。または1 "4" 04の1 "r" 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]

次に、メモリ[0]で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などの変数に格納できます。そして、「throをループする」ためにこれを使うことができます

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++;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top