0% found this document useful (0 votes)
26 views21 pages

N2 - ASM Instruction Execution

Uploaded by

1553
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views21 pages

N2 - ASM Instruction Execution

Uploaded by

1553
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

ECE

HC12/S12 Programmer’s Model 331

• Programmer’s Model = model of µC useful to view hardware


during execution of software instructions

• Recall: General Microcontroller/Computer Architecture


– note: Control Unit & Register File

CPU Memory I/O Devices


program data
Control
Unit m n m n

m-bit address bus


ALU
Buses
Register n-bit data bus
File
Data Path control bus

 2013, Professor A. Mason AMS Instruction Execution p.1

ECE
HC12/S12 Programmer’s Model 331

• Programmer’s Model = model of µC useful to view hardware


during execution of software instructions
– focus on Register File & Control Unit of a specific controller
• will be different for each different brand/model of controller

A 7  6  5  4  3  2  1  0 B 7  6  5  4  3  2  1  0 2@8-bit Accumulator: A,B


Register File

D 15  14  13  12 11 10  9  8  7  6  5  4  3  2  1  0 or 1@16-bit Accumulator: D

IX 15  14  13  12 11 10  9  8  7  6  5  4  3  2  1  0 16-bit Index Register: X

IY 15  14  13  12 11 10  9  8  7  6  5  4  3  2  1  0 16-bit Index Register: Y

IR 7 . . . 0 7 . . . 0 7 . . . 0 7 . . . 0 Multi-byte Instruction Register


current instruction
Control Unit

PC 15  14  13  12 11 10  9  8  7  6  5  4  3  2  1  0 16-bit Program Counter


address of next instruction

SP 15  14  13  12 11 10  9  8  7  6  5  4  3  2  1  0 16-bit Stack Pointer


address of stack

CCR 7 S  X  H  I  N  Z  V  C 0 8-bit Condition Code Register

 2013, Professor A. Mason AMS Instruction Execution p.2


ECE
HC12/S12 Programmer’s Model 331

• Register File 2@8-bit Accumulator: A,B


A 7 ‐ 0 B 7 ‐ 0
– store data in/out of memory or ALU or 1@16-bit Accumulator: D

Register File
D 15 ‐ 8 7 ‐ 0
– Accumulators: 2 @ 8-bit OR 1 @ 16-bit

ALU
16-bit Index Register: X

Central Processing Unit


• general purpose storage IX 15  ‐ 8 7 ‐ 0
16-bit Index Register: Y
– Index Registers: 2 @ 16-bit IY 15  ‐ 8 7 ‐ 0
• general purpose or in indexed addressing Multi-byte Instruction Register: current instruction

• Control Unit IR 7 ‐ 0 7 ‐ 0 7 ‐ 0

Control Unit
16-bit Program Counter: addr. next instruction

– Instruction Register (IR) PC 15 ‐ 8 7 ‐ 0

• holds current instruction, multi-byte


16-bit Stack Pointer: address of stack
SP 15 ‐ 8 7 ‐ 0
– Program Counter (PC) 8-bit Condition Code Register
CCR 7 S  X  H  I  N  Z  V  C 0
• holds address of next instruction, 16-bit
– Stack Pointer (SP)
• holds address of stack (special block of memory), 16-bit
– Condition Code Register (CCR)
• holds “flag” values generated by last instruction executed, 8-bit
• known as Status Register in other controllers
 2013, Professor A. Mason AMS Instruction Execution p.3

ECE
Condition Code Register 331

• CCR = register 8 of individually functioning bits


– AKA: Flags Register, Status Register

CCR 7 S  X  H  I  N  Z  V  C 0
Stop Disable Carry/Borrow
External Interrupt Mask Overflow BLACK = set by ALU
Half Carry Zero GRAY = other; covered later
Interrupt Mask Negative

• ALU Status Flags: each condition tested after each instr. exec.
– C: Carry Flag
• = 1 if carry (addition) or borrow (subtraction) occurs in instr. exec.
– V: Overflow Flag 2C _ Overflow  An 1  Bn 1  S n 1  An 1  Bn 1  S n 1
• = 1 if 2’s complement overflow occurs in instr. exec.
– Z: Zero Flag: =1 if ALU result = 0
– N: Negative Flag: =1 if MSU of ALU result is 1 (i.e., negative in S2C)
– H: Half-Carry Flag: =1 if carry from lower nibble (nibble = ½ byte =4 bits)
1
 2013, Professor A. Mason AMS Instruction Execution p.4
ECE
CCR Examples 331

• Instructions & resulting CCR flag status


– 8-bit addition (hexadecimal)
• assign each problem to group
of students to evaluate as
• B7 + 4A TPS exercise
• write answers (C=, V=, etc)
on board before next slide

• 07 + F9

• B6 + 9A

 2013, Professor A. Mason AMS Instruction Execution p.5

ECE
CCR Examples 331

• Instructions & resulting CCR flag status


– 8-bit addition

• B7 + 4A

• 07 + F9

• B6 + 9A

V (2C overflow) is ALWAYS checked, even if value is not in S2C


 2013, Professor A. Mason AMS Instruction Execution p.6
ECE
CCR Examples & Carry Flag Rules 331

• Instructions & resulting CCR flag status


– 8-bit subtraction (hexadecimal)

• 00 – 17

• Carry Flag (C) Rules


* if A + B (addition), then C = carry_out (Cout)
* if A – B (subtraction), then C = Cout (not_Cout, inverse)
• if A > B, no borrow is needed  C = 0
• if A < B, borrow needed  C = 1
9
 2013, Professor A. Mason AMS Instruction Execution p.7

ECE
CCR Example: Carry Flag & Subtraction 331

• Evaluate: -4 – (-3)
– operation is A – B (subt.)  C = Cout
– A < B  borrow will be needed  C should be 1

Note: in S2C form, the more negative a number is, the “smaller” it is
EX: -4 = 1100 is smaller than -3 (= 1101)
Thus, you can compare A < or > B in normal/decimal or S2C notation

6
 2013, Professor A. Mason AMS Instruction Execution p.8
ECE
HC12/S12 Assembly Instructions 331

• Assembly (ASM) language: programming in the smallest unit


of machine (µC, µP) action

• Example ASM program code

• ASM Instruction Format


– LABEL INSTR_MNEMONIC OPERAND(S) COMMENT
– example:

 2013, Professor A. Mason AMS Instruction Execution p.9

ECE
HC12/S12 Assembly Instructions 331

• ASM Instruction Format


– LABEL INSTR_MNEMONIC OPERAND(S) COMMENT
– example:

• LABEL: identifies location of a line of code


– used by Assembler (compiler); not part of actual instructions
– generally used for looping (jump, branch)
– CHECK is branch location of later instruction (BRA CHECK)
• MNEMONIC: text code for each ASM instruction
– translated by Assembler to a specific instr. “op-code”
• op-code = hex machine code for each ASM instruction
– CMPA is instruction to compare value in accA to operand value
• OPERAND: data/address used by ASM instruction
– function of “addressing mode” (discussed later)
– some instr. don’t have operands
– #$0A is the value accA will be compared to
 2013, Professor A. Mason AMS Instruction Execution p.10
ECE
HC12/S12 Assembler Notation 331

• $ = HEX value
– EX: $12 = 1810
• % = BIN value
– EX: %10 = 210
• none = DEC value
– EX: 12 = 1210
• # denotes a data value (rather than an address)
– EX: ADDA #$A5, adds value $A5 to accA
ADDA $A5, adds value at address $A5 to accA
– illustration to clarify will come soon!
• first need to make things even more complicated 

 2013, Professor A. Mason AMS Instruction Execution p.11

ECE
ASM Instructions & Program Assembly 331

• Example ASM program code

• Program Assembly
– instr._mnemonics converted to HEX op-codes

• So… HEX values can represent


– instruction op-code bytes
– instruction data or operand bytes
– data/instruction address bytes
– and you need to be able to tell which witch is which!
 2013, Professor A. Mason AMS Instruction Execution p.12
ECE
Clear As Mud! 331

• Relationship between Software (instruction) and Hardware


– Program Elements:
• SOFTWARE: location of instr., action to perform, data to act on
• HARDWARE: address, CPU control bits, data bits (or address of data)

• Relationship between Program and Data memory


– all instructions are converted to hex and stored in memory
• Program Memory = block of memory addresses allocated to program bytes
– most instruction act on data and produce results stored in memory
• Data Memory = block of memory addresses allocated to data bytes

• Relationship between Address and Data values


– evaluate: block 1 block 2 block 3 Address
• #1 + #2 = #3 4 5 6 Data within address
• #1 + 2 = #6
– no “#” implies an address; value in block 2 is #5, so #1+#5=#6

 2013, Professor A. Mason AMS Instruction Execution p.13

ECE
68HC12 Expanded Programmer’s Model 331

• CPU (ALU, Register File, Control Unit) and Memory


– note separate memory allocated for Program and Data

 2013, Professor A. Mason AMS Instruction Execution p.14


ECE
Microcontroller Program Development 331

from concept to action…


A. Write program to complete task
• check syntax; test functionality (Simulator)
B. Assemble program (Assembler)
• ASM code  Machine code (op-codes and operands)
C. Upload program to program memory
D. Run program on Microcontroller
• set PC to start of program memory
1. fetch instruction to IR from program memory
2. decode instruction: set ALU to perform instruction
3. execute instruction: load/store to data memory & register file
• advance PC to next instruction in program memory
• repeat step 1 until commanded to stop

 2013, Professor A. Mason AMS Instruction Execution p.15

ECE
Instruction Execution Cycle 331

• 3 steps of instruction execution cycle


– Fetch: Load instruction byte from program memory into IR
– Decode: Translate op-code to control signals for ALU and Control Unit
– Execute: Pass data through ALU to generate desired result

• Example
1. fetch bytes for LDAA #$00
2. decode: set ALU to load value
#$00 into accA
3. execute: accA contains $00
4. fetch bytes for CMPA #$0A
5. decode: set ALU to compare accA with the value $0A
6. execute: set C/V/N/Z flags (e.g., if accA were $0A, Z1)
7. etc…

 2013, Professor A. Mason AMS Instruction Execution p.16


ECE
Instruction Cycle Example 331

• Code Executed:
– LDAA $3000 (load from $3000)
– STAA $2000 (store to $2000)

• Explaining the instruction execution chart

 2013, Professor A. Mason AMS Instruction Execution p.17

ECE
Instruction Cycle Example 331

• Code Executed:
– LDAA $3000
• (load from $3000)
– STAA $2000
• (store to $2000)

 2013, Professor A. Mason AMS Instruction Execution p.18


ECE
HC12 Instruction Set 331

• Instruction Set: the full set of functional instructions a


µC/µP can execute
– varies with each family of controllers, but generally very similar

• Basic types of instructions (see HO_3)


– Data Transfer/Manipulation
• move data to/from memory; shift/rotate; etc.
– Arithmetic
• add; subtract; increment; decrement; etc.
– Logic & Bit Operations
• Boolean logic; condition flag clears; etc.
– Data Test
– compare/test data & set CCR flags (test for conditional branches)
– Branch
– jump out of program sequence; if-then-else operations
– Function Call (Subroutine) covered later
• start/end subroutines; adjust PC in class
 2013, Professor A. Mason AMS Instruction Execution p.19

ECE
Reading HO_3 331

• Information in HO_3 instruction tables


– mnemonic
– description of function
– operation in terms of programmer’s model elements
– CCR flag affects

Data Transfer/Manipulation
Table A. Load instructions put data into CPU memory (e.g. Register File)
Mnemonic Function Operation C V Z N
LDAA Load accumulator A AM -- 0  
LDAB Load accumulator B BM -- 0  
LDD Load accumulator D A  M, B  M+1 -- 0  
LDX Load index register X X  M:M+1 -- 0  
LDY Load index register Y Y  M:M+1 -- 0  
LDS Load stack pointer (SP) SP  M:M+1 -- 0  

Memory address (M) defined by instruction operand

all these instructions CLEAR ‘V’ (make 0) and


CHANGE ‘Z’ and ‘N’ based on ALU result

 2013, Professor A. Mason AMS Instruction Execution p.20


ECE
2-byte Operations 331

• Accumulators
– accA is MSBy of accD; accB is LSBy of accD

• Memory operations
– instructions refer to only one 8-bit memory address
• where does 2nd byte come from for 16-bit instructions (e.g., LDX)
– defined/reference memory address (M)  MSBy; M+1  LSBy

16-bit Register (e.g., iX) 8-bit memory address e.g., M = $679D


MSBy [8:15] LSBy [0:7] M-1 $679C
M $679D
M+1 $679E
M+2 $679F
M+3 $67A0

 2013, Professor A. Mason AMS Instruction Execution p.21

ECE
Quick Review: HC12 Instructions 331

Data Transfer/Manipulation
Table B. Store instructions put data (from CPU) into memory
Mnemonic Function Operation C V Z N
STAA Store accumulator A AM -- 0  
STAB Store accumulator B BM -- 0   You don’t have to memorize
A  M, B  M+1  
these. Instruction tables will
STD Store accumulator D -- 0
STX Store index register X X  M:M+1 -- 0  
STY Store index register Y Y  M:M+1 -- 0   always be available to you.
STS Store stack pointer (SP) SP  M:M+1 -- 0   Even on exams!
Table C. Move/transfer instructions copy data to a memory/register
Mnemonic Function Operation C V Z N
TAB Transfer acc. A to acc. B BA -- 0  
TBA Transfer acc. B to acc. A AB -- 0  
TAP Transfer acc. A to CCR CCR  A    
TPA Transfer CCR to acc.A A  CCR -- -- -- --
(M)1  (M)2
which is which?
MOVB Mem to Mem: move byte -- -- -- --
MOVW Mem to Mem: move Word (M:M+1)1(M:M+1)2 -- -- -- --

Shift/rotate instructions
Logic shift: input = 0, output to carry_out
Arithmetic shift: shift right puts copy of MSB into MSB
Rotate: input rolls from output (carry_out included)

 2013, Professor A. Mason AMS Instruction Execution p.22


ECE
Quick Review: HC12 Instructions 331

• Arithmetic
– Addition: adds Register with Memory (or Register), stores in Register
• note: A  A+B, but no B  A+B
– Subtraction: subtr. Register with Memory (or Register), stores in Register
– Decrement: subtr. 1 from value in (M, A, B, SP, X or Y)
– Increment: add 1 to value in (M, A, B, SP, X or Y)
• Logic
– AND, OR, XOR, Complement (invert)
– 2’s complement = $00 – A (or B); additive inverse, same as A’+1
• Bit Operations
– Clear CCR flags: C, I, V
– Bit Test; AND’s A (or B) with Memory: application unknown to me 
– Bit Set/Clear
• clears (make 0) or sets (make 1) individual bits of a byte
• can affect 1 or multiple bits
• very useful for defining individual bits of an I/O port
• requires a “mask” byte
 2013, Professor A. Mason AMS Instruction Execution p.23

ECE
Masking Concept 331

• Bit set/clear instructions (BSET, BCLR) [as well as some others


we’ll learn later] use mask bytes.
– Mask byte defines which bits of a byte will be affected by instr.
• other bits will not be changed
• Instruction format
*only operates on Memory; not
– mnemonic mem_addr mask on CPU registers or operands
BSET/BCLR addr of data bits to set/clr

– if mask bit = 1  change


– if mask bit = 0  don’t change
• Examples: ASM instruction

because masking is bit-wise operation,


mask bytes often specified in binary
 2013, Professor A. Mason AMS Instruction Execution p.24
ECE
BSET/BCLR Examples 331

• Determine memory value after each instruction INITIAL


addr. value
set/clear all bits that are ‘1’ in the mask operand $009C $9C
– BSET $9D %10101010 data: 1010 1101 $009D $AD
• value in $9D is $AD = %1010 1101 mask: 1010 1010 $009E $E2
• bset  $AF bset-> 1010 1111
red=set, blue=pass $67B2 $FF
– BSET $67B3 %11100111 data: 0000 0000 $67B3 $00
• value in $67B3 is $00 mask: 1110 0111
• bset  $E7 bset-> 1110 0111

– BCLR $009E %10000001 data: 1110 0010 FINAL


• value in $009E is $E2 mask: 1000 0001 addr. value
• bclr  $62 bclr-> 0110 0010
$009C $00
red=clr, blue=pass
– BCLR $009C $9C $009D $AF
data: 1001 1100 $009E $62
• value in $9C is $9C mask: 1001 1100
• mask also $9C = %1001 1100 bclr-> 0000 0000
$67B2 $FF
• bclr  $00
$67B3 $E7

 2013, Professor A. Mason AMS Instruction Execution p.25

ECE
Quick Review: HC12 Instructions 331

Data Test Instructions


• Compare Data Compare: C= , V=, Z=, N=
– compare 2 values by subtracting them
– CCR flags will show <, >, or =
• N will show which was greater
EX: CBA  Compare A=$5D to B=$37
 A – B  $5D - $37
 N = 0  A > B (subtraction not negative)

• Z will show if they were equal

• Test Data
Test: C= 0, V=0, Z=, N=
– subtracts $00
– CCR flags show if value in tested memory/register is
negative (N) or zero (Z)

 2013, Professor A. Mason AMS Instruction Execution p.26


ECE
Address Modes 331

• 68HC12 has six (6) addressing modes


– addressing modes define how data is associated with an instruction
– Inherent: instruction requires no data form outside the CPU
• EX: ABA {A  A+B} or INX {increment iX by 1}
remaining 2 modes
• inherent instructions have no operands are more
– all needed data within CPU registers complicated and will
– Immediate: data value is in operand (not in memory) be covered later
• easily identified by having a # in the operand
• EX: LDAA #$F3 {put $F3 into accA} or ANDA #$2C
– Extended: data for instruction is in memory <..> notation means the
• 2-byte operand specifies memory address value at this mem. addr.
• EX: LDAB $20B4 {put value in $20B4 into accB; B  <$20B4>}
– Direct: data for instruction is in memory with 1-byte address
• special case of Extended
– used for addresses $0000 – $00FF (256 bytes), where MSBy is $00
– saves program bytes and execution time; eliminates 1 operand value
– addresses $00–$FF largely used by configuration registers (control I/O functions)
• EX: ADDA $E3 {A  A+<$00E3>}
 2013, Professor A. Mason AMS Instruction Execution p.27

ECE
Address Modes 331
Identify the address mode for each of the following instructions
– Inherent, Immediate, Direct, Extended

– LDAB #$4F Immediate


– STAA $8D2C Extended
– ABA Inherent
– LDX #$8D2C Immediate
– STY $8D2C Extended
– INCB Inherent
– ANDA $C6 Direct
– TAB Inherent
– LSL $F0 Direct
– SUBD $8D2C Extended
– ADDD #$0750 Immediate

 2013, Professor A. Mason AMS Instruction Execution p.28


ECE
Quiz 1 Topics 331

• Following topics should be studied for Quiz 1


– ECE230 review
• base conversion
• S2C form and conversions
• Boolean logic; DeMorgan’s rules
• flip-flop/register operation
– Microcontroller architecture; structure & name/function of blocks
– 68HC12 programmers model
– CCR bits; setting after hexadecimal math
– 68HC12 instruction format & execution cycle
– masking concept: BSET/BCLR instructions
– 68HC12 address modes: the simple ones (INH, IMM, DIR, EXT)

 2013, Professor A. Mason AMS Instruction Execution p.29

ECE
Instruction Register Chart 331

Initial Values
Action: _______________________ A ABA
Action: _______________________ B
Inherent
Add B to A
aA $A2 aB $4B $0060 $20
aA $ED aB $4B $0060 $20 A2
$0061 $00 $0061 $00
+4B
IX $2100 IX $2100
=ED
$00C7 $FF $00C7 $FF
Memory

Memory

IY $1000 IY $1000
$2000 $31 $2000 $31
SP ignore SP ignore
$2001 $5E $2001 $5E
PC ignore $2002 $20 PC ignore $2002 $20
CCR H N Z V C CCR H N Z V C
address value address value

Initial Values
Action: _______________________ A INCB
Action: _______________________ B Inherent
Increment B
aA $A2 aB $4B $0060 $20
aA $A2 aB $4C $0060 $20 (B  B+1)
IX $2100 $0061 $00 IX $2100 $0061 $00
$00C7 $FF $00C7 $FF
Memory

Memory

IY $1000 IY $1000
$2000 $31 $2000 $31
SP ignore SP ignore
$2001 $5E $2001 $5E
PC ignore $2002 $20 PC ignore $2002 $20
CCR H N Z V C CCR H N Z V C
address value address value
 2013, Professor A. Mason AMS Instruction Execution p.30
ECE
Instruction Register Chart 331

Initial Values
Action: _______________________ A ANDA #$4C
Action: _______________________ B
Immediate
AND aA w/ M
aA $A2 aB $4B $0060 $20
aA $00 aB $4B $0060 $20 (A2)(4C)
$0061 $00 $0061 $00
A2 = 1010 0010
IX $2100 IX $2100
4C = 0100 1101
$00C7 $FF $00C7 $FF

Memory

Memory
IY $1000 IY $1000 0000 0000
$2000 $31 $2000 $31
SP ignore SP ignore
$2001 $5E $2001 $5E
PC ignore $2002 $20 PC ignore $2002 $20
CCR H N Z V C CCR H N Z V C
address value address value

Immediate Inherent
Initial Values
Action: _______________________ A
Action: LDX #$8000
_______________________ B ABX Add B to iX
Action: _______________________ C
aA $A2 aB $4B $0060 $20 $A2
aA aB $4B $0060 $20
aA $A2 aB $4B $0060 $20
IX $2100 $0061 $00IX $8000 $0061 $00 IX $804B $0061 $00
$00C7 $FFIY $00C7 $FF $00C7 $FF
Memory

Memory

Memory
IY $1000 $1000 IY $1000
$2000 $31 $2000 $31 $2000 $31
SP ignore SP ignore SP ignore
$2001 $5E $2001 $5E $2001 $5E
PC ignore $2002 $20PC ignore $2002 $20 PC ignore $2002 $20
CCR H N Z V C CCR H N Z V C CCR H N Z V C
address value address value address value
 2013, Professor A. Mason AMS Instruction Execution p.31

ECE
Instruction Register Chart 331

Initial Values
Action: _______________________ A LDX $60
Action: _______________________ B Direct
Load iX from M (60)
aA $A2 aB $4B $0060 $20
aA $A2 aB $4B $0060 $20
IX $2100 $0061 $00 IX $2000 $0061 $00
$00C7 $FF $00C7 $FF
Memory

Memory

IY $1000 IY $1000
$2000 $31 $2000 $31
SP ignore SP ignore
$2001 $5E $2001 $5E
PC ignore $2002 $20 PC ignore $2002 $20
CCR H N Z V C CCR H N Z V C
address value address value

Direct
LDAA $C7
Action: _______________________ C STAA $2001
Action: _______________________ D
Extended
aA $FF aB $4B $0060 $20
aA $FF aB $4B $0060 $20
IX $2000 $0061 $00 IX $2000 $0061 $00
$00C7 $FF $00C7 $FF
Memory

Memory

IY $1000 IY $1000
$2000 $31 $2000 $31
ignore ignore
$2001 $FF
SP SP
$2001 $5E $5E
PC ignore $2002 $20 PC ignore $2002 $20
CCR H N Z V C CCR H N Z V C
address value address value
 2013, Professor A. Mason AMS Instruction Execution p.32
ECE
Instruction Register Chart: CCR Flags 331

ABA
Action: _______________________ B INCB
Action: _______________________ B
aA $ED aB $4B $0060 $20
aA $A2 aB $4C $0060 $20
IX $2100 $0061 $00 IX $2100 $0061 $00
$00C7 $FF $00C7 $FF

Memory

Memory
IY $1000 IY $1000
$2000 $31 $2000 $31
SP ignore SP ignore
$2001 $5E $2001 $5E
PC ignore $2002 $20 PC ignore $2002 $20

0 1 0 0
CCR H N Z 0
V C
address value - 0 0 x
CCR H N Z -
V C
address value

ANDA #$4C
Action: _______________________ B A
Action: LDX #$8000
_______________________ B
aA $00 aB $4B $0060 $20
aA $A2 aB $4B $0060 $20
IX $2100 $0061 $00 IX $8000 $0061 $00
$00C7 $FF $00C7 $FF
Memory

Memory
IY $1000 IY $1000
$2000 $31 $2000 $31
SP ignore SP ignore
$2001 $5E $2001 $5E
PC ignore $2002 $20 PC ignore $2002 $20

- 0 1 0V -
CCR H N Z C
address value - 1 0 0 -
CCR H N Z V C
address value
 2013, Professor A. Mason AMS Instruction Execution p.33

ECE
Instruction Register Chart: CCR Flags 331

ABX Add B to iX
Action: _______________________ C LDX $60
Action: _______________________ B
aA $A2 aB $4B $0060 $20
aA $A2 aB $4B $0060 $20
IX $8048 $0061 $00 IX $2000 $0061 $00
$00C7 $FF $00C7 $FF
Memory

Memory

IY $1000 IY $1000
$2000 $31 $2000 $31
SP ignore SP ignore
$2001 $5E $2001 $5E
PC ignore $2002 $20 PC ignore $2002 $20

0 1 0 0
CCR H N Z 0
V C
address value - 0 0 0V -
CCR H N Z C
address value

LDAA $C7
Action: _______________________ C STAA $2001
Action: _______________________ D
aA $FF aB $4B $0060 $20
aA $FF aB $4B $0060 $20
IX $2000 $0061 $00 IX $2000 $0061 $00
$00C7 $FF $00C7 $FF
Memory

Memory

IY $1000 IY $1000
$2000 $31 $2000 $31
ignore ignore
$2001 $FF
SP SP
$2001 $5E $5E
PC ignore $2002 $20 PC ignore $2002 $20

- 1 0 0V -
CCR H N Z C
address value - 1 0 0 -
CCR H N Z V C
address value
 2013, Professor A. Mason AMS Instruction Execution p.34
ECE
Indexed Address Mode 331

• Indexed: instruction data is in memory at address


specified relative to (offset from) a reference address
that is stored in a CPU register
– reference address can be in iX, iY, SP, or PC
– offsets are signed number  can offset forward or backward
– useful for accessing a list of data beginning (or ending) at the
reference address
• Several varieties of indexed addressing in HC12 ASM
– we will only study Indexed-Immediate ex: addr.
6015
– others covered in textbook and HO_3 6016
index 6017
6018

offset
6019
6017 601A
$XX 601B
reference 601C
CPU register 601D
601E
block of memory
 2013, Professor A. Mason AMS Instruction Execution p.35

ECE
Indexed-Immediate Addressing 331

• Indexed-Immediate
– reference address in iX, iY, SP, or PC
– offset address in operand
• just like Immediate address mode has data in operand
• Format: MNEMONIC offset,reference
• Example: LDX #$6017
LDAA $05,X {accA  <$B5+<iX>>}
• accA loaded with value in memory at addr ($65 + value in iX)
ex: addr.
• note: value at index, < <iX> >, is irrelevant 6015
– unless instr. was LDAA $00,X 6016
index 6017
1 6018
offset

2 6019
$27
accA $AA iX 6017 3 601A
target of reference 4 601B
5 $27 601C
instruction 601D
601E
block of memory
 2013, Professor A. Mason AMS Instruction Execution p.36
ECE
Indexed Immediate Addressing 331

• Example INITIAL addr. FINAL addr.


– LDY #$5000
B3 5000 B3 5000
28 5001 28 5001
– ADDA $4C,Y accA $21 52 5002 accA $3B 52 5002
accB $80 00 5003 accB $80 00 5003
A  A + M, ... ... ... ...
iX $2000 50 504A iX $2000 50 504A
M = <$4C + <iY> >
4B 504B 4B 504B
M = $504C iY $5000 iY $5000
1A 504C 1A 504C
A  $21 + $1A reference 04 504D reference 04 504D
A  $3B 5E 504E 5E 504E
memory block memory block
• Example (same memory as above)
1) LDY #$5000 1 2 3 4
2) ADDA 0,Y
accA $21 accA $D4 accA $D4 accA $FC
3) INY accB $80 accB $80 accB $80 accB $80
4) ADDA $0,Y
• can add a series of iX $2000 iX $2000 iX $2000 iX $2000
numbers like this iY $5000 iY $5000 iY $5001 iY $5001
• reload Y to move to
another set
 2013, Professor A. Mason AMS Instruction Execution p.37

ECE
Instruction Register Chart 331

Initial Values
Action: _______________________ A LDX $3011
Action: _______________________ B Add B to A
A2
aA $A2 aB $01 $00F0 $2C
aA $A2 aB $01 $00F0 $2C
+4B
=ED
IX $2100 . . . ... IX $3100
$3011 . . ...
$3011 $31 $3011 $31
Memory

Memory

IY $1000 IY $1000
$3012 $00 $3012 $00
SP ignore ...
SP ignore ...
. . . . . .
PC ignore $301A $20 PC ignore $301A $20
CCR H N Z V C $3109 $BE CCR H N Z V C $3109 $BE
address value address value

ORAB #$F0
Action: _______________________ C which is right?
STAB $09,X
Action: _______________________ D
which is right?
aA $A2 aB $F1 $00F0 $2C
OR$A2
aA aA aB
& <F0>
$F1 $00F0 $2C aA + 09  iX
A2 OR 2C
IX $3100 . . ... IX $3100 . . ... aB + 09  iX
$3011 $31 $3011 $31
Memory

Memory

IY $1000 IYOR aB & <F0>


$1000 aB  $3011+$09
$3012 $00 01 OR 2C $3012 $00 aB  $3100+$09
SP ignore ...
SP ignore ...
. . . . . . aB  $3100+<$09>
ignore
OR ignore
aB & F0
PC
$301A $20 PC
$301A $20
01 OR F0
CCR H N Z V C $3109 $BE CCR H N Z V C $3109 $F1 $BE
address value address value
 2013, Professor A. Mason AMS Instruction Execution p.38
ECE
HC12 Compiler Directives 331

• Directive: command to compiler; makes coding easier


• HC12 ASM Directives (see HO_3)
EQU equates symbol with numeric valve
-use to define memory location or constant
-assembler replaces label with correct # value
EX: LIST EQU $5B
defines variable ‘LIST’ = $5B

ORG origin: set memory addr. of instructions/data


that follow
-all programs must specify their ORG
EX: TOP ORG $6000
sets program origin at $6000

END set end of program


-any ASM instructions following END are ignored
-can have directives after END

 2013, Professor A. Mason AMS Instruction Execution p.39

ECE
HC12 Compiler Directives 331

• Directive: command to compiler


• HC12 ASM Directives (see HO_3)
FCB form constant byte
-reserves block of memory & initiates contents
of reserved block
EX: ABC FCB $11, $12, $13
reserves 3 bytes w/ valves $11, $12 & $13 at
addr. assigned to label ABC

FDB form double-byte


-same as FCB but 2 bytes per operand
FCC form constant character
-stores ASCII code for alphanumeric characters enclosed in " " symbols
EX: NAME FCC “MIKE”
stores 4 ASCII bytes for MIKE
RMB reserve block of memory
EX: TEMP RMB $10
reserves 16 ($10) bytes starting at addr. assigned to label TEMP

 2013, Professor A. Mason AMS Instruction Execution p.40


ECE
Assembly Process 331
Assembly Process: The process of converting ASM code into executable
machine code.
• Input
– .ASM (text file)
• Outputs
– .LST
• compiled code
• program addresses & op-codes
– .S19 record
• HEX file that can be uploaded to C
to store program to memory
• Testing paths
– Simulator
– Test on hardware

 2013, Professor A. Mason AMS Instruction Execution p.41

ECE
Assembly Process Example 331

 2013, Professor A. Mason AMS Instruction Execution p.42

You might also like