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

Similar documents
Programming the Motorola MC68HC11 Microcontroller

EE 3170 Microcontroller Applications

The Motorola 68HC11 Instruc5on Set

Condition Code Register. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

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

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.

Lecture 6 Assembly Programming: Branch & Iteration

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

CprE 288 Introduction to Embedded Systems Course Review for Exam 3. Instructors: Dr. Phillip Jones

TABLE 9-1. Symbolic Convention for Addressing Modes. Register indirect LDA (R1) ACC M[ R1] Refers to Figure 9-4. Addressing mode. Symbolic convention

Introduction to Embedded Microcomputer Systems Lecture 8.1. Computers in the future may weigh no more than 1.5 tons Popular Science, 1949

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

10-1 C D Pearson Education, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 4e

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

ARM Assembly Language. Programming

EE 3170 Microcontroller Applications

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

Outline. 2.8 Stack. 2.9 Subroutines

NET3001. Advanced Assembly

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

RCX internals (Revised February 24)

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

H8/300L Series Programming Manual

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls

Programming. A. Assembly Language Programming. A.1 Machine Code. Machine Code Example: Motorola ADD

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

Chapter 2 HCS12 Assembly Language

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

EE4390 Microprocessors

Motorola 6809 and Hitachi 6309 Programmer s Reference

Lecture 11: Advanced Arithmetic Instructions

ECE251: Tuesday September 11

TYPES OF INTERRUPTS: -

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

Assembly Language Programming

Fri. Aug 25 Announcements

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

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

HC11 Instruction Set

HC 11 Instructions! From Alex Hollowayʼs notes with! many thanks!

ECE251: Tuesday September 12

EECE416 :Microcomputer Fundamentals and Design Instruction Sets and Groups

Chapter 7 Central Processor Unit (S08CPUV2)

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

instruction 1 Fri Oct 13 13:05:

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Using the stack and the stack pointer

Immediate vs. Extended mode: Immediate values are marked with a # symbol. They also are different instructions when assembled.

Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name:

ARM Instruction Set Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

ECE232: Hardware Organization and Design

Intel 8086: Instruction Set

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

INTRODUCTION TO BRANCHING. There are two forms of unconditional branching in the MC68000.

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

EE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name:

SECTION 6 CENTRAL PROCESSING UNIT

H8/500 Series Programming Manual

EE319K Spring 2016 Exam 1 Solution Page 1. Exam 1. Date: Feb 25, UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi

Unsigned and signed integer numbers

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

EE 3170 Microcontroller Applications

INFOB3TC Solutions for Exam 2

Introduction to MIPS Processor

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers

Exam I Review February 2017

Motorola HC11. Fun with Microcontrollers and Embedded Systems

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

EE319K Fall 2013 Exam 1B Modified Page 1. Exam 1. Date: October 3, 2013

Chapter 04: Instruction Sets and the Processor organizations. Lesson 18: Stack-based processor Organisation

Microcontrollers. 2IN60: Real-time Architectures (for automotive systems) Mike Holenderski,

Exam 1. Date: Oct 4, 2018

Architecture. Digital Computer Design

ARM Assembly Programming

The Assembly Language of the Boz 5

ARM Cortex-M4 Programming Model Flow Control Instructions

COMPUTER HARDWARE. Instruction Set Architecture

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

EEM336 Microprocessors I. Arithmetic and Logic Instructions

MIPS Assembly Language

EE319K Spring 2015 Exam 1 Page 1. Exam 1. Date: Feb 26, 2015

Compiling Techniques

(2) Part a) Registers (e.g., R0, R1, themselves). other Registers do not exists at any address in the memory map

CHAPTER 8. Solutions for Exercises

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

ARM Assembly Programming

Computer Internals ECE2036. Lecture 2. ECE2036 Computer Internals Spring / 12

Introduction to Embedded Microcomputer Systems Lecture 10.1

MIPS Architecture and Assembly Language Overview

Chapter 2A Instructions: Language of the Computer

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

OSIAC Read OSIAC 5362 posted on the course website

Signed number Arithmetic. Negative number is represented as

INFOB3TC Exam 2. Sean Leather. Monday, 30 January 2012, 17:00 20:00

EE319K (Gerstlauer), Spring 2013, Midterm 1 1. Midterm 1. Date: February 21, 2013

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Transcription:

Assembly Programming HCS12 Assembly Programming Basic Assembly Programming Top Assembly Instructions (Instruction You Should Know!) Assembly Programming Concepts Assembly Programming HCS12 Assembly Instructions Load and Store Instructions Arithmetic Operations Logic Operations Branch Instructions Shift and Rotation Operation Bit tests and Bit manipulations Stack and Index Pointer Operations Condition Code Register Instructions Subroutine Calls Interrupt Handling Operations Miscellaneous Operations 1 2 Load and Store Instructions ldaa/ldab/ldd - Load A/B/D from memory (or immediate value) ldx/ldy - Load Index Register X/Y from memory (or immediate value) lds - Load Stack Pointer (SP) from memory (or immediate value) staa/stab/std - Store A/B/D to memory stx/sty Store Index Register X/Y to memory sts Store Stack Pointer (SP) to memory Arithmetic Operations adda/addb/addd Add memory (or immediate value) to A/B/D suba/subb/subd Subtract memory (or immediate value) from A/B/D aba Add B to A sba Subtract B from A inca/incb/inx/iny Increment A/B/X/Y e.g. A = A + 1 deca/decb/dex/dey Decrement A/B/X/Y e.g. A = A - 1 3 4

Arithmetic Operations cmpa/cmpb/cpd/cpx/cpy Compare A/B/D/X/Y with memory (or immediate value) Branch follows (e.g. greater, less, equal) mul Performs 8-bit unsigned multiplication of A and B, storing 16-bit result in D e.g. D = A * B idiv Performa 16-bit unsigned division of D and Y, storing quotient in X and remainder in D e.g. X = D / X and D = D % X Logic Operations anda/andb Perform 8-bit logical AND of A/B with memory (or immediate value) oraa/orab Perform 8-bit logical OR of A/B with memory (or immediate value) eora/eorb Perform 8-bit logical XOR of A/B with memory (or immediate value) bset/bclr Set/Clear bit in memory using provided mask bita/bitb Performs 8-bit logical AND of A/B with memory (or immediate value) and modifies CCR Contents of A/B or the memory location are not affected 5 6 Branch Instructions (Unsigned/Signed) beq Branch if equal (Relative PC Addressing) bne Branch if not equal (Relative PC Addressing) bra Branch always (Relative PC Addressing) jmp Branch always (Absolute Addressing) Branch Instructions (Unsigned) bhi Branch if higher (Relative PC Addressing) i.e. unsigned greater than bhs Branch if higher or same (Relative PC Addressing) i.e. unsigned greater than or equal blo Branch if lower (Relative PC Addressing) i.e. unsigned less than bls Branch if lower or same (Relative PC Addressing) i.e. unsigned less than or equal 7 8

Branch Instructions (Signed) bgt Branch if greater than (Relative PC Addressing) bge Branch if greater than of equal (Relative PC Addressing) blt Branch if less than (Relative PC Addressing) ble Branch if less than or equal (Relative PC Addressing) bmi Branch if minus (Relative PC Addressing) i.e. negative result bpl Branch if plus (Relative PC Addressing) i.e. positive result Long Branch Instructions Similar to other branch instructions PC relative addressing But with 16-bit relative address Few Examples: lbra Branch always (Long Relative PC Addressing) lbeq Branch if equals (Long Relative PC Addressing) lbgt Branch if greater than (Long Relative PC Addressing) 9 10 Shift and Rotate Operations rola/rolb Rotate left A/B through carry (C) Rotate Left: C 7 6 5 4 3 2 1 0 Shift and Rotate Operations lsla/lslb/lsld Logical shift left A/B/D into carry (C) Same as asla/aslb/asld instructions Least significant bit is loaded with 0 Also performs multiply by 2 rora/rorb Rotate right A/B through carry (C) Logical Shift Left: C 7 6 5 4 3 2 1 0 0 lsra/lsrb/lsrd Logical shift right A/B/D into carry (C) NOT the same asra/asrb/asrd Most significant bit is loaded with 0 Also performs unsigned divide by 2 Logical Shift Right: 0 7 6 5 4 3 2 1 0 C 11 12

Shift and Rotate Operations asla/aslb/asld Arithmetic shift left A/B/D into carry (C) Same as lsla/lslb/lsld instructions Least significant bit is loaded with 0 Also performs multiply by 2 asra/asrb/asrd Arithmetic shift right A/B/D into carry (C) NOT the same lsra/lsrb/lsrd Most significant bit is loaded with previous most significant bit value Also performs unsigned/signed divide by 2 If-Then C Code: if()! If Arithmetic Shift Right: 7 6 5 4 3 2 1 0 C If-Then Assembly Template: cmp?? ; If b?? EndIf ; Branch! 13 14 If-Then C Code: If-Then-Else C Code: if(a>=20)! If if() else // else body If Else! Else Body If-Then Assembly Code: cmpa, #20 ; If (A>=20) blo EndIf ; Branch!(A>=20)=>(A<20) If-Then-Else Assembly Template: cmp?? ; If-Else b?? Else ; Branch! bra EndIf ; Branch EndIf Else: ; Else Body ; 15 16

If-Then-Else C Code: if(a>=20) else // else body A>=20 If Else!(A>=20) Else Body For C Code: for(init; ; iter) Init. Iter. If-Then-Else Assembly Code: cmpa, #20 ; If-Else (A>=20) blo Else ; Branch!(A>=20)=>(A<20) bra EndIf ; Branch EndIf Else: ; Else Body ; For Assembly Template:?? ; Init. : cmp?? ; b?? End ; Branch! ;?? ; Iter.! 17 18 For C Code: J=0 While C Code: for(j=0; J<10; J++) J++ while() J<10! For Assembly Code: ldaa #0 ; Init. (J=0)!(J<10) : cmpa #10 ; (J<10) bge End ; Branch!(J<10)=>(J>=10) ; adda #1 ; Iter. (J++) While Assembly Template: : cmp?? ; b?? End ; Branch! ; 19 20

Assembly Programming Data Organization While C Code: while(i!=0)!(i!=0) i!=0 Global Variables Constants Program Code Local Variables Return Addresses Temporary Data While Assembly Code: : cmpa, #0 ; (i!=0) beq End ; Branch!(i!=0)=>(i==0) ; 21 22 Assembly Programming Data Organization Heap Block of memory for allocating storage whose lifetime is not related to the execution of the current routine Often used for dynamically allocated data (malloc) Typically located at lowest memory address after global varaibles Assembly Programming Data Organization Stack Generally A data structure supporting two basic operations, push and pop Push Adds an item to the top of the stack Pop Removes an item from the top of the stack LIFO Last In First Out data structure (opposite of queue) Stack Pointer (SP) Points to memory location corresponding to the top of the stack Must be initialized within your assembly program 23 24