Microprocessor and Assembly Language

Slides:



Advertisements
Similar presentations
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Advertisements

1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.c: Logical Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
80x86 Instruction Set Dr. Qiang Lin.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Shift and Rotate Instructions
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
Assembly Language for x86 Processors 6th Edition
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Lecture 05: Assembly Language Programming (2). The 80x86 IBM PC and Compatible Computers Chapter 3 Arithmetic & Logic Instructions and Programs Chapter.
11.1/36 Repeat: From Bits and Pieces Till Strings.
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
Bits and Bytes. BITWISE OPERATORS Recall boolean logical operators in Java… boolean logical operators: &, |, ^ not: ! Show truth tables.
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.
Lecture 4 ( Assembly Language).
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Boolean and Comparison Instructions Operation Description ANDAND Destination, Source OROR Destination, Source XORXOR Destination, Source NOTNOT Destination.
Department of Computer Science and Software Engineering
Lecture 5 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Copyright 2000ELEC 242 Arithmetic Instructions1 Arithmetic Instructions Arithmetic and logical instructions modify the contents of the Flag (Status) register.
Arithmetic Flags and Instructions
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.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Arithmetic and Logic Chapter 5
Introduction to Computer Organization and Assembly Language
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.
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.
Bitwise and Logical Manipulations Assembly Language Programming University of Akron Dr. Tim Margush.
Boolean, Shift and Rotate instructions Dr.Hadi AL Saadi.
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Assembly Language Programming of 8085
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Chapter 3 Bit Operations
Microprocessor Systems Design I
EE3541 Introduction to Microprocessors
Instruction System - Bit Manipulation Instruction
Machine control instruction
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
ECE 353 Introduction to Microprocessor Systems
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Arithmetic and Logic Chapter 5
UNIT: 2 INSTRUCTION SET OF 8086.
Lecture 4 ( Assembly Language).
Microprocessor and Assembly Language
Shift & Rotate Instructions)
University of Gujrat Department of Computer Science
Shift & Rotate Instructions)
Shift, Multiply, and Divide
Arithmetic and Logic Chapter 5
Computer Organization and Assembly Language
CNET 315 Microprocessor & Assembly Language
Shift and Rotate Instructions.
CS-401 Computer Architecture & Assembly Language Programming
Presentation transcript:

Microprocessor and Assembly Language Lecture-9-Bit Manipulation Instructions Muhammad Hafeez Department of Computer Science GC University Lahore

Today’s Agenda Logic Instructions (AND, OR, NOT, XOR) Shift Instructions (SHL, SHR, SAL, SAR) Rotate Instructions (ROL, ROR, RCL, RCR)

Login Instructions Usage To Set Bits To Clear Bits To Examine Bits

AND, OR, XOR Peform Bit-Wise Operations on Operands and store result in destination Sytax AND Destination, Source OR Destination, Source XOR Destination, Source Destination Must be Register or Memory Location Source could be immediate, register or memory location Memory to Memory is not allowed

AND, OR, XOR Affect On Flag Rgister SF, ZF, SF are affected AF is undefined CF, OF=0 (since they operate on bits not on numbers)

Bit Manipulation Using Mask We can selectively modify bits in Destination using bitter pattern called ‘mask’ We use following properties of AND, OR and XOR Y AND 1 = Y, Y AND 0 = 0 Y OR 1 = 1, Y OR 0 =Y Y XOR 1 = ~Y, Y XOR 0 = 1

Bit Encoding and Use of Bit Masks ASCII is a bit encoding of English Character Set, you can develop encoding at your own AND can be used to clear bits, prepare a bit pattern (mask) that has a ‘0’ at particular bit position, set ‘1’ at remaining position to preserve them OR can be used to set bits, prepare a mask that has ‘1’ at particular bit, position, place ‘0’ at other position XOR can be used to complement specific bit, a ‘1’ mask complement, ‘0’ preserve

Examples Prepare following Masks: Clear the Sign of AL=0E5H using AND Instruction Set MSB and LSB and clear other bits in BL=0DFH using OR Change Sign of DL=0FEH using XOR

Use in Assembly Language AND Instruction is used Convert an ASCII Digit to a Number (Its Reverse) Convert an Upper Case Letter to Lower Case (Its Reverse)

Use in Assembly Language AND Instruction is used Convert an ASCII Digit to a Number Bit mask – 0000 1111b – Hex = 0FH AND this mask with Destination (Reg/ Mem) AND AL,0FH (Its Reverse) Convert an Upper Case Letter to Lower Case Bit Mask = 1101 1111d – Clear 5th Bit AND AL, 0DFH (Its Reverse)

Use in Assembly Language XOR Instruction is used Clear a Register/ Memory Location Alternate is MOV AX,0 Or XOR AX,AX In what condition XOR cannot be used? (m/m) OR Instruction OR AL, AL = CMP AL,0 Test a register is zero

Use in Assembly Language NOT Instruction is used To compliments the bits

Test Instruction Just Like CMP to SUB instruction, TEST instruction is the alternate to AND instruction Used to Test specific bits, place in ‘1’ at those positions, does not change destination TEST Destination, mask The result has 1 in tested position, IF, destination has 1’s in those positions, otherwise, result is zero, ZF=1 (if AL is even, even numbers has 0 at 0 position) TEST AL,1 JZ Below ;yes

Test Instruction Just Like CMP to SUB instruction, TEST instruction is the alternate to AND instruction Used to Test specific bits, place in ‘1’ at those positions, does not change destination TEST Destination, mask The result has 1 in tested position, IF, destination has 1’s in those positions, otherwise, result is zero, ZF=1 (if AL is even, even numbers has 0 at 0 position) TEST AL,1 JZ Below ;yes

Shift Instructions Shifts the bits in DESTINATION to Right OR Left, One Place or More Place There are two types of Shift Instruction SHL (Shift Left) SHR (Shift Right) And SAL (Shift Arithmetic Left) SAR (Shift Arithmetic Right)

Shift Instructions There are two formats to write shift instruction Opcode Destination, count OR Opcode Destination, CL SHL/SHR/SAL/SAR REG/MEM , count SHL/SHR/SAL/SAR REG/MEM , CL Count could be immediate value between 0 and 15

Shl Instruction Shift Number of bits to left in the destination A ‘0’ is placed at LSB, MSB is shifted to CF If more than 1 bits to be shifted, place value in CL register

Shl Instruction Affect on Flag SF, PF, ZF reflect the result AF is undefined CF= last bit shifted out OF For multishift OF is undefined For Single Shift OF = 1 if MSB changes after shift

Sal Instruction Due to arithmetic nature of SHL, often SAL is used Both Instructions produces the same result MOV CL,3 SAL AL,CL MULTIPLY AL BY 8

Shr Instruction Perform right shift on destination Format is: SHR Destination, count SHR Destination, 1 SHR Destination, CL A zero is shift at MSB, LSB is shifted to CF

Sar Instruction Equivalent to SHR instruction

Rotate Instructions Shifts the bits within a register or memory location without discard Two types of Rotate Instructions ROL (Rotate Left) ROR (Rotate Right) And RCL (Rotate through Carry Left) RCR (Rotate through Carry Right)

Rotate Instruction Shifts the bits within a register or memory location without discard General Syntax Format ROL/ROR/RCL/RCR REG/MEM , count ROL/ROR/RCL/RCR REG/MEM , CL

Rol Instruction Rotate Left bits are exited from MSB and entered in LSB, as well as, every bit that leave MSB copies itself in CF

Rol Instruction

Ror Instruction Rotate Right bits are exited from LSB and entered in MSB, as well as, every bit that leave LSB copies itself in CF

Rcl Instruction Rotate through Carry Left bits are exited from MSB and entered in CF and from CF entered in LSB, acts as CF is a part of operand

Rcr Instruction Rotate through Carry right bits are exited from LSB and entered in CF and from CF entered in MSB, acts as CF is a part of operand

Application of Shifts and Rotate Instructions Binary Input

Application of Shifts and Rotate Instructions Binary Input

Application of Shifts and Rotate Instructions Binary Output