Lecture5 S14
Lecture5 S14
ADDRESSING MODES
EE 308 Spring 2014
ldx #table
not
ldx table
The following puts the first two bytes of table ($0C7A) into X. X
will not point to table:
ldaa 0,x
inx
or
ldaa 1,x+
EE 308 Spring 2014
1. Start with the org statement, which shows where the first byte of
the program will go into memory.
(e.g., org $2000 will put the first instruction at address $2000.)
4. Put in the object code for the instruction, and put in the
appropriate operand. Be careful to convert decimal operands to hex
operands if necessary. (e.g., ldab #10 becomes C6 0A.)
org $2000
ldab #10
loop: clra
dbne b,loop
swi
Freescale HC12-Assembler
(c) Copyright Freescale 1987-2010
MC9S12 Cycles
The program executes the ldab #10 instruction once. It then goes
through the loop 10 times (which has two instructions, one with
one cycle and one with three cycles), and finishes with the swi
instruction (which takes 9 cycles).
1 + 10 × (1 + 3) + 9 = 50
Assembler Directives
• T hese are not instructions which the HC12 executes but are
directives to the assembler program about such things as where to
put code and data into memory.
org $2000
table1: dc.b $23,$17,$f2,$a3,$56
table2: ds.b 5
var: dc.w $43af
Freescale HC12-Assembler
(c) Copyright Freescale 1987-2009
Abs. Rel. Loc Obj. code Source line
---- ---- ------ --------- ---------------------------
1 1 org $2000
2 2 a002000 2317 F2A3 table1: dc.b $23,$17,$f2,$a3,$56
002004 56
3 3 a002005 table2: ds.b 5
4 4 a00200A 43AF var: dc.w $43af
5 5
Note that table1 is a name with the value of $2000, the value of
the location counter defined in the org directive. Five bytes of data
are defined by the dc.b directive, so the location counter is
increased from $2000 to $2005.
EE 308 Spring 2014
Note that table2 is a name with the value of $2005. Five bytes of
data are set aside for table2 by the ds.b 5 directive. The as12
assembler initialized these five bytes of data to all zeros. var is a
name with the value of $200a, the first location after table2.
EE 308 Spring 2014
HC12 Instructions
• Logic Instructions
ANDA $2000 ; Logical AND of A with contents of
; $2000
EORB 2,X ; Exclusive OR B with contents of
; address (X+2)
• Interrupt instructions
SWI ; Initiate software interrupt
RTI ; Return from interrupt
EE 308 Spring 2014
10. Stop and Wait Instructions — put MC9S12 into low power
mode (S12CPUV2 Reference Manual, Section 5.27).
NOP ; No operation
BRN ; Branch never
EE 308 Spring 2014
ADDR DATA
---------------------------------------------------------
1000 C6 05 CE 20 00 E6 01 18 06 04 35 EE 3F
- If the first byte is $18, use Sheet 2 of Table A.2, and do the
same thing. For example, 18 06 is a two byte instruction, the
mnemonic is ABA, and it uses the INH addressing mode, so
there is no operand. Thus, the two bytes 18 06 is the op code
for the instruction ABA.
EE 308 Spring 2014