Exam I Review February 2017

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

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

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)

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

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

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

CHAPTER 8. Solutions for Exercises

A Simple MC9S12 Program

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

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

Using the stack and the stack pointer

Programming the Motorola MC68HC11 Microcontroller

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

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

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

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

What is an Addressing Mode?

COSC345 Software Engineering. Basic Computer Architecture and The Stack

Mark II Aiken Relay Calculator

Exam 1 Feb. 23, 25, 27?

Outline. 2.8 Stack. 2.9 Subroutines

S12CPUV2. Reference Manual HCS12. Microcontrollers. S12CPUV2/D Rev. 0 7/2003 MOTOROLA.COM/SEMICONDUCTORS

Microcontrollers. Microcontroller

HC11 Instruction Set Architecture

HC11 Instruction Set Architecture

Chapter 7 Central Processor Unit (S08CPUV2)

Lecture 9 Subroutines

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

Sample Problem Set #1

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.

The Motorola 68HC11 Instruc5on Set

538 Lecture Notes Week 3

ECE 331: PC Lab 3 Stack and Subroutines

Introduction to Programming

CMPEN 472 Sample EXAM II

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

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

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

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

Introduction to the 9S12 Microcontroller

Motorola HC11. Fun with Microcontrollers and Embedded Systems

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

CS/ECE 5780/6780: Embedded System Design

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

SECTION 6 CENTRAL PROCESSING UNIT

538 Lecture Notes Week 2

ME 4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 6

EE 3170 Microcontroller Applications

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Module 1-D. Control Structure Applications. Tim Rogers 2017 [1.D]-1

Introduction to Microcontrollers

Computers and Microprocessors

Introduction to Microcomputer Systems Addressing modes

MIGRATING TO THE 68HC12 IN C

Cross Assembly and Program Development

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

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

HC11 Instruction Set

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

538 Lecture Notes Week 1

CPU12 REFERENCE MANUAL

Introduction to Microcontrollers II

Lecture #3 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Wednesday, 20-Jan-2015

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Introduction to Microcontrollers II

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

Lecture #4 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Monday, 25-Jan-2016

Exam 2 E2-1 Fall Name: Exam 2

Microcontrollers and the Freescale/Motorola HC11

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

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

Coe538 Final Study Guide 2016 (Questions & Answers)

ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Solution Set #2

Homework 12 Solutions

538 Lecture Notes Week 5

538 Lecture Notes Week 5

EE 109 Unit 6 Binary Arithmetic

ME 6405 Introduction to Mechatronics

MC9S12 Address Space

EE 308 Spring The HCS12 has 6 addressing modes

ECE3120: Computer Systems Hardware & Software Development Tools

EE 3170 Microcontroller Applications

Number representations


Chapter 3: part 3 Binary Subtraction

Microcontrollers and Embedded Systems. Fun with Motorola/Freescale HC11

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

Introduction to Computers - Chapter 4

ECE331: Hardware Organization and Design

ECE 4510/5530 Microcontroller Applications Chapter 1

Cmpt 150 The Freescale CPU12 March, The Freescale HC12

ECE 3120 Computer Systems Arithmetic Programming


CPU08RM/AD REV 3 8M68HC08M. CPU08 Central Processor Unit. Reference Manual

PROGRAM CONTROL UNIT (PCU)

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

Transcription:

Exam I Review February 2017 Binary Number Representations Conversion of binary to hexadecimal and decimal. Convert binary number 1000 1101 to hexadecimal: Make groups of 4 bits to convert to hexadecimal, so binary number 1000 1101 can be represented as 8D in hexadecimal Convert binary number 1000 1101 to unsigned decimal: V = 1 2 7 + 1 2 3 + 1 2 2 + 1 2 0 = 141 Convert binary number 1000 1101 to signed decimal: First, note that we are dealing with a negative number (MSB is 1), so take 2 s complement of number, convert result to decimal, and then add the - sign. The 2 s complement is 0111 0011. Now convert to decimal and add the sign, and the final result is -115. Convert the signed decimal number -115 to binary: This is a negative so we should expect to have a 1 in the MSB. First convert the magnitude of the number to binary and then take 2 s complement. 1. To convert a decimal number to binary we need to divide repeatedly by 2, and the reminder will be the binary number, and we get 0111 0011. 2. Take the 2 s complement, and we get 1000 1101.

Convert the unsigned decimal number 115 to binary: Since it is unsigned, we do not have to worry about the sign being 0 or 1. Only divide by 2 consecutively to get the binary number, and do not take the 2 s complement, and we will get 0111 0011. Binary Number Addition and Subtraction (Using 2 s complement) To add binary numbers, add bit-by-bit starting from the LSB: 0001 1110 + 1001 1101-1011 1011 To add hexadecimal numbers, add digit-by-digit: + 9 D B B Status of CCR when adding hex numbers: C bit set when result does not fit in word V bit set when P + P = N or N + N = P N bit set when MSB of result is 1 Z bit set when result is 0 + 9 D B B C = 0, V = 0, N = 0, Z = 0

To subtract binary numbers, find the 2 s complement of subtrahend and then add them: 0001 1110-1001 1101-0001 1110 + 0110 0011-1000 0001 To subtract hex numbers, also find the 2 s complement of subtrahend and then add them: - 9 D + 6 3 8 1 Status of the CCR when subtracting hex numbers: C bit set on borrow (when the magnitude of the subtrahend is greater than the minuend V bit set when N - P = P or P - N = N N bit set when MSB is 1 Z bit set when result is 0-9 D 8 1 C = 1, V = 1, N = 1, Z = 0

Disassembly of an HCS12 Program For example, consider the hex code: 1000 C6 05 CE 20 00 18 06 3F To determine the instructions use Table A-2 - A-6 1. $C6 corresponds to LDAB using IMM addressing mode. LDAB #$05 2. $CE corresponds to LDX using IMM addressing mode. LDX $#2000 3. $18 is not in Sheet 1 of Table A-2, and we need to go to Sheet 2 of Table A-2, to look up $06 code in that sheet. ABA The ABA operation uses INH addressing mode, so there is no operand for this command. 4. $3F corresponds to the SWI instruction to terminate the program. Computation of Time of Execution To compute how long a program takes to execute we need to count the total number of cycles it takes to execute a segment of code. We can also find this information in Table A-2 A-6. Cycles Instructions [1] LDAB #$05 [2] LDX $#2000 [2] ABA [9] $3F -------------- 14 CPU cycles

We want to know how fast this program executes. We also know that a CPU cycle takes 41.7 ns to execute, therefore: 14 cycles 41.7 ns/cycle = 583.8 ns Addressing Modes We are able to tell the effective address by knowing the addressing mode. INH Inherent IMM Immediate DIR Direct EXT Extended IDX Indexed (won t study indirect indexed mode) REL Relative (used only with branch instructions) The Inherent (INH) addressing mode is used by instructions which work only with registers inside ALU ABA ; Add B to A CLRA ; clear A The HC12 does not access memory The Extended (EXT) addressing mode is used by instructions which give the 16 bit address to be accessed LDAA $1000 ; Load accumulator A with contents of address $1000 Effective address $1000 LDX $1001 ; Load index register X with contents of address $1001:$1002 Effective address $1001 Effective address is specified by the two bytes following op code

The Direct (DIR) addressing mode is used by instructions which give 8 LSB of address LDAA $20 ; Load accumulator A with content from address $0020 Effective address $0020 STX $21 ; Load index register with content of address $0021:$0022 Effective Address: $0021 Effective address is specified by byte following op code The Immediate (IMM) addressing mode is used as part of instruction LDAA #$17 ; Move $17 into accumulator A Effective Address: PC + 1 ADDA #10 ; Add to accumulator A a 10 Effective Address: PC + 1 Effective address is the address following the op code The Indexed (IDX, IDX1, IDX2) addressing mode is used by instructions in which the effective address is obtained from X or Y register (or SP or PC): LDAA 0,X ; Use (X) as address to get value to put in A Effective address: contents of X ADDA 5,Y ; Use (Y) + 5 as address to get value to add to Effective address: contents of Y + 5 The Stack and the Stack Pointer The stack is a region of memory can be used for temporary storage by the microcontroller and/or the user. To save information onto the stack use a push (the SP decrements).

To retrieve information from the stack use a pull (the SP increments). The very first instruction in a program that uses the stack should be an LDS. org $2000 ; program starts at $2000 lds #$2000 ; initialize stack at $2000 ldaa #$2E ; loads acca with $2E ldx #$1254 ; loads reg X with $1234 psha ; decrements SP by 1, pushes A into the stack pshx ; decrements SP by 2, pushes X into the stack jsr sub ; decrements SP by 2, saves return address into ; stack, jumps to subroutine pulx ; pulls reg X from stack, increments SP by 2 pula ; pulls reg A from stack, increments SP by 1 swi ; terminates program sub: clra ; clears A (A=$00) ldx #$FFF ; loads reg X with $FFFF rts ; return address is pulled off the stack, and SP increments by 2 When the program finishes executing (executes the SWI instruction), we will have the following in the registers: A = $2E X = $1254 SP = $2000