Download HC12 and S12 Assembly Language Programming

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Chapter 2
HC12 and S12 Assembly Language
Programming
Chapter Problems
• Fundamental
1. Write an instruction to load accumulator A with the 8-bit value in memory location $6700.
Answer: LDAA $6700
2. Write two instructions with the same STAB opcode to store the contents of accumulator B to memory
location $0023. (Use two different addressing modes.)
Answer: (1) STAB $0023 and (2) STAB $23
3. Suppose you are required to load an 8-bit value in memory location at $7001 into accumulator A using
the index addressing mode. Suppose also that you decided to use index register X. What should be the
contents of the index register to satisfy the desired task in the following instruction? LDAA $1,X.
Answer: Index register X must have $7000.
4. Write a program segment to compare the contents of register D with immediate value #$1234.
Answer: CPD #$1234
5. Suppose accumulator A contains hexadecimal number $20, and the HC12 executes instruction ADDA
#$E0. What will be the values for the H, Z, N, and C bits as the result of the instruction? Use appendix
A to answer this question, if necessary.
Answer: After the ADDA instruction is executed, the contents of accumulator A will hold $00. The
H flag will not change, the Z bit will be set (1), the N bit is cleared (0), and the C bit will be set (1).
6. Discuss the benefits of the programming approach described in section 2.7.2.
Answer: Following the approach described in the section allows one to divide a complex problem into
a set of simple problems. By solving many simple problems instead of one complex problem, one can
save time for creation and testing of a program.
7. Write a program segment to load an immediate hexadecimal number $30 to accumulator B.
Answer: LDAB #$30
8. What does the following instruction do? LDAA $20,X
Answer: The instruction loads the contents located at the effective address specified by the offset $20
and the contents of the X register. i.e., memory address = contents of X + $20
9. What does the following instruction do? STAA $2, +X
Answer: The instruction first increments the contents of the index register by $2 and stores the contents
of accumulator A in the memory location specified by the revised value in register X.
3
4
CHAPTER 2. HC12 AND S12 ASSEMBLY LANGUAGE PROGRAMMING
10. Write a program segment that initializes memory locations $0000 and $0001 with $12 and $10 using
appropriate directives.
Answer:
ORG
FCB
FCB
$0000
$12
$10
11. Suppose accumulator B has $34. What are the contents of the accumulator if instruction CMPB #$33
is performed? How will the value change if instruction BITB #$33 is performed?
Answer: Both the CMPB instruction and the BITB instruction do not affect the contents of accumulator B.
12. What do the following directives do?
(a) DATA
(b)
(c)
FDB
FCB
FDB
$C200
%11110000
$11
Answer: (a) The directive initializes two memory locations designated by label DATA with $C2,$00.(b)
The FCB directive initializes the next memory location with $F0. (c) The FDB directive initializes the
next two 8-bit memory locations with $11 and $00.
13. What is the difference between the RMB and FCB directives? zzz
14. What addressing modes are used in the following two instructions: LDD #$2000 and LDD $2000.
Answer: LDD #$2000 – Immediate addressing mode
LDD $2000 – Extended addressing mode
• Advanced
1. Describe the function of the program counter in the programming model shown in Fig. 2-1.
Answer: The program counter contains the address of the next instruction to be executed. The HC12
microcontroller uses the program counter to determine the program flow.
2. Suppose that accumulator A contains $45. If we perform instruction SUBA #$44, which of the following
branch instructions will be activated? BHE, BNE, BLT, BHT, BLE, BNZ.
Answer: The resulting value in accumulator A is $01. Thus, the BHE, BNE, BHT, or BNZ is activated
if placed immediately after the SUBA instruction.
3. What are the advantages of using the direct addressing mode?
Answer: Recall that an instruction using the direct addressing mode assumes that the high byte of an
effective address is $00. Thus, a use of the direct addressing mode reduces the size of a program and
execution time.
4. What are the disadvantages of using the direct addressing mode?
Answer: The range of effective address to fetch data is limited from $0000 to $00FF.
5. What is the benefit of using the extended addressing mode?
Answer: There is no restriction on the effective address range.
6. What is the disadvantage of using the extended addressing mode?
Answer: Each instruction specifies a 16-bit effective address, resulting in a larger program.
7. When should the auto-increment feature of the index addressing be used?
Answer: One of the differences the HC12 offers compared to the previous 68HC microcontrollers is the
capability to auto-increment and auto-decrement an index register contents as a part of an instruction.