190 likes | 403 Views
ECE 447: Lecture 11. Introduction to Programming in Assembly Language. 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. compiler. Pseudocode. 68HC11.
E N D
ECE 447: Lecture 11 Introduction to Programming inAssembly Language
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 compiler Pseudocode 68HC11 8051 Z80 assembler Object code Object code Object code linker Machine language Machine language Machine language ECE 447: Levels of Software
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 Accumulators A and B or 7 0 7 0 A B Double Accumulator D D 0 15 X-index register IX 0 15 Y-index register IY 0 15 Stack Pointer SP 0 15 Program Counter PC 0 15 Condition Code Register 7 0 CCR S X H I N Z V C
ECE447: Condition Code Register 7 CCR 0 S X H I N Z V C 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 Assembly language decimal 23 23 or 23D hexadecimal 0xf9 $f9 or 0f9H binary — %10111111 or 10111111B octal 067 @67 or 67O character ’w’ ’w’ Special constants $0A $09 $07 ‘\n’ - new line ‘\t’ - horizontal tab ‘\a’ - alert (bell)
ECE 447: Assembly Language vs. Machine Code Assembly language [label] mnemonic [operands] START CLRA LDAA #$4A LDAA $5B, Y Machine code [prebyte] opcode [operands] $4F $86 $4A $18 $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 • 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. Relativesigned 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 $5C A LDAA #$5C Extended mode ($6D00) A LDAA $6D00 Direct mode ($001B) A LDAA $1B Indexed mode (IX+$56) A LDAA $56, X LDAA $56, Y (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 N Z V C 1. memory register LDA [A, B] LD [D, X, Y, S] 2. register memory STA [A, B] ST [D, X, Y, S] 3. register register TAB, TBA 4. memory memory 0 – IMM, DIR, EXT, IND 0 – DIR, EXT, IND 0 – INH
ECE 447: Move Instructions N Z V C 1. register register XGD [X, Y] – – – – INH