© 2010 Kettering University, All rights reserved..

Slides:



Advertisements
Similar presentations
Ch.3 Representation and Manipulation of Information From Introduction to Embedded Systems: Interfacing to the Freescale 9s12 by Valvano, published by CENGAGE.
Advertisements

EE 362 Microprocessor Systems and Interfacing © 1-1 Lecture 1: Introduction to Microprocessor Based Systems Microprocessor Architecture Microprocessor.
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
Revised: Aug 1, EE4390 Microprocessors Lesson 6,7 Instruction Set, Branch Instructions, Assembler Directives.
HCS12 Arithmetic Lecture HC12 Arithmetic Addition and Subtraction Shift and Rotate Instructions Multiplication Division.
© 2010 Kettering University, All rights reserved..
Lecture 15: Computer Arithmetic Today’s topic –Division 1.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
© 2010 Kettering University, All rights reserved..
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Programming the HC12 in C. Some Key Differences – Note that in C, the starting location of the program is defined when you compile the program, not in.
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
© 2010 Kettering University, All rights reserved..
Lecture – 5 Assembly Language Programming
© 2010 Kettering University, All rights reserved..
Assembly Language – Lab 5
The M68HC11 Basic Instruction Set Basic Arithmetic Instructions
Chapter 2: 68HC11 Assembly Programming
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
H. Huang Transparency No.2-1 The 68HC11 Microcontroller Chapter 2: 68HC11 Assembly Programming The 68HC11 Microcontroller.
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
© 2010 Kettering University, All rights reserved..
How Computers Work Dr. John P. Abraham Professor UTPA.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
© 2010 Kettering University, All rights reserved..
EECC250 - Shaaban #1 Lec # 20 Winter Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:
9/20/6Lecture 3 - Instruction Set - Al Instruction Set (2)
Chapter four – The 80x86 Instruction Set Principles of Microcomputers 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 1 Chapter.
Microcomputers I - Electrical and Computer Engineering Dept. at Kettering.
© 2010 Kettering University, All rights reserved..
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
© 2010 Kettering University, All rights reserved..
ECE 447: Lecture 12 Logic, Arithmetic, Data Test and Control Instructions of MC68HC11.
ECE 265 – LECTURE 5 The M68HC11 Basic Instruction Set 12/8/ ECE265.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Microcontroller Fundamentals & Programming Arithmetic Instructions.
Arithmetic and Logic Instructions
Advanced Assembly Language Programming
© 2010 Kettering University, All rights reserved..
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Embedded Systems Lecture 5 January 25 th, 2016.
Integer Operations Computer Organization and Assembly Language: Module 5.
EE345 Chapter 2 Lecture 3 April Instruction and addressing modes 1.Extended Addressing 2.Direct Addressing 3.Inherent Addressing 4.Immediate Addressing.
The 68HC11 Microcontroller Minnesota State University, Mankato
CPU12 Instruction Set Overview
Digital Logic & Design Adil Waheed Lecture 02.
Lecture – 5 Assembly Language Programming
Addressing Modes in Microprocessors
ECE 3430 – Intro to Microcomputer Systems
HC11 Programming.
Integer Real Numbers Character Boolean Memory Address CPU Data Types
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Instructor: David Ferry
ECE 3430 – Intro to Microcomputer Systems
Morgan Kaufmann Publishers
Digital Systems Section 14 Registers. Digital Systems Section 14 Registers.
Arithmetic operations Programming
Chapter 11 © 2011, The McGraw-Hill Companies, Inc.
Microprocessor and Assembly Language
ECE 3430 – Intro to Microcomputer Systems
Binary to Decimal Conversion
Chapter 5 Arithmetic and Logic Instructions
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
Presentation transcript:

© 2010 Kettering University, All rights reserved.

Microcomputers I – CE 320 Electrical and Computer Engineering Kettering University Jaerock Kwon, Ph.D.

Announcements Behind the schedule. Go little bit faster!!

Advanced Arithmetic Instructions Lecture 11: Advanced Arithmetic Instructions

Today’s Goals Use basic multiplication and division instructions. Use shift and rotate instructions

Multiplication Three different multiplication instructions.  MUL Unsigned 8 by 8 multiplication D (A:B)  A * B  EMUL Unsigned 16 by 16 multiplication Y:D  D * Y  EMULS Signed 16 by 16 multiplication Y:D  D * Y Note:  Register Y is being used for multiplication. Example: LDAA #$12 LDAB #$34 MUL D(A:B) = 03A8 Example: LDAA #$12 LDAB #$34 MUL D(A:B) = 03A8

Division Five different division instructions  IDIV Unsigned 16 by 16 integer division X  (quotient) (D) / (X) D  (remainder) (D) / (X)  IDIVS Signed 16 by 16 integer division X  (quotient) (D) / (X) D  (remainder) (D) / (X)  FDIV Like IDIV, but 16 by 16 fractional division. Expect dividend to be smaller than divisor. X  (quotient) (D) / (X) D  (remainder) (D) / (X) Example:33÷2 = 16 and 1 16  quotient 1  remainder 33  dividend -- 2  divisor 5÷9 LDD #5 LDX #9 IDIV (X) = 0, (D) = 5 Example:33÷2 = 16 and 1 16  quotient 1  remainder 33  dividend -- 2  divisor 5÷9 LDD #5 LDX #9 IDIV (X) = 0, (D) = 5 DX

Division - continued  EDIV Unsigned 32 by 16 integer division Y  (quotient) (Y:D) / (X) D  (remainder) (Y:D) / (X)  EDIVS Signed 32 by 16 integer division Y  (quotient) (Y:D) / (X) D  (remainder) (Y:D) / (X) Note: Register X is being used for division while Y for multiplication.

Example An exponential filter is often used to condition an incoming input signal. X(t) is an input signal at time t. The weight factor α must be between 0 and 1. α determines how quickly the filtered value will respond to a change in input. Let’s write a program  α = 5/9  8 bit input is supplied in address $0000  8 bit output is written to $0001 Exponential Filter

Example – source code The program uses register Y to save the first term. The second term is saved to register X and transferred to B Transfer register Y to A to add those two terms. (ABA) Exponential Filter alpnEQU5 alpdEQU9 ORG$0000 XinDS.B1 XaveDS.B1 ORG $2000 Loop: ; alpha * X (t) LDAAXin; A <-- (Xin) LDAB#alpn; B <-- 5 MUL; D <-- (A) * (B) = (Xin) * 5 LDX#alpd; X <-- 9 IDIV; X <-- Q((D)/(X)), D <-- R((D)/(X)) TFRX,Y; Y <-- (Xin * 5) / 9 ; (1 - alpha) * Xave (t) ; (1 - 5 / 9) = (9 - 5) / 9 LDAAXave LDAB#(alpd-alpn); (9-5) = 4 MUL; D <-- Xave * 4 LDX#alpd; X <-- 9 IDIV; X <-- (Xave * 4) / 9 TFRX,B; The result of the second term in the equation TFRY,A; The result of the first term in the equation ABA; A <-- (A) + (B) STAAXave; Save the average value. Xave <-- (A) BRALoop SWI

Example – listing file 1: = alpn EQU 5 2: = alpd EQU 9 3: 4: = ORG $0000 5: Xin DS.B 1 6: Xave DS.B 1 7: 8: = ORG $2000 9: 2000 Loop: 10: ; alpha * X (t) 11: LDAA Xin ; A <-- (Xin) 12: 2002 C6 05 LDAB #alpn ; B < : MUL ; D <-- (A) * (B) = (Xin) * 5 14: 2005 CE 0009 LDX #alpd ; X < : IDIV ; X <-- Q( (D)/(X) ), D <-- R( (D)/(X) ) 16: 200A B7 56 TFR X,Y ; Y <-- (Xin * 5) / 9 17: ; (1 - alpha) * Xave (t) 18: ; (1 - 5 / 9) = (9 - 5) / 9 19: 200C LDAA Xave 20: 200E C6 04 LDAB #(alpd-alpn) ; (9-5) = 4 21: MUL ; D <-- Xave * 4 22: 2011 CE 0009 LDX #alpd ; X < : IDIV ; X <-- (Xave * 4) / 9 24: 2016 B7 51 TFR X,B ; The result of the second term in the equation 25: 2018 B7 60 TFR Y,A ; The result of the first term in the equation 26: 201A 1806 ABA ; A <-- (A) + (B) 27: 201C 5A 01 STAA Xave ; Save the average value. Xave <-- (A) 28: 201E 20 E0 BRA Loop 29: F SWI

Shifts LSRx  Logical Shift Right for memory, A, B, or D  Bit shifted out into C CCR bit and 0 shifted in.  Affects all four CCR bits – N always set to 0  Unsigned divide by 2 ASRx  Arithmetic Shift Right for memory, A, B, or D  Bit shifted out into C CCR bit and sign bit replicated.  Affects all four CCR bits  Signed divide by 2 Logical and Arithmetic Right Shift

Shifts ASLx, LSLx  Arithmetic and Logical Shift Left for memory, A, B, or D  Bit shifted out into C CCR bit and 0 shifted in.  Affects all four CCR bits  Unsigned/signed multiply by 2  ASRx is identical with LSLx (same opcodes) Logical and Arithmetic Right Shift

Examples C1 = CodeANZVC A (unsigned)A (signed) LDAA #$C1C ASLA ASLA CodeANZVC A (unsigned)A (signed) LDAA #$C1C ASRAE ASRAF CodeANZVC A (unsigned)A (signed) LDAA #$C1C LSRA LSRA

Rotates RORx, ROLx  Rotate Right/Left for memory, A, or B.  C CCR bit shifted in, bit shifted out goes to C CCR Bit.  Affects all four CCR bits. Rotates are used to extend shift operations to multi-precision numbers.

Example Shift the signed three-byte number in addresses $ $1002 right two bits Shift and Rotate bitsEQU2 numEQU$1000 ORG$2000 LDAB#bits LDXnum again: ASR0, X ROR1, X ROR2, X ; DBNE abdxys, rel9 ;; Decrement Counter and Branch if not 0 ; (cntr) – 1  (cntr) ; if cntr not 0 then Branch DBNEB, again SWI

BCD (Binary Coded Decimal) BCD is a very convenient way of storing numbers that will be sent to external 7-segment displays. In BCD, the hexadecimal number stored in memory looks like the decimal number.  i.e. if $27 appears in a memory location, it will be interpreted as in BCD. DAA (Decimal Adjust A)  DAA instruction corrects the answer. The answer for the addition of 99h + 22h is BB But DAA makes the addition be decimal addition ( = 121). CodeCAA (BCD) LDAA #$99-99 ADDA #$220BBInvalid DAA12121 w/ carry of 1

Questions?

Wrap-up Multiplication and division instructions.  Exponential filter Use shift and rotate instructions  Know difference between arithmetic and logical shift and rotate. What we’ve learned

What to Come Boolean logic instructions