190 likes | 368 Views
ECE 447: Lecture 13. Introduction to Assembly. High-level language (C, C++, Pascal). compiler. Assembly language (68HC11, 8051, Z80). assembler. Object code. linker. Machine language. ECE447: Levels of Software. C. Pascal. compiler. Pseudocode. 68HC11. 8051. Z80. assembler.
E N D
ECE 447: Lecture 13 Introduction to Assembly
High-level language (C, C++, Pascal) compiler Assembly language (68HC11, 8051, Z80) assembler Object code linker Machine language ECE447: Levels of Software
C Pascal compiler Pseudocode 68HC11 8051 Z80 assembler Object code Object code Object code linker Machine language Machine language Machine language ECE447: Levels of Software
ECE 447: Characteristics of Assembly 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. Less memory
ECE 447:Register Structure of MC68HC11 Accumulators A and B or A B 7 0 7 0 D Double Accumulator 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 CCR 7 0 S X H I N Z V C
ECE 447: Condition Code Register CCR 7 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
ECE 447: CCR - Condition Indicators • ( C ) Carry/Borrow – set if the ALU performs a carry or borrow during operation • ( V ) Overflow – set if operation causes an overflow, cleared o/w • ( Z ) Zero – set if the operation result is zero • ( N )Negative – set if the 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: 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 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: Instruction Types 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) 4. Data test instructions (e.g. compare, test, bit test)
ECE 447: Instruction Types (con’t) 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) 8. Subroutine-related instructions (e.g. jump to subroutine, return from subroutine) 9. Interrupt-related instructions (e.g. software interrupt, return from interrupt)
ECE 447: Addressing Modes of 68HC11 1. Inherent: Opcode contains reference. 2. Immediate: Data follows opcode. 3. “Direct”: Base page, Page 0; Low byte of address follows opcode. High byte of address set to zero. 4. Extended: Complete address of the operand follows the opcode. Like Direct but you can specify High byte of address.
ECE 447: Addressing Modes of 68HC11 5. Indexed Contents of X or Y index register added to the unsigned offset 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 68HC11 LDAA example Immediate mode $5C A LDAA #$5C Direct mode ($001B) A LDAA $1B Extended mode ($6D00) A LDAA $6D00 Indexed mode (IX+$56) A LDAA $56, X LDAA $56, Y (IY+$56) A
ECE 447: Move Instructions 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 IMM, DIR, EXT, IND 0 – 0 – DIR, EXT, IND 0 – INH
ECE 447: Move Instructions N Z V C 5. register register XGD [X, Y] – – – – INH
ECE 447: Class Exercise #1 Write a function in assembly language of 68HC11 that transfers 512 bytes of data starting at address 0000H to the block of memory starting at address 4000H.
ECE 447: Class Exercise #2 Write a function in assembly language of 68HC11 that continuously transfers data from PORT E to PORT C of MC68HC11.
ECE 447: Class Exercise #3 Write a function in assembly language of 68HC11 that detects a falling edge of the signal driving pin PD5 of MC68H11. When the falling edge is detected, the microcontroller should set the pin PC4 and toggle the pin of PC2 of MC68HC11.