Logical, Shift, and Rotate Operations CS208. Logical, Shift and Rotate Operations  A particular bit, or set of bits, within the byte can be set to 1.

Slides:



Advertisements
Similar presentations
Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Advertisements

Machine Instructions Operations
Machine Instructions Operations 1 ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-1.ppt Modification date: March 18, 2015.
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.c: Logical Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
Computer Organization & Assembly Language
Logical and Shift operations A particular bit, or set of bits, within the byte is set to 1 or 0 depending on conditions encountered during the execution.
Assembly Language and Computer Architecture Using C++ and Java
Ch. 7 Bitwise Operations Comp Sci Bitwise operations.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Binary Operations Math/Logical. Binary Math Decimal Addition Example ) Add = 15 Write down 5, carry ) Add 3 +
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
Numbering systems.
Lecture 18: Datapath Functional Units
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
1 Programming in Machine Language SCSC 311 Spring 2011.
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.
Operations on Bits Arithmetic Operations Logic Operations
Lecture12. Outline Binary representation of integer numbers Operations on bits –The Bitwise AND Operator –The Bitwise Inclusive-OR Operator –The Bitwise.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Department of Computer Science and Software Engineering
BITWISE OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Bit Operations Horton pp Why we need to work with bits Sometimes one bit is enough to store your data: say the gender of the student (e.g. 0.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
Logical and Bit Operations Chapter 9 S. Dandamudi.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
WEEK 4 ET2640 Logic and Numerical Methods 1ET2640.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
1 Sec (2.4) Arithmetic / logic instruction:. 2 Logical operations: Ex: XOR OR AND
Microprocessor & Assembly Language
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Chapter four – The 80x86 Instruction Set Principles of Microcomputers 2016年3月17日 2016年3月17日 2016年3月17日 2016年3月17日 2016年3月17日 2016年3月17日 1 Chapter Four.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
CS2422 Assembly Language and System Programming 0 Week 13 & 14 Codes in Assembly Language.
Chapter 4 Operations on Bits.
Programming in Machine Language
Data Representation in Computer Systems
Microprocessor Systems Design I
Bit Operations Horton pp
Chapter 3 Bit Operations
Instruction System - Bit Manipulation Instruction
Machine control instruction
Assembly Language Programming Part 2
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Computer Organization and Design
CS-401 Computer Architecture & Assembly Language Programming
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.
Shift & Rotate Instructions)
Shift, Multiply, and Divide
The ARM Instruction Set
Bitwise Operators.
Module 10 Operations on Bits
Microprocessor and Assembly Language
Computer Organization 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.
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Shift and Rotate Instructions.
Bit Manipulations CS212.
CS-401 Computer Architecture & Assembly Language Programming
Bit Operations Horton pp
CS 111 – Sept. 16 Machine language examples Instruction execution
Presentation transcript:

Logical, Shift, and Rotate Operations CS208

Logical, Shift and Rotate Operations  A particular bit, or set of bits, within the byte can be set to 1 or 0, depending on conditions encountered during the execution of a program.  When so used, these bits are often called "flags".  Frequently, the programmer must manipulate these individual bits - an activity sometimes known as "bit twiddling".  The logical, shift, and rotate operations provide the means for manipulating the bits.

Logical OR Rules OR Operations OR Results in 1 if either or both of the operands are 1. OR Table 0 OR 0 = 0 0 OR 1 = 1 1 OR 0 = 1 1 OR 1 = 1

Logical OR Operation To perform the OR operation, take one column at a time and perform the OR operation using the OR table. Ex 1: OR

Logical OR Examples Ex 3: OR Ex 2: OR

Logical XOR Rules XOR Operations The exclusive OR. Similar to OR except that it now gives 0 when both its operands are 1. Rules. 0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0

Logical XOR Examples Ex 1: XOR Ex 2: XOR

Logical AND Rules AND Operations AND yields 1 only if both its operands are 1. Rules. 0 AND 0 = 0 0 AND 1 = 0 1 AND 0 = 0 1 AND 1 = 1

Logical AND Examples Ex 1: AND Ex 2: AND

Logical NOT NOT Operations NOT is a separate operator for flipping the bits. Rules. NOT 0 = 1 NOT 1 = 0 Example.NOT =

Logical Operations – Try It Yourself Complete the following exercises: OR AND XOR NOT = (Answers on next slide)

Answers OR  AND  XOR  NOT 

Shift and Rotate operations Whereas logical operations allow the changing of bit values in place, SHIFT and ROTATE operations allow bits to be moved left or right without changing their values.

Shift Left operation SHL SHL (shift left) shifts each bit one place to the left. The original leftmost bit is lost and a 0 is shifted into the rightmost position. Ex 1.SHL Ex 2.SHL = =

Shift Left - Multiple Bits SHL # bits means to shift left # times Ex 1: SHL Ex 2: SHL = =

Shift Right operation SHR SHR (shift right) shifts each bit one place to the right. The original rightmost bit is lost and a 0 is shifted into the leftmost position. Ex 1.SHR Ex 2.SHR = =

Shift Right – Multiple Bits SHR # bits means to shift right # times Ex 1: SHR = Ex 2: SHR =

Arithmetic Shift Right operation ASR (retains rightmost sign bit) Shifts each bit one place to the right. The original rightmost bit is lost and a the value of the most significant bit (leftmost bit) is shifted into the new leftmost position. Ex 1.ASR Ex 2.ASR = =

Arithmetic Shift Right – Multiple Bits ASR # bits means to arithmetic shift right # times Ex 1: ASR = Ex 2: ASR =

Shift Operations – Try It Yourself Complete the following exercises: a. Given , what will the value be after a left shift? b. Given hexadecimal value AF, what will the hexadecimal value be after a right shift of 3 places? c. How would the answer to (b) differ if the shift was an arithmetic shift? ( Answers on next slide)

Answers a) SHL  b) AF 16  SHR 3   c) AF 16  ASR  F5 16

Rotate Left operation ROL ROL (rotate left) shifts each bit one place to the left. The original leftmost bit is shifted into the rightmost position. No bits are lost. Ex 1.ROL Ex 2. ROL =

Rotate Left – Multiple Bits ROL # bits means to rotate left # times Ex 1: ROL = Ex 2: ROL =

Rotate Right operation ROR ROR (rotate right) shifts each bit one place to the right. The original rightmost bit is shifted into the leftmost position. No bits are lost. Ex 1.ROR Ex 2.ROR =

Rotate Right – Multiple Bits ROR # bits means to rotate right # times Ex 1: ROR = Ex 2: ROR =

Rotate Operations – Try It Yourself Complete the following exercises: a. Given , what will the value be after a left rotation? b. Given hexadecimal value 2E, what will the hexadecimal value be after a left rotation of 5 places? c. How would the answer to (b) differ if the rotation was a right rotation? (Answers on next slide)

Answers a) ROL  b) 2E 16  ROL 5   C5 16 c) 2E 16  ROR 5   71 16