Arithmetic and Logic Chapter 5

Slides:



Advertisements
Similar presentations
Embedded Systems Programming
Advertisements

Ch.3 Representation and Manipulation of Information From Introduction to Embedded Systems: Interfacing to the Freescale 9s12 by Valvano, published by CENGAGE.
Integer Arithmetic: Multiply, Divide, and Bitwise Operations
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Embedded Systems Programming ARM assembler. Creating a binary from assembler source arm=linux-as Assembler Test1.S arm-linux-ld Linker Arm-boot.o Executable.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell 68HC12 Arithmetic Chapter 3.
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
Microcontroller Fundamentals & Programming
AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All.
Assembly Programming on the TI-89 Created By: Adrian Anderson Trevor Swanson.
The 8051 Microcontroller and Embedded Systems
Ch. 7 Logic, Shift and Rotate instr.
Embedded System Spring, 2011 Lecture 10: Arithmetic, Logic Instruction and Programs Eng. Wazen M. Shbair.
CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Introduction to AVR Chapter 1
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
BITWISE OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Unit-2 Instruction Sets, CPUs
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Logic Design Dr. Oliver Faust.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
COMP3221: Microprocessors and Embedded Systems--Lecture 10 1 COMP3221: Microprocessors and Embedded Systems Lecture 10: Shift and Bit-set Instructions.
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
The AVR microcontroller
Microprocessor & Assembly Language
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
ARM Shifts, Multiplies & Divide??. MVN Pseudo Instructions Pseudo Intruction: Supported by assembler, not be hardware.
Universal College Of Engineering & Technology UCET 1/27.
Logical, Shift, Rotate & BCD. What we will learn in this session: Logical instructions. Shift & Rotate instructions. BCD operations. Bit operations.
“ INSTRUCTIONS SET OF AVR MICROCONTROLLER ” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Abhishek Lakhara
Microprocessor Systems Design I
COMP3221: Microprocessors and Embedded Systems
Arithmetic and Logic Chapter 5
68000 Arithmetic Instructions
The 8051 Assembly Language Arithmetic & Logic Instructions
Chapter 11 © 2011, The McGraw-Hill Companies, Inc.
MISP Assembly.
Addressing Modes Register Direct, with 1 and 2 registers I/O Direct
Topic 6: Bitwise Instructions
Shift & Rotate Instructions)
Logical Operations In some applications it is necessary to manipulate other sizes of data, or perhaps only individual bits. There are instructions that.
Multiplication by small constants (pp. 139 – 140)
Shift & Rotate Instructions)
C1 Number systems.
Arithmetic and Logic Chapter 5
Table 3‑1: Unsigned Data Range Summary in ARM
The ARM Instruction Set
March 2006 Saeid Nooshabadi
Branching instructions
Overheads for Computers as Components 2nd ed.
Chapter 5 Arithmetic and Logic Instructions
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Microprocessor and Assembly Language
Immediate data Immediate operands : ADD r3, r3, #1 valid ADD r3, #1,#2 invalid ADD #3, r1,r2 invalid ADD r3, r2, #&FF ( to represent hexadecimal immediate.
MIPS Arithmetic and Logic Instructions
Shift and Rotate Instructions.
Arithmetic and Logic Chapter 3
Presentation transcript:

Arithmetic and Logic Chapter 5 The AVR microcontroller and embedded systems using assembly and c

Objectives The concept of signed numbers and 2’complement Addition and subtraction instructions Carry and overflow Logical instruction and masking Compare instruction and branching Shift, Rotate and Data serialization BCD, Packed BCD and ASCII conversion.

Some ideas 100 – 34 = ? 99 – 34 = ? 100 – 34 = (99-34) + 1 34 – 19 = ? 34 +100 -19 – 100 = 34 + (99-19)+1 -100

100000000 – 00101101 = ? =011111111 – 00101101 + 1 =A 010110110 – 00101101 = 010110110 + A – 100000000 =

ADD instructions ADD Rd,Rr ;Rd = Rd + Rr ( Direct or immediate are not supported)

ADD instructions ADD Rd,Rr ;Rd = Rd + Rr ( Direct or immediate are not supported)

ADC instructions

SUB instruction SUB Rd,Rr ;Rd = Rd - Rr ( immediate are not supported) SUB Rd,Rr ; Rd = Rd – K

SBC instruction 27 62 (H) - 11 96 (H) ----------- 11 CC (H) SBC Rd,Rr ;Rd = Rd – Rr-C ( immediate are not supported) SBIc Rd,Rr ;Rd = Rd – K-C 27 62 (H) - 11 96 (H) ----------- 11 CC (H)

Multiplication and Division

Logic Instructions AND Rd,Rr ;Rd = Rd AND Rr OR Rd,Rr ;Rd = Rd OR Rr EOR Rd,Rr ;Rd = Rd XOR Rr ( immediate are not supported) COM Rd,Rr ;Rd = 1’ Complement of Rd (11111111 – Rd) NEG Rd,Rr ;Rd = 2’ Complement of Rd (100000000 – Rd) AND is used to clear an specific bit/s of a byte OR is used to set an specific bit/s of a byte

Setting and Clearing bits AND Rd,Rr ;Rd = Rd AND Rr OR Rd,Rr ;Rd = Rd OR Rr EOR Rd,Rr ;Rd = Rd XOR Rr ( immediate are not supported) COM Rd,Rr ;Rd = 1’ Complement of Rd (11111111 – Rd) NEG Rd,Rr ;Rd = 2’ Complement of Rd (100000000 – Rd) AND is used to clear an specific bit/s of a byte OR is used to set an specific bit/s of a byte AND OR

Branch and CP Instructions CP Rd,Rr ;Rd – Rr (only flags are set) BRVC is used to branch when oVerflow is clear to zero BRVS is used to branch when oVerflow is set to one

ROR instruction ROR Rd ;Rd (only flags are set) In ROR, as bits are rotated from left to right, the carry flag enters the MSB and the LSB exits to the carry flag. In other words, in ROR the C is moved to the MSB, and the LSB is moved to the C. See what happens to 0010 0110 after running 3 ROR instructions: CLC ;make C = 0 (carry is 0 ) LDI R20 , 0x26 ;R20 = 0010 0110 ROR R20 ;R20 = 0001 0011 C = 0 ROR R20 ;R20 = 0000 1001 C = 1 ROR R20 ;R20 = 1000 0100 C = 1

ROL instruction ROR Rd ;Rd (only flags are set) ROL. In ROL, as bits are shifted from right to left, the carry flag enters the LSB and the MSB exits to the carry flag. In other words, in ROL the C is moved to the LSB, and the MSB is moved to the C. SEC ;make C = 1 (carry is 0) LDI R20,0x15 ;R20 = 0001 0101 ROL R20 ;R20 = 0010 1011 C = 0 ROL R20 ;R20 = 0101 0110 C = 0 ROL R20 ;R20 = 1010 1100 C = 0 ROL R20 ;R20 = 0101 1000 C = 1

LSL instruction LSL Rd ;logical shift left In LSL, as bits are shifted from right to left, 0 enters the LSB and the MSB exits to the carry flag. In other words, in LSL 0 is moved to the LSB, and the MSB is moved to the C. this instruction multiplies content of the register by 2 assuming that after LSL the carry flag is not set. In the next code you can see what happens to 00100110 after running 3 LSL instructions. CLC ;make C = 0 (carry is 0 ) LDI R20 , 0x26 ;R20 = 0010 0110(38) c = 0 LSL R20 ;R20 = 0100 1100(74) C = 0 LSL R20 ;R20 = 1001 1000(148) C = 0 LSL R20 ;R20 = 0011 0000(98) C = 1 as C=1 and content of R20 ;is not multiplied by 2

ROR instruction In LSR, as bits are shifted from left to ROR Rd ;Rd (only flags are set) In LSR, as bits are shifted from left to right, 0 enters the MSB and the LSB exits to the carry flag. In other words, in LSR 0 is moved to the MSB, and the LSB is moved to the C. this instruction divides content of the register by 2 and carry flag contains the remainder of division. In the next code you can see what happens to 0010 0110 after running 3 LSL instructions. LDI R20,0x26 ;R20 = 0010 0110 (38) LSR R20 ;R20 = 0001 0011 (19) C = 0 LSR R20 ;R20 = 0000 1001 (9) C = 1 LSR R20 ;R20 = 0000 0100 (4) C = 1

ASR Instruction ASR means arithmetic shift right. ASR ROR Rd ;Rd (only flags are set) ASR means arithmetic shift right. ASR instruction can divide signed number by 2. In LSR, as bits are shifted from left to right, MSB is held constant and the LSB exits to the carry flag. In other words MSB is not changed but is copied to D6, D6 is moved to D5, D5 is moved to D4 and so on. In the next code you can see what happens to 0010 0110 after running 5 ASL instructions. LDI R20 , 0D60 ;R20 = 1101 0000(-48) c = 0 LSL R20 ;R20 = 1110 1000(-24) C = 0 LSL R20 ;R20 = 1111 0100(-12) C = 0 LSL R20 ;R20 = 1111 1010(-6) C = 0 LSL R20 ;R20 = 1111 1101(-3) C = 0 LSL R20 ;R20 = 1111 1110(-1) C = 1

BCD, Packed BCD and ASCII conversion. ASCII Codes BCD BCD Codes Packed BCD BCD1 BCD0 ASCII and BCD Codes for Digits 0–9

Packed BCD to ASCII conversion To convert packed BCD to ASCII: you must first convert it to unpacked BCD. Then the unpacked BCD is tagged with 011 0000 (30H). Packed BCD = 1001 0010 Un packed BCD = 0000 1001 , 0000 0010 ACSII = 0011 1001 , 0011 0010