Note that there are some explanatory texts on larger screens.

plurals
  1. POstoring a value from an unsigned integer (2bytes long) to an unsigned char variable using bitwise operators?
    primarykey
    data
    text
    <p>How do I put the value of 0x04 in register 4 if the <a href="https://stackoverflow.com/questions/1396732/how-do-i-read-hex-numbers-into-an-unsigned-int-in-c">instruction</a> was 1rxy? 1RXY-Load register R with the value at memory address XY</p> <pre><code>#include &lt;stdio.h&gt; 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 &amp;&amp; 0xFF00) &gt;&gt; 8; if (temp = 0xB){ reg=(memloc1 &amp;0x0F); val_add=memloc2; rxy1(reg,val_add); } return 0; } void reg_check(unsigned char reg){ } void rxy1(unsigned char reg, unsigned char val){ </code></pre> <p>The actual instruction is 0x1404, this split into two bytes, memloc1 and memloc2. According to the format of 1rxy, which means to put value "at" memory location xy in register r. </p> <p>so here register 4 or <code>unsigned char r4</code> would have to hold the value at memory location 0x04 which would hold some other number.</p> <p>My question is how do I test for the register variable by determining the "r" or 1"r"xy in 1"4"04 and placing the value held at the location xy into the unsigned char variable <code>r4</code></p> <p>for example if memory location <code>0x04</code> held <code>0xFB</code>.</p> <p>I hope this makes sense.</p> <p><strong>[edit]</strong> <strong><em>Example</em></strong></p> <pre><code>#include &lt;stdio.h&gt; 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 &amp; 0x0F; if( ((mem1= &amp; 0xF0) &gt;&gt; 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; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload