Page 1
MCO556
- 1 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 1
MCO556
Assembly Language
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 2
MCO556
- 2 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 2
2
Programming Model
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 3
MCO556
- 3 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 3
3
HCS12 Instructions
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 4
MCO556
- 4 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 4
4
Addressing Modes
• Inherent - no operands
• Immediate - operand is in the program
• Direct - operand in first 256 bytes
• Extended - operand anywhere in memory
• Relative - branch instructions only
• Index - sum of index register and offset
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 5
MCO556
- 5 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 5
5
Index Addressing
• 5 bit Constant offset
• 9 bit Constant offset
• 16 bit Constant offset
• 16 bit Constant Indirect
• Auto Post/Pre De/Increment
• Accumulator Offset
• Accumulator D Indirect
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 6
MCO556
- 6 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 6
6
5 bit Constant Offset Indexed
Base index register X, Y, SP or PC.
Range of the offset -16 to +15.
Example:
Load Acc A with contents held at address X + 0
ldaa 0,X
Store contents of Acc B to address held in Y - 10
stab -8,Y
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 7
MCO556
- 7 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 7
7
9 bit Constant Offset Indexed
Base index register X, Y, SP or PC.
Range of the offset -256 to +255.
Example:
Load Acc A with contents held at address X + 255
ldaa $FF,X
Store contents of Acc B to address held in Y - 20
ldab -20,Y
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 8
MCO556
- 8 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 8
8
16 bit Constant Offset Indexed
Base index register X, Y, SP or PC.
Access to any location in 64Kbyte range.
Example:
Load Acc A with contents held at address X + 2000
ldaa 2000,X
Store contents of Acc B to address held in Y + 4000
staa 4000,Y
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 9
MCO556
- 9 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 9
9
Auto Pre/Post De/Increment Indexed
Base index register X, Y, or SP.Index register incremented or decrementedIndexing before or after index register is changedIndex change -8 to -1 or +1 to +8
Example:Decrement SP by 1 and save Acc A at addressstaa 1,-SP
Load Reg X with contents held at SP and advance SP by 2 locations ldx 2,SP+
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 10
MCO556
- 10 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 10
10
Accumulator Offset Indexed
Address sum of accumulator and base index
Base index register X, Y, SP or PC.
Accumulator A, B, D(16 bit)
Example:
Load Acc A with contents held at address X + B
ldaa B,X
Store contents of Acc B to address held in Y + B
stab B,Y
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 11
MCO556
- 11 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 11
11
16 bit Constant Indirect Indexed
Base index register X, Y, SP or PC.
Index plus offset is address of memory which is the effective address
Store contents of Acc A to address (2345 – 4) held in Y
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 12
MCO556
- 12 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 12
12
Accumulator D Indirect Indexed
Base index register X, Y, SP or PC.
Index plus Acc D is address of memory which is the effective address
Store contents of Reg X to address (2345 + 4) sum of D and Y
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 13
MCO556
- 13 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 13
13
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 14
MCO556
- 14 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 14
14
Fields of a HCS12 InstructionLabel
• starts with letter and followed by letters, digits, or special symbols (_ or .)
• start from any column if ended with “:”
• start from column 1 if not ended with “:”
Opcode
• contains the mnemonic of a machine instruction or an assembler directive
• is separated from the label by at least one space
Operand
• follows opcode and is separated from opcode by at least one space
• operands for instructions or arguments for assembler directives
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 15
MCO556
- 15 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 15
15
Instruction Fields
loop ADDA #$40 ; add 40 to accumulator A
(1) “loop” is a label
(2) “ADDA” is an instruction mnemonic
(3) “#$40” is the operand
(4) “add 40 to accumulator A” is a comment
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 16
MCO556
- 16 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 16
16
Assembly Directives
• define data and symbol
• reserve and initialize memory locations
• set assembler and linking condition
• specify output format
• Specifies the end of a program.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 17
MCO556
- 17 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 17
17
Assembler Directives
END - ends a program
ORG - sets new value for location counter
ORG $1000
LDAB #$FF
db (define byte)
dc.b (define constant byte)
fcb (form constant byte)
org $800
array db $11,$22,$33,$44
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 18
MCO556
- 18 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 18
18
Assembler Directivesdw (define word)
dc.w (define constant word)
fdb (form double bytes)
vec_tab dw $1234, $5678
fcc (form constant character)
msg fcc “Please enter 1, 2 or 3:”
ds.w (define storage word)
rmw (reserve memory word)
dbuf ds.w 20
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
Page 19
MCO556
- 19 – Seneca College – School of Information and Communications Technology G VandeBelt 113
Slide 19
19
Assembler Directives
equ (equate)
loop1_cnt equ 100
loop2_cnt equ 50
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________