Cross Assembly and Program Development

Similar documents
EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Programming the Motorola MC68HC11 Microcontroller

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

ME 6405 Introduction to Mechatronics

Mark II Aiken Relay Calculator

Using the stack and the stack pointer

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

538 Lecture Notes Week 3

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Introduction to Microcontrollers

Exam I Review February 2017

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

Module 1-G. Marcos and Structured Programming

Menu Computer Organization Programming Model for the an example microprocessors (the G-CPU & Motorola 68HC11) Assembly Programming Look into my...

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

Macro Assembler. Defini3on from h6p://

CMPEN 472 Sample EXAM II

MC9S12 Address Space

1. Memory Mapped Systems 2. Adding Unsigned Numbers

TEMPERATURE SENSOR. Revision Class. Instructor / Professor LICENSE

0b) [2] Can you name 2 people form technical support services (stockroom)?

An ability to program a microcontroller to perform various tasks

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

Introduction to the 9S12 Microcontroller

Lab 7: Asynchronous Serial I/O

Exam 2 E2-1 Fall Name: Exam 2

538 Lecture Notes Week 5

538 Lecture Notes Week 5

COE538 Lecture Notes Week 3 (Week of Sept 17, 2012)

EE 3170 Microcontroller Applications

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

EE319 K Lecture 7. Address mode review Assembler, Debugging Psuedo ops 16 bit timer finite state machines. University of Texas ECE

Coe538 Final Study Guide 2016 (Questions & Answers)

Lecture 9 Subroutines

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

ECE 331: PC Lab 3 Stack and Subroutines

Introduction to Programming

; export symbols ; export 'Entry' symbol. ; include derivative specific macros PORTA EQU $0000 PORTB EQU $0001 DDRA EQU $0002 DDRB EQU $0003

Wed. Sept 6 Announcements

CET335 Microprocessor Interfacing Lab 5: LCD Interface (Bus Attached Peripheral)

NAM M6800 DISK-BUG DS VER 3.5 OPT PAG

COSC 243. Instruction Sets And Addressing Modes. Lecture 7&8 Instruction Sets and Addressing Modes. COSC 243 (Computer Architecture)

C SC 230 Computer Architecture and Assembly Language April 2000 Exam Sample Solutions

UNIVERSITY OF MANITOBA DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING. Term Test #2 Solution ECE 3610 MICROPROCESSING SYSTEMS

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3. You will be able to use all of the Motorola data manuals on the exam.

What is an Addressing Mode?

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Exam 1 Feb. 23, 25, 27?

; export symbols XDEF Entry ; export 'Entry' symbol ABSENTRY Entry ; for assembly entry point

History of the Microprocessor. ECE/CS 5780/6780: Embedded System Design. Microcontrollers. First Microprocessors. MC9S12C32 Block Diagram

ELEG3924 Microprocessor

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

Sample Problem Set #1

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Assembly Language programming (1)

Homework 12 Solutions

HC11 Instruction Set

Outline. 2.8 Stack. 2.9 Subroutines

538 Lecture Notes Week 3

Introduction to Microcontrollers III

Lecture 6 Assembly Programming: Branch & Iteration

Lecture 5 Assembly Programming: Arithmetic

Chapter 2 HCS12 Assembly Language

SECTION 6 CENTRAL PROCESSING UNIT

538 Lecture Notes Week 2

EE4390 Microprocessors

POTENTIOMETER. Revision Class. Instructor / Professor LICENSE

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Total: EEL 3701 Digital Logic & Computer Systems Final Exam Fall Semester 2007 COVER SHEET: Re-Grade Information: 1 (10) 2 (10) 3 (10) 4 (14) 5 (14)

Programming Book for 6809 Microprocessor Kit

COSC345 Software Engineering. Basic Computer Architecture and The Stack

HC11 Instruction Set Architecture

HC11 Instruction Set Architecture

Most of the HC12 s instructions access data in memory There are several ways for the HC12 to determine which address to access

Program Development. Chapter 5

CHAPTER 8. Solutions for Exercises

Introduction to Microcontrollers III

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

EE 308 Spring The HCS12 has 6 addressing modes

538 Lecture Notes Week 1

Timing Generation and Measurements

ECE 3610 MICROPROCESSING SYSTEMS AN ENCRYPTED ASCII CODE DECODER

ECE 372 Microcontroller Design Assembly Programming Arrays. ECE 372 Microcontroller Design Assembly Programming Arrays

ORG ; TWO. Assembly Language Programming

AN Kbyte Addressing with the M68HC11. Overview

NAME asm cross-assembler SYNOPSIS

8051 Microcontrollers

CPU. IBM PC and compatible Memory Structure

Small Computer Monitor User Guide

A Simple MC9S12 Program

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

Run time environment of a MIPS program

Ethical Hacking. Assembly Language Tutorial

ECE3120: Computer Systems Hardware & Software Development Tools

Transcription:

Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 1 Introduction Text Editor Program Ex. DOS, Notepad, Word saved as ASCII Source Code Assembler or Cross-Assembler Object Code Machine code + other information Listing file - Linker Hex File Linker combines one or more object file to generate hex file Loader Binary File Executable Form ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 2

Introduction Cross-assembler runs on a system using one type of computer and it assembles the source code for a different processor Motorola AS11 Cross-Assembler runs on an Intel 80x86 based operating system => produces object code for Motorola 68HC11 ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 3 Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 4

Format and Source Code The source code must follow very definite rules in order for an assembler to assemble it properly Each line of source code is organized into fields (or columns) Label Operation Operand Comments Identifier Must begin in the first column Other fields may start in any other column Opcode (mnemonic) or Pseudo-op Identifies the data or an address comment starting in column 1 must start with an * otherwise with ; ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 5 Format and Source Code * FILE list4a.asm * demo source file * ---------------------------------------------------------- * MAXIMUM UNSIGNED BYTE * Find the largest unsigned byte in a block of data * * DATA STRUCTURE * MAXRESULT Address where result is stored * COUNT Address that contains number of * bytes in data block * FIRST Address of first element in block * * ALGORITHM * 1. Get COUNT * 2. Set MAX = 0, the current maximum * 3. Compare each element to MAX * If element > MAX then MAX = element * Else MAX unchanged * 4. Repeat step 3 for all elements * 5. Put result, MAX into MAXRESULT * ======================================== ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 6

Format and Source Code * Define data and segment addresses PAGE0 EQU 0 STACK EQU $FF PROGSEG EQU $0100 * -------------------------------------------------- * start data segment * want page0 RAM to force direct addressing mode * whenever possible ORG PAGE0 RAM RMB 4 MAXRESULT RMB 1 COUNT RMB 1 * for convenience of testing, predefine some RAM data FIRST FCB $5C,$67,$00,$31,$B3,$A5,$20,$80 FCB $88,$3C,$91,$91,$43,$CE,$34,$01 * end data segment ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 7 Format and Source Code * ---------------------------------------------------------- * Program Segment * ---------------------------------------------------------- ORG PROGSEG LDS #STACK;initialize start of stack LDAB COUNT ;get count CLRA ;maximum=zero(min. possible) LDX #FIRST ;point to first entry in block MAXM CMPA 0,X ;is current maximum greater * ;than current entry? BCC NOCHG ;if yes, keep maximum LDAA 0,X ;else replace with current entry NOCHG INX ;point to next entry DECB ;all entries checked? BNE MAXM STAA MAXRESULT ;save maximum LDX #MAXRESULT-2 TAB ;set up calling registers JSR UNPACK ;unpack result HERE BRA HERE ;stop program ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 8

Format and Source Code * ---------------------------------------------- * Subroutine UNPACK (Same as Listing 3.5) * Converts a byte into two single-hex-digit bytes (MSD=0) * Stores the unpacked result in 2 bytes in RAM * Calling Registers * ACCB = data byte to be unpacked * IX = address to store unpacked result (MSD first) * Return Registers * All registers unaffected UNPACK PSHA ;store ACCA TPA ;store CCR PSHA TBA ;shift upper digit into lower nibble LSRA LSRA LSRA LSRA STAA 0,X ;and store it TBA ;next, ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 9 Format and Source Code INX ;work on lower digit STAA 0,X ;first store both digits BCLR 0,X $F0 ;then remove upper digit DEX ;restore IX PULA ;restore CCR TAP PULA ;restore ACCA RTS ;return to calling routine * end of program segment * -------------------------------------------------------- END ;(optional) end of source code, * ;assembler will not assemble * ;anything AFTER this point. * -------------------------------------------------------- ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 10

Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 11 Code and Data Segments The source code can be organized into blocks called segments Should have separate segments for code, data and special areas such as vectors, look-up tables, subroutine codes, and the stack AS11 has no segments the assembler does the linker s job Memory Type RAM EEPROM ROM Page 0 Calibration Table Application Program Utility Subroutine Interrupt and Reset Handler Routine Vectors Reserved Data Initial SP ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 12

Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 13 Pseudo-Operations Pseudo-operation tells the assembler what to do Examples of pseudo operations from AS11 RMB reserve memory bytes FCB form constant byte FDB form double byte FCC form constant characters Fill, BSZ, and ZMB these are directives to define a block of bytes to Other cross-assembler pseudo-ops ORG DB define byte DW define word EQU equal DS define space ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 14

* Listing 4.2 * Sample data segment to demonstrate data definition * pseudo-ops * * start data segment * ---------------------------------------------------------- DATASEG EQU $C000 ORG DATASEG * assigning values to symbols, can use decimal, hex or ASCII STACK EQU $FF NUM1 EQU 55 NUM2 EQU $55 NUM3 EQU 'U' * RESULT STACK=$FF, NUM1=$37, NUM2=$55, * NUM3=$55, ASCII code for 'U' * RMB reserves uninitialized bytes of space BEGINS RMB 4 ;assigned to address $C000 RESULTRMB 1 ;assigned to address $C004 COUNT RMB 1 ;assigned to address $C005 ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 15 * FCB defines 8-bit quantities * can use decimal, hex, or ASCII BEGIN FCB 50,$50,'5' FCB 76,$76 * RESULT BEGIN assigned to address $C006 * hex code C006 32 50 35 4C 76 ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 16

* FCC (Form Constant Characters) can define a string * a string is a sequence of bytes representing ASCII * characters STRING FCC "Hello my friend" CR EQU $0D LF EQU $0A FCB CR, LF * add carriage return (CR) and line feed (LF) to string * RESULT STRING assigned to address $C00B * hex code C00B 48 65 6C 6C * C00F 6F 20 6D 79 * C013 20 66 72 69 * C017 65 6E 64 0D * C01B 0A ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 17 * FDB defines 16-bit quantities FDB FDB FDB $6,6,$54C3,'x' 'y' 'z' * RESULT * hex code C01C 00 06 00 06 * C020 54 C3 00 78 * C024 00 79 00 7A * demonstrate prefix convention HEXP FCB $FB ; hex DECP FCB 251 ; decimal OCTP FCB @373 ; octal BINP FCB %11111011 ; binary * RESULT * hex code C028 FB FB FB FB ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 18

* demonstrate signed numbers and arithmetic FCB $FB UNSGN FCB 251 SGN FCB -5 ADD1 FCB 248+3 SUB1 FCB 254-3 * RESULT * hex code C02C FB FB FB FB FB * use labels or symbols as operands FCB NUM2 ;a symbol FDB STRING ;a label * RESULT note that label STRING was assigned address $C00B * hex code C031 55 C0 0B * end of data segment * ----------------------------------------------- ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 19 Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 20

The Assembly Two-Pass Process Pass 1: starts with the source code Assembler fills in all known address and hex code information line by li leaves spaces for any unknown information collects all possible information Pass 2: starts with the source code fills in the missing information left behind after the firs pass During the assembly process the assembler use a location counter to point to the line on which it is working ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 21 Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 22

Assembler Options and Preprocessor Directives Avocet assembler options and preprocessor directives Options must begin in column 1 with a $ sign must occur at the beginning of the source code Preprocessor directives follow the assembler options must begin with a % tell the assembler to do something before beginning the assembly process ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 23 ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 24

ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 25 ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 26

ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 27 Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 28

Hex and Binary Files Linkers produce a hex file Hex files have standard formats Motorola S-record Intel hex Applications are first developed and tested using evaluation boards Motorola hex file => EVBU board The EVBU board has a built-in program in ROM that converts the hex file to binary After the application is tested it can be written in the ROM by the semiconductor manufacturer ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 29 Hex and Binary Files Data records S1 Two-character data byte count (Number of data bytes plus three) Four-character load address Data byte characters Two-character checksum Carriage return Linefeed The end record S9 Count, 03 Four-character start address Two-character checksum Carriage return Linefeed ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 30

Hex and Binary Files Intel Hex Format Data records : Two-character data byte count Four-character load address Record type, 00 Data byte characters Two-character checksum Carriage return Linefeed The end record : Two character count Four-character start address Record type, 01 Two-character checksum Carriage return Linefeed ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 31 Hex and Binary Files Checksum technique used by the hex files can detect errors but cannot correct them Motorola hex format checksum one s complement of the 8-bit sum of the data bytes, byte count, and address bytes Intel hex format checksum two s complement of the 8-bit sum of all the data bytes, byte count, record type, and address bytes ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 32

Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 33 Documentation Files Listing file Cycle count Symbol listing ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 34

Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 35 Simulation Instead of running a program in the actual 68HC11 CPU you can run it using a computer simulator that simulates the CPU With simulation you can freely modify your program, modify registers, modify data and set breakpoints A simulator usually shows the information more conveniently and allows easier access to registers and memory for modification ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 36

Cross Assembly and ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 37 Evaluation Boards and Emulation ENGG4640/3640; Fall 2004; Prepared by Radu Muresan 38