PLEASE DO NOT COPY AND PASTE AN ANSWER FROM A SIMILAR CHEGG QUESTION, CAUSE THEY
ID: 2249282 • Letter: P
Question
PLEASE DO NOT COPY AND PASTE AN ANSWER FROM A SIMILAR CHEGG QUESTION, CAUSE THEY ARE WRONG. IF YOU DO I WILL DOWNVOTE IMMEDIATELY. PLEASE EXPLAIN
The following code is used to initialize the Z pointer for indirect addressing:
ldi ZH, high(table<<1)
ldi ZL, low(table<<1)
a. Why are two registers required to initialize the pointer to the correct address?
b. If the address for the start of “table” is at 0x1621 and the data that being saved in table is 0x92 and 0x26, what will the value in the Z register be (for ZH and ZL)? Explain.
c. What value does the expression table<<1 represent?
Explanation / Answer
Answer:-a) Z is a pointer register made of registers R30 and R31. So this is a 16-bit pointer. AVR SRAM address is also a 16-bit value. Thus to point a particular location in SRAM, both registers R30(Z-low) and R31(Z-high) is to be loaded. Lower 8-bit of address in R30 and higher 8-bit of address in R31.
b) Z register always keeps the address and not the value at that address, so here as per instruction ZH = 0x2C and ZL = 0x42. The values are one bit left shited. This is done because we have one address(as here 0x1621) and two data(as here 0x92 and 0x26). So to take one data from same address we focus on LSB of ZL, if LSB of ZL is zero means lower data will be taken otherwise second byte(higher) data will be taken.
c) table<<1 means shift the address of table left by one bit or multiply the address of table by 2, since shifting left by one bit is same as multiplying by 2.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.