HC12 Assembly Language Programming



Similar documents
The stack and the stack pointer

Lecture 3 Addressing Modes, Instruction Samples, Machine Code, Instruction Execution Cycle

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Programming the Motorola MC68HC11 Microcontroller

M6800. Assembly Language Programming

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

Programmer s Model = model of µc useful to view hardware during execution of software instructions

How To Understand All Instructions In The Power12 Program

Introduction to Microcontrollers

6800 Basics. By Ruben Gonzalez

How To Write A Microsoft Microsoft 8D (Droid) (Program) (Powerbook) (I386) (Microsoft) (Donga) (Opera) And (Dungeo) (Dugeo

THUMB Instruction Set

1 Classical Universal Computer 3

What to do when I have a load/store instruction?

U:\montages\dominique\servo\moteur_AV_AR\program\moteur_AV_AR.asm jeudi 28 avril :32

Microprocessor/Microcontroller. Introduction

MACHINE ARCHITECTURE & LANGUAGE

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

Faculty of Engineering Student Number:

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

AN2183. Using FLASH as EEPROM on the MC68HC908GP32. Introduction. Semiconductor Products Sector Application Note

CS201: Architecture and Assembly Language

PROBLEMS (Cap. 4 - Istruzioni macchina)

Embedded system programming: HCS12

8085 INSTRUCTION SET

A Utility for Programming Single FLASH Array HCS12 MCUs, with Minimum RAM Overhead

Instruction Set Design

Typy danych. Data types: Literals:

Introduction. What is an Operating System?

Instruction Set Architecture

MICROPROCESSOR AND MICROCOMPUTER BASICS

Z80 Instruction Set. Z80 Assembly Language

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

PIC Programming in Assembly. (

Instruction Set Architecture

Chapter 7D The Java Virtual Machine

EECS 427 RISC PROCESSOR

Traditional IBM Mainframe Operating Principles

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

Notes on Assembly Language

Addressing The problem. When & Where do we encounter Data? The concept of addressing data' in computations. The implications for our machine design(s)

PART B QUESTIONS AND ANSWERS UNIT I

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis

EC 362 Problem Set #2

The string of digits in the binary number system represents the quantity

Systems I: Computer Organization and Architecture

Real-time system programs

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

A3 Computer Architecture

An Introduction to the ARM 7 Architecture

Section 44. CPU with Extended Data Space (EDS)

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

EE282 Computer Architecture and Organization Midterm Exam February 13, (Total Time = 120 minutes, Total Points = 100)

Computer Organization and Architecture

Translating C code to MIPS

LABORATORY MANUAL EE0310 MICROPROCESSOR & MICROCONTROLLER LAB

Keil C51 Cross Compiler

MACHINE INSTRUCTIONS AND PROGRAMS

Computer Systems Architecture

Computer organization

Developer Suite ARM. Assembler Guide. Version 1.2. Copyright 2000, 2001 ARM Limited. All rights reserved. ARM DUI 0068B

Reduced Instruction Set Computer (RISC)

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Lecture 22: C Programming 4 Embedded Systems

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Complete 8086 instruction set

Adding and Subtracting Positive and Negative Numbers

Administrative Issues

Freescale Semiconductors, Inc. Freescale HC12 Assembler

X86-64 Architecture Guide

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

Instruction Set Architecture (ISA)

A Tiny Guide to Programming in 32-bit x86 Assembly Language

We will use the accumulator machine architecture to demonstrate pass1 and pass2.

CHAPTER 7: The CPU and Memory

Summary of the MARIE Assembly Language

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

Call Subroutine (PC<15:0>) TOS, (W15)+2 W15 (PC<23:16>) TOS, Process data. Write to PC NOP NOP NOP NOP

The Java Virtual Machine (JVM) Pat Morin COMP 3002

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

IBCM: The Itty Bitty Computing Machine

The 68000's Instruction Set

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

MDRM. MULTOS Developer's Reference Manual. MAO-DOC-TEC-006 v MAOSCO Limited. MULTOS is a registered trademark of MULTOS Limited.

6809 SBUG-E Monitor ROM Version 1.5

Programming Examples. B.1 Overview of Programming Examples. Practical Applications. Instructions Used

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

CPU Organization and Assembly Language

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Transcription:

HC12 Assembly Language Programming Programming Model Addressing Modes Assembler Directives HC12 Instructions Flow Charts 1

Assembler Directives In order to write an assembly language program it is necessary to use assembler directives. These are not instructions which the HC12 executes but are directives to the assembler program about such things as where to put code and data into memory. All of the assembler directives can be found in Pages 46 through 49 of the manual for the evaluation version of the Cosmic Compiler. A PDF version of this manual can be found on the EE 308 home page. We will use only a few of these directives. (Note: In the following table, [] means an optional argument.) Here are the ones we will need: Directive Name Description Example equ Give a value to a symbol len: equ 100 org Set starting value of location counter org $0800 where code or data will go section Define a new program section CODE: section.text For example, code or data dc[.size] Allocate and initialize storage var: dc.b 2,18 for variables. Size can be b (byte), w (two bytes) or l (4 bytes) If no size is specified, b is uses ds[.size] Allocate specified number of table: ds.w 10 storage spaces. size is the same as for dc directive 2

Using labels in assembly programs A label is defined by a name followed by a colon as the first thing on a line. When the label is referred to in the program, it has a numerical value of the location counter when the label was defined. Here is a code fragment using labels and the assembler directives dc and ds: DATA: section.data ;The stuff which follows is data org $0900 table1: dc.b $23,$17,$f2,$a3,$56 table2: ds.b 5 var: dc.w $43af Here is the listing from the assembler: 9 DATA: section.data ;The stuff w 10 0900 org $0900 11 0900 2317f2a356 table1: dc.b $23,$17,$f2,$a3,$56 12 0905 0000000000 table2: ds.b 5 13 090a 43af var: dc.w $43af And here is the map file: Map of demo.h12 from link file demo.lkf - Thu Jan 25 09:56:12 2 table1 00000900 table2 00000905 var 0000090a Note that, table1 is a name with the value of $0900, the value of the location counter defined in the org directive. Five bytes of data are defined by the dc.b directive, so the location counter is increased from $0900 to $0905. table2 is a name with the value of $0905. Five bytes of data are set aside for table2 by the ds.b 5 directive. The Cosmic assembler initialized these five bytes of data to all zeros. 3

HC12 Assembly Language Programming Programming Model Addressing Modes Assembler Directives HC12 Instructions Flow Charts 4

1. Data Transfer and Manipulation Instructions instructions which move and manipulate data (CPU12 Reference Manual, Sections 5.2, 5.3, and 5.4). Load and Store load copy of memory contents into a register; store copy of register contents into memory. LDAA $0900 ; Copy contents of addr $0900 into A STD 0,X ; Copy contents of D to addrs X and X+1 Transfer copy contents of one register to another. TBA ; Copy B to A TFR X Y ; Copy X to Y Exhange exchange contents of two registers. XGDX ; Exchange contents of D and X EXG A B ; Exchange contents of A and B Move copy contents of one memory location to another. MOVB $0900 $09A0 ; Copy byte at $0900 to $09A0 MOVW 2,X+ 2,Y+ ; Copy two bytes from address held ; in X to address held in Y ; Add 2 to X and Y 2. Arithmetic Instructions addition, subtraction, multiplication, divison (CPU12 Reference Manual, Sections 5.5, 5.6, 5.7 5.11). ABA ; Add B to A; results in A SUBD $09A1 ; Subtract contents of $09A1 from D INX ; Increment X by 1 MUL ; Multiply A by B; results in D 3. Logic and Bit Instructions perform logical operations (CPU12 Reference Manual, Sections 5.9, 5.10, 5.12, 5.13). Logic Instructions ANDA $0900 ; Logical AND of A with contents of $0900 NEG -2,X ; Negate (2 comp) contents of address (X-2) LSLA ; Logical shift left A by 1 5

Bit manipulate and test instructions work with one bit of a register or memory. BITA #$08 ; Check to see if Bit 4 of A is set BSET $0002,#$18 ; Set bits 3 and 4 of address $002 4. Data test instructions test contents of a register or memory (to see if zero, negative, etc.), or compare contents of a register to memory (to see if bigger than, etc.) (CPU12 Reference Manaul, Section 5.7). TSTA ; (A)-0 -- set flags accordingly CPX #$8000 ; (X) - $8000 -- set flags accordingly 5. Jump and Branch Instructions Change flow of program (e.g., goto, it-thenelse, switch-case) (CPU12 Reference Manual, Sections 5.18, 5.19, 5.20). JMP l1 ; Start executing code at address label l1 BEQ l2 ; If Z bit zero, go to label l2 DBNE X l3 ; Decrement X; if X not 0 then goto l3 BRCLR $1A,#$80 l4 ; If bit 7 of addr $1A set, goto l4 6. Function Call and Interrupt Instructions initiate or terminate a subroutine; initiate or terminate and interrupt call (CPU12 Reference Manual, Sections 5.20, 5.21). Subroutine instructions: JSR sub1 ; Jump to subroutine sub1 RTS ; Return from subroutine Interrupt instructions SWI ; Initiate software interrupt RTI ; Return from interrupt 6

7. Stacking Instructions push data onto and pull data off of stack (CPU12 Reference Manual, Section 5.23). PSHA PULX ; Push contents of A onto stack ; Pull two top bytes of stack, put into X 8. Stop and Wait Instructions put HC12 into low power mode (CPU12 Reference Manual, Section 5.26). STOP WAI ; Put into lowest power mode ; Put into low power mode until next interrupt 9. Instructions we won t discuss or use BCD arithmetic, fuzzy logic, minimum and maximum, multiply-accumulate, table interpolation (CPU12 Reference Manual, Sections 5.6, 5.14, 5.15, 5.16, 5.17). 7

Branch if A > B Is 0xFF > 0x00? If unsigned, 0xFF = 255 and 0x00 = 0, so 0xFF > 0x00 If signed, 0xFF = 1 and 0x00 = 0, so 0xFF < 0x00 Using unsigned numbers: BHI (checks C bit of CCR) Using signed numbers: BGT (checks V bit of CCR) For unsigned numbers, use branch instructions which check C bit For signed numbers, use branch instructions which check V bit Will the branch be taken? LDAA #$FF LDAA #$FF CMPA #$0 CMPA #$0 BLO label1 BLT label2 LDX #$C000 LDX #$C000 CMPX #$8000 CMPS #$8000 BGT label3 BHI label4 8