Department of Computer Science and Software Engineering

Slides:



Advertisements
Similar presentations
Machine Instructions Operations
Advertisements

NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.c: Logical Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
Department of Computer Science and Software Engineering
Lecture 4 Basic Instructions Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
80x86 Instruction Set Dr. Qiang Lin.
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.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
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.
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
Practical Session 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.
Microcomputer & Interfacing Lecture 3
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 7:
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
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.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Overview of Assembly Language Chapter 4 S. Dandamudi.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
ECE291 Computer Engineering II Lecture 4 Josh Potts University of Illinois at Urbana- Champaign.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
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.
Arithmetic and Logic Instructions. Outline Declarations Moving data The Flags register Logic instructions Addition & subtraction.
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.
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.
ECE291 Computer Engineering II Lecture 4 Josh Potts University of Illinois at Urbana- Champaign.
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.
CS2422 Assembly Language and System Programming 0 Week 13 & 14 Codes in Assembly Language.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Computer Architecture and Assembly Language
Computer Architecture CST 250
Data Transfers, Addressing, and Arithmetic
Microprocessor Systems Design I
Chapter 3 Bit Operations
Microprocessor Systems Design I
EE3541 Introduction to Microprocessors
Instruction System - Bit Manipulation Instruction
Machine control instruction
Assembly Language Programming Part 2
ADDRESSING MODES.
Overview Introduction General Register Organization Stack Organization
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
UNIT: 2 INSTRUCTION SET OF 8086.
CS-401 Computer Architecture & Assembly Language Programming
Shift & Rotate Instructions)
CET 3510 – Lecture 11 Bit Manipulation in a High-Level Programming Language Dr. José M. Reyes Álamo.
Shift & Rotate Instructions)
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
University of Gujrat Department of Computer Science
Shift, Multiply, and Divide
Chapter 5 Arithmetic and Logic Instructions
Microprocessor and Assembly Language
Computer Organization and Assembly Language
Shift and Rotate Instructions.
CS-401 Computer Architecture & Assembly Language Programming
Presentation transcript:

Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 6 Department of Computer Science and Software Engineering University of Wisconsin-Platteville

Logic instructions NOT, AND, OR, XOR NOT does not modify any flag NOT X ; X = ~X AND X, Y ; X = X & Y OR X, Y ; X = X | Y XOR X, Y ; X = X ^ Y NOT does not modify any flag The other instructions affect C , O, Z, S, P

Bit masking and flipping  Suppose AL = 00101100b Masking: if you only need the lower four bits (i.e. 1100) mov al, 00101100b mov ah, 00001111b and al, ah ; --> now al = 00001100b  Flipping: to flip the middle four bits of AL mov ah, 00111100b xor al, ah ; --> now al = 00010000b

The TEST instruction TEST is a non-destructive version of AND Logically ANDs two operands as AND would Modifies FLAG bits like AND Does not modify the contents of the destination TEST AL,1 sets flags like AND AL,1 but does not modify AL Useful prior to jump instructions

Shift Left Syntax SHL reg, count Result: Count could be immediate or in register value Result: Moves the left operand a bit position to the left as many times as specified by count or CL The empty positions are filled with 0’s The higher order (H.O) bit is stored in the C flag The most efficient way to multiply by 2 C Register SHL

Shift Left: Application Here is a code snippet that counts the number of bits that are “on” (i.e. 1) in the EAX register

Shift Right Syntax SHR reg, count Result: Count could be immediate or in register value Result: Moves the left operand a bit position to the right as many times as specified by count or CL The empty positions are filled with 0’s The lower order (L.O) bit is stored in the C flag The most efficient way to divide by 2 Register C SHR

Shift Arithmetic Right Syntax SAR reg, count Count could be immediate or in register value Result: Moves each bit of the operant one position to the right as many times as specified by count/CL Lower order bit shifts to the carry flag High order bit is replicated Register C SAR

Shift Arithmetic Left This instruction is just a synonym for SHL It is assembled into the exactly the same machine code as SHL

Rotate Through Carry L/R Left: Syntax RCL reg, count Count could be immediate or in register value Rotate bits to the left through the carry flag Bit in the carry flag is written back to bit 0 Right: Syntax RCR reg, count Rotate bits to the right through the carry flag Bit in the carry flag is written back to H.O. bit RCL RCR

Rotate Left/Right Left: Syntax ROL reg, count Count could be immediate or in register value Rotate bits to the left H.O. bit goes to the L.O. bit and the carry flag Right: Syntax ROR reg, count Rotate bits to the right L.O. bit goes to the H.O. bit and the carry flag ROL ROR

Examples mov ax,3 ; Initial register values AX = 0000 0000 0000 0011 mov bx,5 ; BX = 0000 0000 0000 0101 or ax,9 ; ax <- ax | 0000 1001 AX = 0000 0000 0000 1011 and ax,10101010b ; ax <- ax & 1010 1010 AX = 0000 0000 0000 1010 xor ax,0FFh ; ax <- ax ^ 1111 1111 AX = 0000 0000 1111 0101 Neg ax ; ax <- (-ax) AX = 1111 1111 0000 1011 Not ax ; ax <- (~ax) AX = 0000 0000 1111 0100 or ax,1 ; ax <- ax | 0000 0001 AX = 0000 0000 1111 0101 shl ax,1 ; logical shift left by 1 bit AX = 0000 0001 1110 1010 shr ax,1 ; logical shift right by 1 bit AX = 0000 0000 1111 0101 ror ax,1 ; rotate right (LSB=MSB) AX = 1000 0000 0111 1010 rol ax,1 ; rotate left (MSB=LSB) AX = 0000 0000 1111 0101 mov cl,3 ; Use CL to shift 3 bits CL = 0000 0011 shr ax,cl ; Divide AX by 8 AX = 0000 0000 0001 1110 shl bx,cl ; Multiply BX by 8 BX = 0000 0000 0010 1000