An overview of the instruction set and program flow control in the hc11 microcontroller. It covers stack and index register instructions, data manipulation, register interchange instructions, and program flow control instructions such as conditional branches and jumps. The document also includes examples and calculations for using time delays and branches.
Download Instruction Set and Program Flow Control in HC11 Microcontroller and more Slides Microprocessor and Interfacing in PDF only on Docsity!
Lecture Overview
Stack and index register instructions
The remaining instructions classes are for program flow control - Branch Instructions - Jump Instructions - Subroutine Calls - No Operation - Stop
REF: Chapter 3 and the appendix that details the instructions.
Stack &Index register instructions
These instructions allow manipulation of the index registers, X and Y, and exchange with the D accumulator. Additionally, they provide the ability to push and pop X and Y to/from the stack.
This class of instructions can be further subdivided into sub-classes of the type of operation.
Data manipulation of contents
Add the B accumulator to and index register
ABX ABY
Does not affect the CC register
Data testing of contents of index register
CPX CPY
There are compares to a 16-bit value in memory
Move the X and Y index registers
Push them on the stack – copy the value in the register to the top of the stack. The register stays the same value. These are 2 byte push and pop operations. - PSHX PSHY
Pull the top 2 bytes from the stack into X or Y
PULX PULY
Store the X or Y index register or the SP
STX STY STS
Load the X or Y index register or the SP
LDX LDY LDS
Register interchange instructions
Values before execution
SP -- $C
X -- $000C
Execute a TSX instruction
Values now
SP -- $C
X -- $C
X is loaded with 1 plus the contents of the stack pointer so that it points to the last value that was stored on the stack.
• Ended here on Fri Jan 27,
Conditional Branches
These are instructions to the control the flow of execution based on a value in the condition code register.
Their general execution is:
If the condition tested is false execution continues with the next instruction.
If the condition tested is true then execution continues at the relative location indicated in the argument of the instruction.
The effect of a branch
A branch controls the flow of execution
Relative addressing mode
Relative means the address is related to something.
It is related to the current instruction address which is in the program counter (PC). The instruction argument is the offset to be taken if the condition is TRUE.
The offset can be positive of negative. It is an 8 bit quantity that is treated as a 2’s complement value and allows offsets of - to +127. Docsity.com
An example
This is a timing delay loop
DECB takes 1usec
BNE takes 1.5 usec
LDAB immediate mode takes 1us
Coding
LDAB #$ count
DELAY: DECB
BNE DELAY
Time delay = 1us+(1us+1.5us)*count
Simple Branches summary
Branch on Carry Set of Carry Clear
BCS BCC
Branch on Zero
Equal to zero – BEQ Not Equal to zero – BNE
Branch on Minus – BMI
Branch on Plus – BPL
Branch on Overflow clear or set
BVC BVS
Unsigned Binary Branches
Branch if higher BHI
CMPA $D380 compares A to the contents of $D
BHI will branch if A > $D380 i.e. A > M
Branch on higher or same BHS
BHI is >
BHS is a ≥ test
Branch if lower BLO <
Branch if lower or equal BLS ≤
Jump and Branch always
Sometimes called unconditional branches
Transfers control to the location specified in the argument of the instruction.
Jump, JMP, uses direct, extended, or indexed addressing for the target address
Branch always – BRA – us a relative transfer
Subroutines
High level languages and good programming practice use subroutines.