ECE 447: Lecture 9 - the GMU ECE Department

Download Report

Transcript ECE 447: Lecture 9 - the GMU ECE Department

ECE 447: Lecture 11
Introduction to
Programming in
Assembly Language
ECE 447: Levels of Software
High-level language
(C, C++, Pascal)
compiler
Assembly language (68HC11, 8051, Z80)
assembler
Object code
linker
Machine language
ECE 447: Levels of Software
C
Pascal
Pseudocode
68HC11
8051
compiler
Z80
assembler
Object
code
Object
code
Object
code
linker
Machine
language
Machine
language
Machine
language
ECE 447: Features of Assembly Language
1. Very hardware dependent
2. Not very portable (if at all)
3. Very detailed (responsible for all register contents)
4. No inherent data types
5. Requires programming discipline
6. Difficult to document
7. Access to all hardware intricacies of the chip
8. Fastest execution
9. Small memory usage
ECE 447: Register Structure of 68HC11
7
15
A
0
7
B
D
0
Accumulators A and B or
Double Accumulator D
0
15
IX
0
X-index register
15
IY
0
Y-index register
15
SP
0
Stack Pointer
15
PC
0
Program Counter
0
Condition Code Register
7
CCR
SXHINZVC
ECE447: Condition Code Register
7
CCR
0
SXHINZVC
carry / borrow
overflow
zero
negative
I-interrupt mask
half-carry (from bit 3)
X-interrupt mask
stop disable
ECE447: Condition Indicators (Flags)
• ( C ) Carry/Borrow – indicates going out of range for
arithmetic operations on unsigned numbers
(set if the ALU performed a carry or borrow during the
last arithmetic operation)
• ( V ) Overflow – indicates going out of range for
arithmetic operations on signed numbers
• ( Z ) Zero – set if the last operation result is zero
• ( N ) Negative – set if the last operation result is
negative (MSB = 1)
• ( H ) Half Carry – set when a carry occurs between bits
3 and 4 during an ADD, ABA, or ADC instruction
ECE 447: Constants in C and
Assembly Language
C
decimal
hexadecimal
binary
octal
character
23
0xf9
—
067
’w’
Assembly language
23
or
23D
$f9
or
0f9H
%10111111 or 10111111B
@67 or
67O
’w’
Special constants
‘\n’ - new line
‘\t’ - horizontal tab
‘\a’ - alert (bell)
$0A
$09
$07
ECE 447: Assembly Language vs.
Machine Code
Assembly language
[label]
mnemonic
START
CLRA
[operands]
LDAA
#$4A
LDAA
$5B, Y
opcode
[operands]
Machine code
[prebyte]
$4F
$18
$86
$4A
$A6
$5B
ECE 447: Machine Code Instructions
of 68HC11
Number of instructions represented using
a single-byte opcode
236
Number of instructions represented using
a combination prebyte+opcode
76
Values of prebytes
18, 1A, CD
ECE 447: Groups of Instructions (1)
1. Data handling instructions
a. Move instructions
(e.g., load, store, exchange)
b. Alter data instructions
(e.g., clear, increment, decrement)
c. Edit instructions
(e.g., shift, rotate)
2. Arithmetic instructions
(e.g., add, subtract, multiply, divide, negate)
3. Logic instructions
(e.g., and, or, xor)
ECE 447: Groups of Instructions (2)
4. Data test instructions
(e.g. compare, test, bit test)
5. Control instructions
(e.g., jump, branch)
6. Condition code instructions
(e.g., set carry, clear overflow flag)
7. Stack operations
(e.g. push, pull)
ECE 447: Groups of Instructions (3)
8. Subroutine-related instructions
(e.g. jump to subroutine, return from subroutine)
9. Interrupt-related instructions
(e.g. software interrupt, return from interrupt,
wait for interrupt)
10. Miscellaneous instructions
(e.g. no operation, stop)
ECE 447: Addressing Modes of 68HC11
1. Inherent:
Opcode itself contains a reference
to the location of the operand
2. Immediate:
Operand (data) follows the opcode.
3. Extended:
Complete address of the operand
follows the opcode.
4. “Direct”:
Low byte of the operand’s address
follows the opcode.
High byte of the operand’s address
set to zero.
The operand resides in the Base page
(Page 0) = first 256 bytes of memory space
ECE 447: Addressing Modes of 68HC11
5. Indexed
Contents of X or Y index register
added to an unsigned offset provided in the
byte following the opcode to form
effective address
6. Relative
signed byte following the opcode
added to the pre-incremented
program counter PC to form effective
address
ECE 447: Addressing Modes of the
LDAA Instruction
Immediate mode
LDAA #$5C
$5C  A
Extended mode
LDAA $6D00
($6D00)  A
Direct mode
LDAA
$1B
($001B)  A
Indexed mode
LDAA $56, X
LDAA $56, Y
(IX+$56)  A
(IY+$56)  A
ECE 447: Notation
$5C  A
Number $5C loaded to the Accumulator A
($6D00)  A
Contents of the memory location at the address $6D00
loaded to the Accumulator A
ECE 447: Move Instructions
1. memory  register
LDA [A, B]
LD [D, X, Y, S]
N Z V C
IMM, DIR, EXT, IND
0 –
2. register  memory
STA [A, B]
ST [D, X, Y, S]
DIR, EXT, IND
0 –
3. register  register
TAB, TBA
4. memory  memory
INH
0 –
ECE 447: Move Instructions
N Z V C
1. register  register
XGD [X, Y]
INH
– – – –