Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 447: Lecture 11 Introduction to Programming in Assembly Language.

Similar presentations


Presentation on theme: "ECE 447: Lecture 11 Introduction to Programming in Assembly Language."— Presentation transcript:

1 ECE 447: Lecture 11 Introduction to Programming in Assembly Language

2 ECE 447: Levels of Software High-level language (C, C++, Pascal) Assembly language (68HC11, 8051, Z80) Machine language assembler compiler linker Object code

3 ECE 447: Levels of Software C Pascal Pseudocode 68HC118051Z80 Object code compiler assembler Machine language Object code Machine language Object code Machine language linker

4 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

5 ECE 447: Register Structure of 68HC11 X-index register Y-index register Stack Pointer Program Counter Condition Code Register Double Accumulator D Accumulators A and B or IX 0 15 IY 0 15 SP 0 15 PC 0 15 CCR 07 D 0 15 7700 AB S X H I N Z V C

6 ECE447: Condition Code Register CCR 0 7 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

7 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

8 ECE 447: Constants in C and Assembly Language CAssembly language decimal23 23or 23D hexadecimal0xf9$f9 or 0f9H binary— %10111111 or 10111111B octal067@67or 67O character ’w’ ’w’ Special constants ‘\n’ - new line ‘\t’ - horizontal tab ‘\a’ - alert (bell) $0A $09 $07

9 ECE 447: Assembly Language vs. Machine Code Assembly language [label] mnemonic [operands] LDAA #$4A LDAA $5B, Y Machine code $86 $4A [prebyte] opcode [operands] $18 $A6 $5B START CLRA $4F

10 ECE 447: Machine Code Instructions of 68HC11 Number of instructions represented using a single-byte opcode Number of instructions represented using a combination prebyte+opcode 76 236 Values of prebytes 18, 1A, CD

11 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)

12 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)

13 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)

14 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

15 ECE 447: Addressing Modes of 68HC11 5. IndexedContents 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

16 ECE 447: Addressing Modes of the LDAA Instruction Immediate mode LDAA #$5C Extended mode LDAA $6D00 Indexed mode LDAA $56, X LDAA $56, Y $5C  A ($6D00)  A (IX+$56)  A (IY+$56)  A Direct mode LDAA $1B ($001B)  A

17 ECE 447: Notation $5C  A ($6D00)  A Number $5C loaded to the Accumulator A Contents of the memory location at the address $6D00 loaded to the Accumulator A

18 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 DIR, EXT, IND INH N Z V C 0 –

19 ECE 447: Move Instructions 1. register  register XGD [X, Y] N Z V C – – INH


Download ppt "ECE 447: Lecture 11 Introduction to Programming in Assembly Language."

Similar presentations


Ads by Google