MC9S12 Address Space

Similar documents
Introduction to the 9S12 Microcontroller

A Simple MC9S12 Program

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Lab 1 MC9S12 Assembler and Monitor

N bit is set if result of operation in negative (MSB = 1) Z bit is set if result of operation is zero (All bits = 0)

Lab 1 MC9S12 Assembler and Monitor

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.

Mark II Aiken Relay Calculator

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

HC11 Instruction Set

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

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

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

PRINCETON (VON NEUMAN) ARCHITECTURE MICROPROCESSOR

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

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

EE 308 LAB 1 ASSEMBLER, SIMULATOR, AND MONITOR. Introduction and Objectives

Introduction to 6811 Programming


Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

1. Memory Mapped Systems 2. Adding Unsigned Numbers

Exam I Review February 2017

Exam 1 Feb. 23, 25, 27?

Cross Assembly and Program Development

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

EE 308 Spring Lecture 28 March 30, 2012 Review for Exam 2. Introduction to the MC9S12 Expanded Mode

CHAPTER 8. Solutions for Exercises

Introduction to Embedded Systems and Chapter 1: Introduction to HCS12/MC9S12. EE383: Introduction to Embedded Systems University of Kentucky

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

The 9S12 in Expanded Mode - Using MSI logic to build ports Huang Chapter 14

Comparison of C and Assembly How to compile a C program using CodeWarrior

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

Lecture 5 Assembly Programming: Arithmetic

EE 308 Spring Lab on IIC Bus

Introduction to Microcontrollers

Introduction to CPU architecture using the M6800 microprocessor

ELEG3924 Microprocessor

Accumulator and memory instructions 1. Loads, stores, and transfers 2. Arithmetic operations 3. Multiply and divide 4. Logical operations 5. Data test

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

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

It translates (converts) assembly language to machine code.

Comparison of C and Assembly How to compile a C program using CodeWarrior

Microcontrollers. Microcontroller

Lecture 11: Advanced Arithmetic Instructions

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

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

Lecture 7 Assembly Programming: Shift & Logical

HC11 Instruction Set Architecture

Programming the Motorola MC68HC11 Microcontroller

HC11 Instruction Set Architecture

EE 3170 Microcontroller Applications

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

538 Lecture Notes Week 2

Lecture 6 Assembly Programming: Branch & Iteration

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

Using the MC9S12 in Expanded Mode External Ports S12CPUV2 Reference Manual Multiplexed External Bus Interface (MEBI) Module V3 Block User Guide

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Reference Guide For SRecCvt

1. Introduction to Assembly Language

Chapter 7 Central Processor Unit (S08CPUV2)

Computer Organization I. Lecture 28: Architecture of M68HC11

Using the stack and the stack pointer

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

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2

Microcontrollers and the Freescale/Motorola HC11

CS/ECE 5780/6780: Embedded System Design

538 Lecture Notes Week 3

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

COE538 Microprocessor Systems Lab 1: Using the CodeWarrior IDE and Introduction to Assembly Programming 1

Lab 4: Arithmetic Logic Unit (ALU)

8051 Microcontrollers

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

68000 Assembler by Paul McKee. User's Manual

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

EE251: Thursday November 15

Introduction to Programming

Lab 2 Part 3 Assembly Language Programming and 9S12 Ports

Introduction to the MC9S12 Hardware Subsystems

Microprocessors/Microcontrollers

ECE 4510/5530 Microcontroller Applications Chapter 1

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

Introduction to Computers - Chapter 4

Interrupt vectors for the 68HC912B32. The interrupt vectors for the MC9S12DP256 are located in memory from 0xFF80 to 0xFFFF.

ECET Chapter 2, Part 3 of 3

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

Solutions - Homework 2 (Due date: October 4 5:30 pm) Presentation and clarity are very important! Show your procedure!

EMCH 367 Fundamentals of Microcontrollers Example7 EXAMPLE 7

Tutorial 1 Microcomputer Fundamentals

Integer Representation

ECE 3120 Lab 1 Code Entry, Assembly, and Execution

ME 515 Mechatronics. A microprocessor

Lecture 9 Subroutines

538 Lecture Notes Week 5

538 Lecture Notes Week 5

C Language Programming, Interrupts and Timer Hardware

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

ECE 372 Microcontroller Design Basic Assembly Programming. ECE 372 Microcontroller Design Basic Assembly Programming

Transcription:

MC9S12 Address Space MC9S12 has 16 address lines MC9S12 can address 2 16 distinct locations For MC9S12, each location holds one byte (eight bits) MC9S12 can address 2 16 bytes 2 16 = 65536 2 16 = 2 6 2 10 = 64 1024 = 64 KB (1K = 2 10 = 1024) MC9S12 can address 64 KB 1

MC9S12 Address Space Lowest address: 0000000000000000 2 = 0000 16 = 0 10 Highest address: 1111111111111111 2 = FFFF 16 = 65535 10 0x0000 0 0xFFFF 65535 16 2 1 2

RAM: ROM: PROM: EPROM: MEMORY TYPES Random Access Memory (can read and write) Read Only Memory (programmed at factory) Programmable Read Only Memory (Program once at site) Erasable Programmable Read Only Memory (Program at site, can erase using UV light and reprogram) EEPROM: Electrically Erasable Programmable Read Only Memory (Program and erase using voltage rather than UV light) MC9S12 has: 12 KB RAM 3 KB EEPROM 256 KB Flash EEPROM (Can access 48 KB at a time) 3

0x0000 0x03FF 0x0400 0x0FFF 0x1000 MC9S12 Address Space Registers User EEPROM User RAM 1 K Bytes 3 K Bytes 11 K Bytes 0x3BFF 0x3C00 0x3FFF 0x4000 0x7FFF 0x8000 0xFFFF D Bug 12 RAM Banked Flash EEPROM D Bug 12 Flash EEPROM 1 K Bytes 16k Bytes 32k Bytes 4

MC9S12 ALU Arithmetic Logic Unit (ALU) is where instructions are executed. Examples of instructions are arithmetic (add, subtract), logical (bitwise AND, bitwise OR), and comparison. MC9S12 has two 8-bit registers for executing instructions. These registers are called A and B. For example, the MC9S12 can add the 8-bit number stored in B to the eight-bit number stored in A using the instruction ABA (add B to A): A B COMBINATIONAL BLOCK (ADD B TO A) CONTROL (0x1806 = ABA) CLOCK When the control unit sees the sixteen-bit number 0x1806, it tells the ALU to add B to A, and store the result into A. 5

MC9S12 Programming Model A Programming Model details the registers in the ALU and control unit which a programmer needs to know about to program a microprocessor. Registers A and B are part of the programming model. Some instructions treat A and B as a sixteen-bit register called D for such things as adding two sixteen-bit numbers. Note that D is the same as A and B. A 7 0 7 0 B 15 0 D The MC9S12 can work with 8-bit numbers (bytes) and 16-bit numbers (words). The size of word the MC9S12 uses depends on the instruction. For example, the instruction LDAA (Load Accumulator A) puts a byte into A, and LDD (Load Double Accumulator) puts a word into D. 6

MC9S12 Programming Model The MC9S12 has a sixteen-bit register which tells the control unit which instruction to execute. This is called the Program Counter (PC). The number in PC is the address of the next instruction the MC9S12 will execute. The MC9S12 has an eight-bit register which tells the MC9S12 about the state of the ALU. This register is called the Condition Code Register (CCR). For example, one bit (C) tells the MC9S12 whether the last instruction executed generated a carry. Another bit (Z) tells the MC9S12 whether the result of the last instruction was zero. The N bit tells whether the last instruction executed generated a negative result. There are three other 16-bit registers X, Y, SP which we will discuss later. A 7 0 7 0 B 15 0 D 15 15 15 15 0 0 0 0 S X H I N Z V C X Y SP PC CCR 7

Some MC9S12 Instructions Needed for Lab 1 LDAA address Put the byte contained in memory at address into A STAA address Put the byte contained in A into memory at address CLRA Clear A (0 -> A) INCA Add 1 to A ((A) + 1 -> A) ABA ASRA LSRA Add B to A, store the result in A Shift A right by one bit (keep the MSB the same) This divides a signed byte by 2 Shift A right by one bit (put 0 into MSB) This divides an unsigned byte by 2 NEGA Negate A (-(A) -> A) TAB Transfer A to B ((A) -> B) SWI Software Interrupt (Used to end all our MC9S12 program 8

A Simple MC9S12 Program All programs and data must be placed in memory between address 0x1000 and 0x3BFF. For our short programs we will put the first instruction at 0x1000, and the first data byte at 0x2000 Consider the following program: ldaa $2000 ; Put contents of memory at 0x2000 into A inca ; Add one to A staa $2001 ; Store the result into memory at 0x2001 swi ; End program If the first instruction is at address 0x1000, the following bytes in memory will tell the MC9S12 to execute the above program: Address Value Instruction 0x1000 B6 ldaa $2000 0x1001 20 0x1002 00 0x1003 42 inca 0x1004 7A staa $2001 0x1005 20 0x1006 01 0x1007 3F swi If the contents of address 0x2000 were 0xA2, the program would put an 0xA3 into address 0x2001. 9

A Simple Assembly Language Program. It is difficult for humans to remember the numbers (op codes) for computer instructions. It is also hard for us to keep track of the addresses of numerous data values. Instead we use words called mnemonics to represent instructions, and labels to represent addresses, and let a computer programmer called an assembler to convert our program to binary numbers (machine code). Here is an assembly language program to implement the previous program: prog equ $1000 ; Start program at 0x1000 data equ $2000 ; Data value at 0x2000 org ldaa inca staa swi prog input result org data input: dc.b $A2 result: ds.b 1 We would put this code into a file and give it a name, such as test.s Note that equ, org, dc.b and ds.b are not instructions for the MC9S12 but are directives to the assembler which make it possible for us to write assembly language programs. The are called assembler directives or psuedo-ops. For example the psuedo-op org tells the assembler that the starting address (origin) of our program should be 0x1000. 10

Assembling an Assembly Language Program A computer program called an assembler can convert an assembly language program into machine code. The assembler we use in class is a freee compiler from Motorola. The easiest way to assemble it is to use the freeware IDE AsmIDE, as discussed in Lab 1 and in Huang. The assembler will produce a file called test.lst, which shows the machine code generated. as12, an absolute assembler for Motorola MCU s, version 1. 1000 prog equ $1000 ; Start p 2000 data equ $2000 ; Data va 1000 org prog 1000 b6 20 00 ldaa input 1003 42 inca 1004 7a 20 01 staa result 1007 3f swi 2000 org data 2000 a2 input: dc.b $A2 2001 result: ds.b 1 Executed: Thu Jan 19 21:19:06 2006 Total cycles: 23, Total bytes: 9 Total errors: 0, Total warnings: 0 11

This will produce a file called test.s19 which we can load into the MC9S12. S012000046696C653A20746573742E61736D0ADA S10B1000B62000427A20013FF2 S1042000A239 S9030000FC The first line of the S19 file starts with a S0: the S0 indicates that it is the first line. The last line of the S19 file starts with a S9: the S9 indicates that it is the last line. The other lines begin with a S1: the S1 indcates these lines are data to be loaded into the MC9S12 memory. On the second line, the S1 if followed by a 0B. This tells the loader that there this line has 11 (0x0B) bytes of data follow. The count 0B is followed by 1000. This tells the loader that the data should be put into memory starting with address 0x1000. The next 16 hex numbers B62000427A20013F are the 8 bytes to be loaded into memory. You should be able to find these bytes in the test.lst file. The last two hex numbers, 0xF2, is a one byte checksum, which the loader can use to make sure the data was loaded correctly. 12