Assembly Language Programming for the MC68HC11. Assembly language programming  Recall the 4 design levels for software development: – Application – High.

Slides:



Advertisements
Similar presentations
Lecture 6 Programming the TMS320C6x Family of DSPs.
Advertisements

EET 2261 Unit 3 Assembly Language; Load, Store, & Move Instructions  Read Almy, Chapters 5 and 6.  Homework #3 and Lab #3 due next week.  Quiz next.
Chapter 10- Instruction set architectures
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
The Assembly Language Level
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Chapter 3 Assembly Language: Part 1. Machine language program (in hex notation) from Chapter 2.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Railway Foundation Electronic, Electrical and Processor Engineering.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Railway Foundation Electronic, Electrical and Processor Engineering.
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.
© 2010 Kettering University, All rights reserved..
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Chapter 2 Software Tools and Assembly Language Syntax.
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
CPS120: Introduction to Computer Science
P.1ECE 331, Prof. A. Mason Professor Andrew Mason Michigan State University Spring 2013 ECE 331: PC Lab 1: Using HC12 ASM Simulators.
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
A Simple Two-Pass Assembler
1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h  Int 21 –A hexadecimal.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Machine Instruction Characteristics
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
1 4.2 MARIE This is the MARIE architecture shown graphically.
Programming With C.
Assemblers.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
1 Segments and Pseudo Operations Program Development.
Assembly Language ELEC 330 Digital Systems Engineering Dr. Ron Hayne.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
What is a program? A sequence of steps
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Computer Science 210 Computer Organization
PROGRAMMING THE BASIC COMPUTER
Machine dependent Assembler Features
Addressing Modes in Microprocessors
Chapter 7 Assembly Language
Assembly Language (continue)
ECE 3430 – Intro to Microcomputer Systems
Assembly Language Programming of 8085
Microprocessor Systems Design I
Wed. Sept 6 Announcements
Chapter 7 Assembly Language
Chapter 3 Machine Language and Assembly Language.
Chapter 3 Machine Language and Assembly Language.
INTRODUCTION ABOUT ASSEMBLY
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME4447/6405 Microprocessor Control of Manufacturing Systems and
Assembler CASE Tool.
Computer Science 210 Computer Organization
Chapter 7 Assembly Language
COMP2121: Microprocessors and Interfacing
Chapter 7 Assembly Language
A Simple Two-Pass Assembler
Chapter 7 Assembly Language
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Location Counter (LC) = 0 while line of code <> END if ORG
Presentation transcript:

Assembly Language Programming for the MC68HC11

Assembly language programming  Recall the 4 design levels for software development: – Application – High Level Language – Assembly – Machine code (often called object code)  Machine code programs are the only ones that can be directly executed on the processor -- programs in the higher 3 levels must be converted to machine code CONTD

Assembly language programming – High level language programs must be compiled » Synthesize an assembly-level intermediate form » Convert the intermediate form to machine code – Assembly language programs must be assembled » Translated into machine code » The synthesis part of compiling is not required » One-to-one translation of instructions

Assembly language programming  Assembly level programming – Advantages (over HLL programs) » Faster » Less memory » Enhanced control over the hardware – Disadvantages (vs. HLL programming) » Coding requires more "talent" » Life cycle support more difficult » Program tied to a specific HW platform --- Not portable

Overview of the AS11 assembler  Assembly language programs consist of 3 types of statements: » Instructions that will be executed by the microprocessor » Comments to document the program operation for humans » Assembler directives (pseudo-operations) that tell the assembler what to do CONTD

Overview of the AS11 assembler  Instructions: – Format is shown below: label operation operand ;comment – Labels » Optional » Must start in column 1 and begin with an alphabetic character » No more than 15 characters long » Delimit with a space or colon » May be on a line by itself

Overview of the AS11 assembler – Operation Operand » The instruction mnemonic from the instruction set followed by any needed operands » The opcode cannot start in column 1 of the source file » It a label is present, there must be at least one space or a colon between it and the opcode – Comments » Comments in an instruction line are delimited by a semicolon CONTD

Overview of the AS11 assembler » Everything to the right of a semicolon is treated as a comment (ignored by the assembler) » If a line starts with a semicolon or an asterisk in column 1, the entire line is treated as a comment » Use enough comments to explain program function -- not so many as to "flood" reader » Use meaningful comments; the following is not very useful LDDA #$FC ; load $FC into A

Overview of the AS11 assembler – Directives and pseudo-operations » These statements cause the assembler to perform certain actions -- they are converted directly to executable code » ORG xxxx  Place the next byte of the program at address $xxxx  The programmer uses this to place logical program groups into different memory areas CONTD

Overview of the AS11 assembler » EQU label EQU xxxx  The label is assigned the constant value xxxx  The programmer uses EQU to give meaningful names to constant numeric data – enhances code readability  Examples: TRUE: EQU 1 MAXINT EQU $FF

Overview of the AS11 assembler » Memory allocation  You should always allocate any memory locations that you use – Variables (RAM) – Constants (ROM/EEPROM) – Strings (ROM/EEPROM)  FCC ‘ASCII characters’ – Declare a string (Form Constant Characters) – Assembler converts characters to ASCII – Example: string1: FCC ‘This is string1.’

Overview of the AS11 assembler  FDB word,word,... – Declare 16-bit constants (Form Double Bytes) – Words may be constants, symbols, or expressions – If you have more than one word, they must be separated by commas, with no spaces between them – Example: Jump_Table: FDB $E000,$E010,$E020 CONTD

Overview of the AS11 assembler  FCB byte,byte,... – Declare 8-bit constants (Form Constant Bytes) – Bytes may be constants, symbols, or expressions – Separate bytes with commas, no paces between them – Example: sqr_tbl: FCB $0,$1,$4,$9,$10

Overview of the AS11 assembler  RMB size – Declare storage for variables (Reserve Memory Bytes) – Reserves size number of bytes (bytes are not initialized) – Size may be constant, symbol, or Expression – Example: Declare a 128-byte buffer at address $100 ORG $100 Buffer: RMB 128

Overview of the AS11 assembler » INCLUDE “filename” » INCLUDE  Include the specified file into the source code  Useful for initialization and definition of sections of code that are common across many programs  For example, I/O register names » Output control  PAGE  OPT option – Available options: l, nol, c, noc, contc, cre, s, crlf, nnf, p50

Overview of the AS11 assembler » Conditional assembly:  IFD symbol  IFND symbol  ELSE  ENDIF – Checks if the symbol has been defined or not defined – Each IFD or IFND must have a matching ENDIF – ELSE statements are optional CONTD

Overview of the AS11 assembler – IF/ELSE/ENDIF blocks may be nested – Format: IFD symbol ; code, more IFs, comments, etc. ELSE ; code, more IFs, comments, etc. ENDIF

Overview of the AS11 assembler  The assembly process – Most assemblers perform their job by making 2 “passes” over the source code – Pass 1 identifies all symbolic references to memory locations, and to the starting locations of all instructions » Symbol table is built during Pass 1 CONTD

Overview of the AS11 assembler Contains name and value for each symbol Symbols may be labels or they may be created with EQU directives – Pass 2 converts all symbolic references to absolute memory references and produces the final object code » Uses the symbol table information

Overview of the AS11 assembler Assembler first pass [Sho87]Assembler second pass [Sho87]

Overview of the AS11 assembler – Assembler outputs: » Object code: A specification of the actual bytes that will be placed in the HC11’s memory to be executed  On our systems, this is an ASCII file where binary code is represented as strings of hex equivalents – Motorola S-records format – Intel hex format CONTD

Overview of the AS11 assembler  Must be "loaded" into memory, at which time the ASCII-encoded hex digits are mapped to actual memory contents » Listing file: composite file giving both the source assembly code and the corresponding memory addresses and their contents  This file is particularly useful for debugging coding errors

Overview of the AS11 assembler  General Format of Listing File – address = Starting address in memory of the instruction – code = Hex digits that are the values put into the memory locations – source line no. = line number CONTD

Overview of the AS11 assembler – source line = assembly source code instruction – Other things that can be seen: Comments, cycle count, symbol table at the end of file, etc.  Example: 018A LDAA #$12 018C LDAA $34 018E B LDAA $5678

Overview of the AS11 assembler  Example: Write a program to find the minimum value in a list of unsigned integers. Assume that the starting address of the list is stored in memory location START, and the length of the list is stored in location LENGTH. Store the minimum value in memory location RESULT. CONTD

Overview of the AS11 assembler Pseudocode: Set min = MAX_INT; for each item in the list { if (list item < min) { min = list item } Store the min in RESULT

Overview of the AS11 assembler One implementation (in C): int *START; int LENGTH; int RESULT; int *ptr; int count; int min; min = MAX_INT; count = LENGTH; ptr = START; while (count != 0) { if (*ptr < min) { min = *ptr; } ptr++; count--; } RESULT = min;

Overview of the AS11 assembler ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Program: FIND_MIN -- Finds the minimum value of ; a list of unsigned integers. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAX_INT EQU $FF ; largest unsigned integer ORG $100 START RMB 2 ; starting address of list LENGTH RMB 1 ; length of list RESULT RMB 1 ; minimum value ORG $E000 FIND_MIN: CONTD

Overview of the AS11 assembler FIND_MIN: LDAA #MAX_INT ; ACCA = min = MAX_INT LDAB LENGTH ; ACCB = count = LENGTH LDX START ; IX = ptr = START ; LOOP: CMPA 0,X ; compare list item with min BLS END_LOOP ; branch if min <= list item LDAA 0,X ; else, update min END_LOOP: INX ; increment list pointer DECB ; decrement counter BNE LOOP ; and repeat if counter > 0 ; STAA RESULT ; store minimum value

Overview of the AS11 assembler

 Disassembly – Translate from object code/machine code back to source code – You usually lose symbols, labels, etc. – Example: (problem 12, chapt. 2 in text) E000 7F C CE CE E010 A A F CONTD

Overview of the AS11 assembler CLR $5000 INC $5000 LDX #$1000 LDY #$2000 LABEL: INX DEY LDAA 0,X STAA 0,Y LSL $5000 BCC LABEL – What does this program do ?

Overview of the AS11 assembler  Example: Exercise 13 from Chapt. 2 – Write a program to clear the first 20 bytes of RAM (set them to zero) » One solution: ORG $B600 LDX #$00 ; start with address $00 Loop: CLR $0,X ; clear the byte INX ; increment addr pointer CPX #20 ; addr < 20? BLO Loop ; branch if so

Overview of the AS11 assembler  Example: Exercise 13 from Chapt. 2 – A slightly different solution ORG $B600 LDX #19 ; s tart with end of block Loop: CLR $0,X ; clear the byte DEX ; decrement addr pointer BNE Loop ; branch if not done CLR $0,X ; why do we need this?

Overview of the AS11 assembler  Example : – Write a routine that will delay for a specified number of milliseconds. (The number of milliseconds will be stored in memory location DELAY_VALUE). Assume the system uses an 8 MHz crystal. The delay should be accurate to +/- 1%. » Remember that the E-clock, or system clock, is the internal clock frequency of the processor. CONTD

Overview of the AS11 assembler  E-clock = crystal frequency / 4 = 8 MHz / 4 = 2 MHz  Each clock period is therefore 0.5 µsec  1 ms = 2000 clock cycles  So, we need to write a routine that will  take 2000 clock cycles (+/- 20 cycles) to execute

Overview of the AS11 assembler  Solution(?): DELAY_VALUE RMB 1 DELAY: LDAA #LOOP_CNT ; 2 cycles LOOP: DECA ; 2 cycles BNE LOOP ; 3 cycles ; DEC DELAY_VALUE ; 6 cycles BNE DELAY ; 3 cycles – What value should we use for LOOP_CNT?

Overview of the AS11 assembler  Corrected solution: DELAY_VALUE RMB 1 DELAY: LDAA #LOOP_CNT ; 2 cycles LOOP: NOP ; 2 cycles DECA ; 2 cycles BNE LOOP ; 3 cycles ; DEC DELAY_VALUE ; 6 cycles BNE DELAY ; 3 cycles – Now what should LOOP_CNT be?