Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A

Similar documents
Microprocessor & Computer Architecture / Lecture

Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H.

8086 Programming. Multiplication Instructions. Multiplication can be performed on signed and unsigned numbers.

Chapter 5. Real-Mode 80386DX Microprocessor Programming 1 Part 2. The 80386, 80486, and Prentium Processors,Triebel Prof. Yan Luo, UMass Lowell 1

Lecture 9. INC and DEC. INC/DEC Examples ADD. ADD Examples SUB. INC adds one to a single operand DEC decrements one from a single operand

Arithmetic and Logic Instructions And Programs

Arithmetic Instructions

Introduction to 8086 Assembly

Week /8086 Microprocessor Programming I

Lecture (08) x86 programming 7

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100

8086 INTERNAL ARCHITECTURE

Lab Session 08. To understand the use of Shift and Rotate instructions. To be able to differentiate between Arithmetic shift and Logical shift.

Signed number Arithmetic. Negative number is represented as

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

Bit Operations. Ned Nedialkov. McMaster University Canada. SE 3F03 February 2014

Logical and Bit Operations. Chapter 8 S. Dandamudi

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

Instructions moving data

Shift and Rotate Instructions

8088/8086 Programming Integer Instructions and Computations

Kingdom of Saudi Arabia Ministry of Higher Education. Taif University. Faculty of Computers & Information Systems

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Chapter 12. Selected Pentium Instructions

Q1: Multiple choice / 20 Q2: Protected mode memory accesses

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic

International Islamic University Chittagong (IIUC) Department of Electrical and Electronic Engineering (EEE)

EEM336 Microprocessors I. Arithmetic and Logic Instructions

Computer Department Chapter 7. Created By: Eng. Ahmed M. Ayash Modified and Presented by: Eng. Eihab S. El-Radie. Chapter 7

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

Code segment Stack segment

EC 333 Microprocessor and Interfacing Techniques (3+1)

Intel 8086: Instruction Set

Basic Pentium Instructions. October 18

Week /8086 Microprocessor Programming II

16.317: Microprocessor Systems Design I Fall 2013

Basic Assembly SYSC-3006

8086 INSTRUCTION SET

Logical and bit operations

EECE.3170: Microprocessor Systems Design I Spring 2016

Section 001 & 002. Read this before starting!

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION 80x86 Instructions

Section 001. Read this before starting!

Data Movement Instructions

Integer Arithmetic. Shift and rotate. Overview. Shift and Rotate Instructions

CMSC 313 Lecture 07. Short vs Near Jumps Logical (bit manipulation) Instructions AND, OR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, RCR

Program controlled semiconductor device (IC) which fetches (from memory), decodes and executes instructions.

Defining and Using Simple Data Types

16.317: Microprocessor Systems Design I Spring 2014

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

CS220 Logic Design AS06-Advanced Assembly. AS06-Advanced Assembly Shift Operations. AS06-Advanced Assembly Shift Operations

CS241 Computer Organization Spring 2015 IA

Week /8086 Microprocessor Programming

CS-202 Microprocessor and Assembly Language

Integer Arithmetic. Pu-Jen Cheng. Adapted from the slides prepared by Kip Irvine for the book, Assembly Language for Intel-Based Computers, 5th Ed.

Addressing Modes on the x86

Chapter 7 Integer Arithmetic

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

Assembly Language Each statement in an assembly language program consists of four parts or fields.

CS401 Assembly Language Solved MCQS From Midterm Papers

CSC 8400: Computer Systems. Machine-Level Representation of Programs

Chapter Four Instructions Set

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)


Computer Architecture and Assembly Language. Practical Session 3

Q1: Multiple choice / 20 Q2: Data transfers and memory addressing

b) List the 16 Bit register pairs of 8085?(Any 2 pair, 1 Mark each) 2M Ans: The valid 16 bit register pair of 8085 are

Intel 8086 MICROPROCESSOR ARCHITECTURE

1-Operand instruction types 1 INC/ DEC/ NOT/NEG R/M. 2 PUSH/ POP R16/M16/SR/F 2 x ( ) = 74 opcodes 3 MUL/ IMUL/ DIV/ DIV R/M

Mnem. Meaning Format Operation Flags affected ADD Addition ADD D,S (D) (S)+(D) (CF) Carry ADC Add with ADC D,C (D) (S)+(D)+(CF) O,S,Z,A,P,C

Assignment no:4 on chapter no :3 : Instruction set of 8086

MICROPROCESSOR TECHNOLOGY

1. Introduction to Assembly Language

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU

Basic characteristics & features of 8086 Microprocessor Dr. M. Hebaishy

Lesson 1. Fundamentals of assembly language

Integer Arithmetic. Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/17. with slides by Kip Irvine

EXPERIMENT - 1: ADDITION & SUBTRACTION

Alexandria University Faculty of Engineering Communications and Computers SSP

Read this before starting!

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

Chapter 3: Addressing Modes

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide

EC-333 Microprocessor and Interfacing Techniques

Computer Architecture and Assembly Language Programming CS401 Lecture No: 1 Address, Data, and Control Buses A computer system comprises of a

/ 30 Q3: Arithmetic instructions / 30 Q4: Logical instructions / 20 TOTAL SCORE / 100 Q5: EXTRA CREDIT / 10

APPENDIX C INSTRUCTION SET DESCRIPTIONS

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

COMPUTER ENGINEERING DEPARTMENT

Intel 8086 MICROPROCESSOR. By Y V S Murthy

CMSC 313 Lecture 05 [draft]

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

3.1 DATA MOVEMENT INSTRUCTIONS 45

Overview COMP 3221 Bitwise Logical Operations

Lab 3. The Art of Assembly Language (II)

Computer Architecture 1 ح 303

CS401 - Computer Architecture and Assembly Language Programming Glossary By

Transcription:

Segment 4A Logic Instructions Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Course Instructor Mohammed Abdul kader Lecturer, EEE, IIUC

Basic Logic Instructions AND OR Exclusive OR (XOR) NOT TEST NEG AND Instruction AND operation performs logical Multiplication. The AND operation clears bits of a binary number. The task of clearing a bit in a binary number is called masking. AND instruction uses any addressing mode except memory to memory and segment register addressing. Example: AND AL, BL AND AX, [DI] 2

OR Instruction Basic Logic Instructions (Continued) OR operation performs logical addition and is often called the Inclusive-OR function OR instruction is used to set bit of a unknown binary number. Example: OR AH, BL ; AH= AH or BL OR DX, [BX] ; DX is Ored with the word contents of data segment memory location addressed by BX 3

Exclusive-OR Instruction Basic Logic Instructions (Continued) The exclusive-or instruction produces 1 when input logics are different otherwise it produces 0. Because of this Exclusive-OR is sometimes called a comparator. The exclusive-or instruction is useful if some bits of a register or memory location must be inverted without changing the other bits. Example: XOR CH, DL ; CH= CH xor DL XOR DX, [SI] ; DX is exclusive-ored with the word content of the data segment memory location addressed by SI. 4

Problem: Basic Logic Instructions (Continued) Develop a short sequence of instructions that sets the rightmost five bits, invert leftmost three bits and clear middle four bits of DI without changing the remaining three bits of DI. Save the result in SI. Solution: invert clear set b15 b14 b13 b12 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b2 B0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 XOR with E000H to invert 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 AND with FC3FH to clear 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 OR with 001FH to set XOR DI, E000H ; invert leftmost three bits AND DI, FC3FH ; clear middle three bits OR DI, 001FH ; set rightmost five bits MOV SI, DI ; save result in SI 5

TEST Instruction Basic Logic Instructions (Continued) TEST instruction performs the AND operation. The difference is that the AND instruction changes the destination operand, whereas the TEST instruction does not. The TEST instruction functions in the manner as a CMP instruction. The difference is that the TEST instruction normally a single bit, whereas the CMP instruction tests the entire byte or, word. It only changes zero flag (Z) bit. The zero flag (Z) is a logic 1 (indicating a zero result) if the bit under test is a zero and Z=0 (indicating a nonzero result) if the bit under test is not zero. Usually the TEST instruction is followed by either the JZ (jump if result zero, Z=1) or, JNZ (jump if result not zero, Z=0) instruction. Example: TEST DL, DH ; DL is ANDed with DH. TEST AH, 4 ; AH is ANDed with 4. Problem: (a) Write an instruction set to test the rightmost and leftmost bit position of AL register. The program should jumps to the operand address RIGHT if right most bit of AL is set and jumps to the address LEFT if leftmost bit of AL is set. 6

NOT Basic Logic Instructions (Continued) NOT instruction performs logical inversion (invert all bits of a byte or word) or find the one s complement. Example: NOT CH ; CH is one s complemented NOT BYTE PTR[BX] ; The byte contents of data segment memory location addressed by BX are one s complemented. NEG NEG instruction performs arithmetic sign inversion or, the two s complement. The arithmetic sign of a signed number changes from positive to negative or from negative to positive by NEG instruction. Example: NEG CH ; CH is two s complemented. NEG AX; AX is two s complemented. 7

SHIFT and ROTATE instructions SHIFT and ROTATE instructions are used to shift or rotate any memory data or register. The instructions mostly use to control I/O devices. SHIFT Instruction Shift instructions position or move numbers to the left or right within a register or memory location. They also perform simple arithmetic such as multiplication by powers of 2 +n (left shift) and division by powers of 2 n right shift. The microprocessor instruction set contains four different shift instruction. Two logical shift : (a) Shift operand bits left (SHL) (b) Shift operand bits right (SHR) Two arithmetic shift: (c) Shift arithmetic Left (SAL) (d) Shift arithmetic Right (SAR) Logical shifts (SHL and SHR): The logical shifts move a zero into the rightmost bit position for a logical left shift and a 0 into the leftmost bit position for a logical right shift. MSB is shifted to CF in case of SHL and LSB shifted to CF in case of SHR. 8

SHIFT and ROTATE instructions (continued) Arithmetic shifts (SAL and SAR): The arithmetic left shift and logical left shift are identical. The arithmetic right shift and logical right shift are different because the arithmetic right shift copies the sign bit through the numbers, where as logical right shift copies a 0 through the numbers. Logical VS arithmetic shift: Logical shift operations function with unsigned numbers and arithmetic shifts function with signed numbers. Logical shifts multiply or divide unsigned data, and arithmetic shifts multiply or divide signed data. 9

SHIFT and ROTATE instructions (continued) Two different modes used in shift counting: One modes uses an immediate shift count and other uses register CL to hold the shift count. Note that CL must hold the shift count. Example: SHL AX, 1 ; AX is logically shifted left 1 place. SHR BX, 12 ; BX is logically shifted right 12 places (12 times) SAR SI, 2 ; SI is arithmetically shifted right 2 places. SAL DATA, CL ; The contents of data segment memory location DATA are arithmetically shifted left the number of spaces specified by CL. Division by SHIFT instructions: A shift right always divides by 2 for each bit position shifted. Two times right shifting divides by 4. For n times right shift the number is divided by 2 n. Multiplication by SHIFT instructions: A shift left always multiplies by 2 for each bit position shifted. Two times left shifting multiplies by 4. For n times left shift the number is multiplied by 2 n. 10

ROTATE instruction SHIFT and ROTATE instructions (continued) Rotate instructions position binary data by rotating the information in a register or memory location, either from one end to another or through the carry flag. There are four available rotate instructions: Rotate through carry left (RCL) Rotate out of carry left (ROL) Rotate through carry right (RCR) Rotate out of carry right (ROR) 11

ROTATE instruction (Continued) SHIFT and ROTATE instructions (continued) A rotate count can be immediate or located in register CL. Example: ROL SI, 14 ; SI rotates left (out of carry) 14 places. RCL BL, 6 ; BL rotates left through carry 6 places. RCR AH, CL ; AH rotates right through carry the number of places specified by CL. ROR WORD PTR[BP], 2 ; The word contents of the stack segment memory location addressed by BP rotate right (out of carry) 2 places. 12 Problem: (a) AX=0F07H and BX=6644H, find the value of AX and BX after the execution following instructions- MOV CL, 4; RCL AX, CL; ROR BX, CL (b) AX=0F07H and BX=6644H, find the value of AX and BX after the execution following instructions- SHL AX, 4 SAR BX, 3