I am having a problem with two practice problems. I read the Appendix from the H
ID: 3868556 • Letter: I
Question
I am having a problem with two practice problems. I read the Appendix from the HCS12 Microcontrollers and Embedded Systems, 1st Edition and could not figure out how to get the answer. I used Freescale Codewarrior and create a program to get the value of $A5 to match answer choice. However, The result shows that I accumulator A value of $22 close to the answers, but it does not show the $A5 and B4 in the memory. I need help to solve this problem and it require a explanation. Due tonight. Thank you
Assume that X = $1052, A = $22, M[1050] = $B4, M[1052] = $5A, After LDAA 2,X-:
X = $1052, A = $5A, M[1050] = $B4, M[1052]=$5A
X = $1050, A = $5A, M[1050] = $B4, M[1052]=$5A
X = $1052, A = $B4, M[1050] = $B4, M[1052]=$5A
X = $1050, A = $B4, M[1050] = $B4, M[1052]=$5A
Assume that X = $1052, A = $22, M[1050] = $B4, M[1052] = $5A, After LDAA 2,-X:
X = $1050, A = $5A, M[1050] = $B4, M[1052]=$5A
X = $1050, A = $B4, M[1050] = $B4, M[1052]=$5A
X = $1052, A = $B4, M[1050] = $B4, M[1052]=$5A
X = $1052, A = $5A, M[1050] = $B4, M[1052]=$5A
Explanation / Answer
1.
Initial values: X = $1052, A = $22, M [1050] = $B4, M [1052] = $5A
Instruction: LDAA 2, X-:
The above instruction loads the accumulator A with the value present at the memory location pointer by the register X.
Since the negative sign is after the register X, the value will be first loaded into the accumulator and then the value of X will be decreased by the offset 2.
The calculation is as follows:
X = $1052
A = M[X] = M [1052] = $5A
X = X – 2 = 1052 – 2 = 1050
Therefore, the answer is X = $1050, A = $5A, M [1050] = $B4, M [1052] = $5A.
2.
Initial values: X = $1052, A = $22, M [1050] = $B4, M [1052] = $5A
Instruction: LDAA 2, -X:
The above instruction loads the accumulator A with the value present at the memory location pointer by the register X.
Since the negative sign is before the register X, the value of X will be decreased by the offset 2 and then the value will be loaded into the accumulator A.
The calculation is as follows:
X = $1052
X = X – 2 = 1052 – 2 = 1050
A = M[X] = M [1050] = $B4
Therefore, the solution is X = $1052, A = $B4, M [1050] = $B4, M [1052] = $5A.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.