Embedded System Spring, 2011 Lecture 10: Arithmetic, Logic Instruction and Programs Eng. Wazen M. Shbair.

Slides:



Advertisements
Similar presentations
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Advertisements

MOV Instruction MOV destination, source ; copy source to dest. MOV A,#55H ;load value 55H into reg. A MOV R0,A ;copy contents of A into R0 ;(now A=R0=55H)
Embedded System Spring, 2011 Lecture 9: I/O Programming Eng. Wazen M. Shbair.
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Lecture - 2 Number systems and computer data formats
Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2
By Muhammad Ali Mazidi, Rolin McKinlay, Danny Causey
King Fahd University of Petroleum and Minerals
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
ECE 331 – Digital System Design
ECE 301 – Digital Electronics Number Systems and Conversion, Binary Arithmetic, and Representation of Negative Numbers (Lecture #10) The slides included.
Microprocessor Systems Design I
Lecture – 5 Assembly Language Programming
Embedded System Spring, 2011 Lecture 3: The PIC Microcontrollers Eng. Wazen M. Shbair.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
1.6 Signed Binary Numbers.
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Instruction Set.
Today’s Lecture List the Timers of PIC18 and their associated registers Describe the various modes of the PIC18 timers Program the PIC18 timers in Assembly.
The 8051 Microcontroller and Embedded Systems
Chapter 6 Digital Arithmetic: Operations and Circuits ECE 221 Intro
Binary Arithmetic & Data representation
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
Number Systems ELEC 311 Digital Logic and Circuits Dr. Ron Hayne Images Courtesy of Cengage Learning.
Embedded System Spring, 2011 Lecture 4: The PIC Microcontrollers Eng. Wazen M. Shbair.
ASCII and BCD Arithmetic Chapter 11 S. Dandamudi.
ECE 331 – Digital System Design
Lecture – 4 PIC18 Family Instruction Set 1. Outline Literal instructions. Bit-oriented instructions. Byte-oriented instructions. Program control instructions.
Embedded System Spring, 2011 Lecture 5: The PIC Microcontrollers Eng. Wazen M. Shbair.
PIC – ch. 2b. Move to GPR Move [copy] contents of WREG  GPR/RAM MOVLW99H;WREG=99H MOVWF0H ;move [copy] WREG contents to location 0h … -Cant move literal.
Embedded System Spring, 2011 Lecture 11: Bank Switching Eng. Wazen M. Shbair.
ACOE2511 Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
Today’s Lecture Unconditional branch instruction
ECE 448 – FPGA and ASIC Design with VHDL George Mason University Lab 1 Introduction to Aldec Active HDL Implementing Combinational Logic in VHDL.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
A four function ALU A 00 ADD B MUX SUB 11 Result AND OR
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
CPEN Digital Logic Design Binary Systems Spring 2004 C. Gerousis © Digital Design 3 rd Ed., Mano Prentice Hall.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
Arithmetic and Logic Chapter 5
©2010 Cengage Learning SLIDES FOR CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION Click the mouse to move to the next page. Use the ESC key to exit.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
Embedded System Spring, 2011 Lecture 11: Bank Switching Eng. Wazen M. Shbair.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
Chapter 6. Digital Arithmetic: Operations and Circuits
COMPUTER ARITHMETIC Binary Coded Decimal Presented By Chung Wai Chow.
Unit I From Fundamentals of Logic Design by Roth and Kinney.
Lecture – 5 Assembly Language Programming
Array multiplier TU/e Processor Design 5Z032.
CHAPTER 9 COMPUTER ARITHMETIC - ALU
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Microprocessor Systems Design I
Digital Arithmetic Wen-Hung Liao, Ph.D..
Microprocessor Systems Design I
ECE 3430 – Intro to Microcomputer Systems
PIC – ch. 2b Md. Atiqur Rahman Ahad.
PIC18 CH. 4.
Principles & Applications
Arithmetic and Logic Chapter 5
Arithmetic operations Programming
Chapter 11 © 2011, The McGraw-Hill Companies, Inc.
2’s Complement form 1’s complement form 2’s complement form
Arithmetic and Logic Chapter 5
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
CSC 220: Computer Organization Signed Number Representation
Computer Architecture CST 250
Presentation transcript:

Embedded System Spring, 2011 Lecture 10: Arithmetic, Logic Instruction and Programs Eng. Wazen M. Shbair

2 IUG- Embedded System Today’s Lecture  Arithmetic Instructions  Signed Number Concepts and Arithmetic Operations  Logic and Compare Instructions

3 Arithmetic Instructions  Unsigned numbers are defined as data in which all the bits are used to represent data (no bits are set aside for neg. or pos. sign).  Addition of unsigned numbers ADDLW k ADDWF fileReg, d, a ADDWFC (adding two 16-bit numbers)  What happens to flag register?

4 Addition of unsigned numbers

5 ADDWFC & addition of 16 bit number  When adding two 16-bit data operand, we need to be concerned with the propagation of a carry form lower byte to higher byte.  Multi byte addition vs. individual byte addition ??

6 ADDWFC

7 BCD Number System  We use the digits 0 to 9 in everyday  Binary Coded Decimal (BCD) Unpacked BCD  The lower 4 bits is just used  Requires 1 byte  Ex. ( ) Packed BCD  A single byte has two BCD numbers  Efficient in storing data  Ex. ( )

8 BCD Number System  What is the result if you add 0x17 0x28 0x3F This is not BCD number To convert it to BCD add 6 The result will be : 45

9 DAW, Decimal Adjust WREG  Works only with WREG  Add 6 to the lower or higher nibble if needed.  After execution If the lower nibble is greater than 9, or if DC = 1, add 0110 to the lower nibble. If the upper nibble is greater than 9, or if C =1, add 0110 to the upper nibble.  Doesn’t require the use of arithmetic instructions prior the DAW execution.

10 DAW, Decimal Adjust WREG

11 DAW, Decimal Adjust WREG

12 Subtraction of unsigned numbers  Subtracter circuit is cumbersome. (Why?)  PIC performs the 2’s complement then uses adder circuit to the result.  Take one Clock Cycle.  There are four sub instructions SUBLW k (k – WREG) SUBWF f d ( destination = fileReg – WREG) SUBWFB (subtract with borrow ) SUBFWB (subtract with borrow )

13 Subtraction of unsigned numbers

14

15 Multiplication of unsigned number  PIC supports byte-by-byte multiplication  One of the operand must be in WREG and the other operand is literal K value.  After multiplication, the result is stored in SFR registers PRODH and PRODL (16 bit)

16 Division of unsigned numbers  There is no single instruction for the division of byte/byte numbers.  You need to write a program. Repeated subtraction The numerator is place in a fileReg Denominator is subtracted from it repeatedly The quotient is the number of times we subtracted The reminder is in fileReg upon completion

17 Example

18 Signed Number and Arithmetic Operations  The Most Significant Bit (MSB) is set aside for the sign (+ or -) (0 for positive & 1 for negative)  The rest, 7 bits, are used for the magnitude.  To convert any 7-bit positive number to negative use the 2’s complement.

19 Signed Number  You have 128 negative numbers and 127 positive numbers

20 Signed Number

21 Logic and Compare Instructions  Widely used instructions ANDLW k ANDFW FileReg, d IORLW k IORFW FileReg, d XORLW k XORFW FileReg, d  Effect only Z and N Flags

22 Example

23

24 Complement Instructions  COMF FileReg,d Takes the 1’s complement of a file register Effect only Z and N Flags  NEGF FileReg Takes the 2’s complement of a file register Effect all Flags

25 Compare Instructions

26 Compare Instructions

27 IUG- Embedded System27 References  Jie Hu, ECE692 Embedded Computing Systems, Fall  PIC Microcontroller And Embedded Systems: using Assembly and C for PIC 18, M. Mazidi, R. McKinlay and D. Causey, Prentice Fall,  Eng. Husam Alzaq, Embedded System Course, IUG, 2010