Based on the initial register and data memory contents shown
Based on the initial register and data memory contents shown below (represented in hexadecimal), show howthese contents are modified (in
hexadecimal) after executing each of the following AVR assembly instructions.Do not be concerned about what happens to the Status Register (SREG)
afterthe operation.Instructions areunrelated.
(i)sbiw XH:XL, 2
(ii)ldi r27, 85
(iii)ror r2
(iv)adc r2, r1
(v)sts $0007, r28
Solution
We have given the Intial Status Register Value as HexaDecimal FF that is equal to 11111111 means
All Flags bits I T H S V N Z C containing the values 1
( C:Carry Flag, Z: Zero Flag, N: Negative Flag, V: Two’s complement overflow indicator, S: N Å V, For signed tests, H: Half Carry Flag,T:Transfer bit used by BLD and BST instructions, I:Global Interrupt Enable/Disable Flag)
SBIW XH:XL, 2
This statement is used to subtract the immediate value 2 from XH and XL Register Pair, After performing the instruction it affects the Z,C,N,V,S flags
Here we have given XH: XL Pair value in Hexadecimal as 0106
When we perform XH:XL = XH:XL -2 it becomes
XH:XL = 0104 and Status Register becomes
SREG = E0 (ITHSVNZC = 11100000)
LDI r27,85
This statement is used to load immediate value 85 to register r27 , after execution of the statement it does not affect any flag of SREG
Thus
R27=27 and
SREG = E0 (ITHSVNZC = 11100000)
ROR R2
This instruction Rotate Right Through Carry bit and after execution statement affect the status register’s Z,N,C,V flag bits
In case of register R2 containing the value in hexadecimal 1B (00011011) when we rotate right it takes carry bit in and send carry bit out from b0. Here b0 containing the 1 and carry bit containing the 0 so after ROR value become hexadecimal 0D (00001101) which overflow the data so SREG become
R2= 0D
SREG=E9 (ITHSVNZC = 11101001)
ADC R2,R1
This instruction is used to Adds two registers and the contents of the C Flag and places the result in the destination register Rd and affect the H,S,V,N,Z,C flags of SREG
Here values stored in register r2 = 1B (00011011) and r1 = 05 (00000101) and carry bit containing the value=1
After performing the
ADC R2,R1
It generate the value in hexadecimal 21 (000100001) and flag affected are H=1, S=0,V=0, N=0.Z=0, C=0
Thus SREG =E0(ITHSVNZC =11100000)
STS $0007, r28
This statement is used to Stores one byte from a Register to the data space. This statement does not affect any flag bit of the status register.
So after execution of the program segment the final value of the SREG = E0 in Hexadecimal and 11100000 in binary.

