Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.

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,
Computer Organization & Assembly Language
80x86 Instruction Set Dr. Qiang Lin.
Introduction to Assembly Here we have a brief introduction to IBM PC Assembly Language –CISC instruction set –Special purpose register set –8 and 16 bit.
Assembly 02. Outline mov Command Registers Memory EFLAGS Arithmetic 1.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
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.
Practical Session 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.
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.
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.
11.1/36 Repeat: From Bits and Pieces Till Strings.
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.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Department of Computer Science and Software Engineering
Logic Conditional Processing. Status flags - review The Zero flag is set when the result of an operation equals zero. The Carry flag is set when an instruction.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly 03. Outline inc, dec movsx jmp, jnz Assembly Code Sections Labels String Variables equ $ Token 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.
Assembly 06. Outline cmp (review) Jump commands test mnemonic bt mnemonic Addressing 1.
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.
CSC 3210 Computer Organization and Programming
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
Microprocessor Systems Design I
Practical Session 2.
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
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
UNIT: 2 INSTRUCTION SET OF 8086.
Practical Session 2.
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
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:

Assembly 05

Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1

Bit Mapping Assign special meaning to individual bits within bytes E.g., EFLAGS register 2

Bit Mapping Bit numbering starts at 0 for LSB, starts on right side Bit number increases going right to left 3 bit 0 bit number increases

Bit Mapping Many x86 instructions to manipulate individual bits Bitwise logical operations: and, or, xor, not Bit-shifting operations: shl, shr, … Bit rotation operations: ror, rol, … 4

Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 5

Boolean Logic (review) Logical operations AND, OR, XOR, NOT Same logic as before (with gates) Compare individual bits… 6

Boolean Logic (review) For bitwise logical operations, each pair of bits get evaluated AND

Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 8

Bitwise Logic Mnemonics 9 andxor notor

and Mnemonic and -> logical AND two operands and al, bl;AND two 8-bit values, store in al and ax, bx;AND two 16-bit values, store in ax and eax, ebx; AND two 32-bit values, store in eax 10

and Mnemonic mov al, b; mov bl, b; and al, bl; 11 Note that you can input binary numbers directly… al bl

and Mnemonic mov al, b; mov bl, b; and al, bl; al bl

and Mnemonic mov al, b; mov bl, b; and al, bl; al bl

and Mnemonic mov al, b; mov bl, b; and al, bl; al bl

or Mnemonic or->logical OR two operands or al, bl;OR two 8-bit values, store in al or ax, bx;OR two 16-bit values, store in ax or eax, ebx; OR two 32-bit values, store in eax 15

or Mnemonic mov al, b; mov bl, b; or al, bl; 16 al bl

or Mnemonic mov al, b; mov bl, b; or al, bl; al bl

or Mnemonic mov al, b; mov bl, b; or al, bl; al bl

or Mnemonic mov al, b; mov bl, b; or al, bl; al bl

xor Mnemonic xor->logical XOR between two operands or al, bl;XOR two 8-bit values, store in al or ax, bx;XOR two 16-bit values, store in ax or eax, ebx; XOR two 32-bit values, store in eax 20

xor Mnemonic mov al, b; mov bl, b; xor al, bl; 21 al bl

xor Mnemonic mov al, b; mov bl, b; xor al, bl; al bl

xor Mnemonic mov al, b; mov bl, b; xor al, bl; al bl

xor Mnemonic mov al, b; mov bl, b; xor al, bl; al bl

not Mnemonic not->logical NOT on single operand not al; NOT the 8-bit value, store in al not ax; NOT the 16-bit value, store in ax not eax; NOT the 32-bit value, store in eax 25

not Mnemonic mov al, b; not al; 26 al

not Mnemonic mov al, b; not al; al

not Mnemonic mov al, b; not al; al

Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 29

Bit Masking Bit mask : used to isolate certain bits Use and instruction to mask bits Set unwanted bits to 0 Allows wanted bits to “pass through” 30

Bit Masking Example: isolate bits #4 and #5 mov al, b;value to inspect mov bl, b;bit mask and al, bl;isolate bits 31

Bit Masking Example: isolate bits #4 and # valuemaskresult LSB MSB AND=

Bit Masking Example: isolate bits #4 and # valuemaskresult LSB MSB mask allows two bits to “pass through”

Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 34

Bit Shifting Shift bits to left or right Shift left => multiply by powers of 2 Shift right => divide by powers of 2 “New” bits are set to 0 (zero padding) Bits can “fall off” the left or right Bits that “fall off” are lost If you bump a 1 off the left side, carry flag (CF) will be set Numbers shifted as binary, not decimal or hex 35

Bit Shifting Example: Shift Left 1 Unit zero padding MSB “falls off”

Bit Shifting Example: Shift Right 3 Units these bits “fall off” “new” bits zero padded

Bit Shifting shl-> shift left shl, 38 register or memory always cl register or immediate value

Bit Shifting mov al, b; mov cl, 4; shl al, cl; 39 al cl

Bit Shifting mov al, b; mov cl, 4; shl al, cl; al cl

Bit Shifting mov al, b; mov cl, 4; shl al, cl; al cl

Bit Shifting mov al, b; mov cl, 4; shl al, cl; al cl

Bit Shifting shr-> shift right shr, 43 register or memory always cl register or immediate value

Bit Shifting x: db b; declare x in.data section. shr byte [x], 3;shift [x] right 3 places ;(in.text section) 44

Bit Shifting x: db b shr byte [x], x:

Bit Shifting x: db b shr byte [x], x:

Bit Shifting (Rotate) Bits that “fall off” appear at other end E.g., rotate left by 3:

Bit Shifting (Rotate) rol-> rotate left rol, 48 register or memory always cl register or immediate value

Bit Shifting (Rotate) ror-> rotate right ror, 49 register or memory always cl register or immediate value

Bit Shifting (Rotate) mov al, b; rol al, 1; 50 al ? CFCF

Bit Shifting (Rotate) mov al, b; rol al, 1; al ? CFCF

Bit Shifting (Rotate) mov al, b; rol al, 1; al 1 CFCF CF set

Bit Shifting (Rotate) rcl-> rotate left w/ carry flag (CF) - CF used as “extra” bit rcl, 53 register or memory always cl register or immediate value

Bit Shifting (Rotate) rcr-> rotate right w/ carry flag (CF) - CF used as “extra” bit rcr, 54 register or memory always cl register or immediate value

Bit Shifting (Rotate) E.g., rotate left 1 with carry (rcl) CFCF CFCF

Set / Clear Carry Flag (CF) How to manually clear or set CF? clc -> clear CF (takes no operands) stc -> set CF (takes no operands) 56

Bit Shifting (Rotate) mov al, 0; mov bl, 0; stc; rcl al,1; stc; rcr bl,1; 57 al ? CFCF bl

Bit Shifting (Rotate) mov al, 0; mov bl, 0; stc; rcl al,1; stc; rcr bl,1; 58 0 al ? CFCF bl

Bit Shifting (Rotate) mov al, 0; mov bl, 0; stc; rcl al,1; stc; rcr bl,1; 59 0 al ? CFCF 0 bl

Bit Shifting (Rotate) mov al, 0; mov bl, 0; stc; rcl al,1; stc; rcr bl,1; 60 0 al 1 CFCF 0 bl CF set

Bit Shifting (Rotate) mov al, 0; mov bl, 0; stc; rcl al,1; stc; rcr bl,1; al 0 CFCF 0 bl

Bit Shifting (Rotate) mov al, 0; mov bl, 0; stc; rcl al,1; stc; rcr bl,1; al 1 CFCF 0 bl

Bit Shifting (Rotate) mov al, 0; mov bl, 0; stc; rcl al,1; stc; rcr bl,1; al 0 CFCF bl

Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 64

Lookup Table Basically an array Declared / initialized in.data section Commas to separate array items Data access is NOT : array[ index ] Data access IS : [ array + index ] “array” is declared label name “index” is index into the array (either immediate value OR 32-bit register) 65

Lookup Table digits: db 8,6,7,5,3,0,9 ;declared in.data mov al, [digits]; mov bl, [digits + 4]; mov [digits + 6], bl; 66

Lookup Table digits: db 8,6,7,5,3,0,9 mov al, [digits]; mov bl, [digits + 4]; mov [digits + 6], bl; 67 al bl digits: index

Lookup Table digits: db 8,6,7,5,3,0,9 mov al, [digits]; mov bl, [digits + 4]; mov [digits + 6], bl; 68 al bl digits: index

Lookup Table digits: db 8,6,7,5,3,0,9 mov al, [digits]; mov bl, [digits + 4]; mov [digits + 6], bl; 69 8 al bl digits: index

Lookup Table digits: db 8,6,7,5,3,0,9 mov al, [digits]; mov bl, [digits + 4]; mov [digits + 6], bl; 70 8 al 3 bl digits: index

Lookup Table digits: db 8,6,7,5,3,0,9 mov al, [digits]; mov bl, [digits + 4]; mov [digits + 6], bl; 71 8 al 3 bl digits: index