Computer Organization & Assembly Language

Slides:



Advertisements
Similar presentations
BINARY & HEX I/O. Binary input : read in a binary number from keyboard, followed by a carriage return. character strings of 1’s & 0’ we need to convert.
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,
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
80x86 Instruction Set Dr. Qiang Lin.
1 Lecture 7 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language :CSC 225 (Lec#4: Flag Register and Conditional Statements) By Dr. Syed Noman.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
Flow Control Instructions
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.
Ch. 5 from Yu & Marut. Registers 14(16-bit) registers: 1.Data reg. – to hold data for an op. 2.Address reg – to hold addr of an instruction or data.
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt.
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.
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.
Overview of Assembly Language Chapter 4 S. Dandamudi.
Department of Computer Science and Software Engineering
Lecture 5 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#5) By Dr. Syed Noman.
Arithmetic Flags and Instructions
(Flow Control 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.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
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.
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.
Computer Architecture CST 250
Practical Session 2.
8086 Microprocessor.
Microprocessor Systems Design I
Chapter 3 Bit Operations
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Instruction System - Bit Manipulation Instruction
Machine control instruction
Assembly Language Programming Part 2
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Introduction to Assembly Language
Shift & Rotate Instructions)
Program Logic and Control
Program Logic and Control
Shift & Rotate Instructions)
Assembly Language for Intel-Based Computers, 5th Edition
Shift, Multiply, and Divide
Microprocessor and Assembly Language
Computer Organization and Assembly Language
Chapter 7 –Program Logic and Control
Chapter 8: Instruction Set 8086 CPU Architecture
Chapter 7 –Program Logic and Control
Shift and Rotate Instructions.
CS-401 Computer Architecture & Assembly Language Programming
Ch. 5 – Intel 8086 – study details from Yu & Marut
Presentation transcript:

Computer Organization & Assembly Language Shift & Rotate Instructions Binary & Hex IO

Shift/Rotate Instructions Shift the bits in destination operand by one or more positions either to the left or right. Shift: Bit shifted out is lost Rotate: Bit shifted out from one end of the destination operand is put back on the other end. Syntax: OPCODE destination, 1 ;single shift/rotate OPCODE destination, CL ;for N positions shift/rotate Where: destination can be 8-bit or 16-bit registers or memory variable

Shift Instructions SHL Instruction (Left Shift) SAL (Shift Arithmetic Left) SHR (Right Shift) SAR (Shift Arithmetic Right)

The SHL Instruction Shifts the bit in destination to the left Effects on flags: SF, PF, ZF reflects the result AF is undefined CF = last bit shifted out OF = 1 if result changes sign on last shift Example: DH = 8Ah CL = 3 Value of DH and CF after executing instruction: SHL DH, CL Solution: DH = 50h, CF = 0

Contd.. Multiplication by left shift Consider digit 235, if each digit is shifted left one position and a 0 is attached at right end, the value will be 2350 Same as Multiplying 235 by 10 Left shift on a binary number means multiplying the number by 2 Example: If AL = 5d, after left shift AL = 10d, after another left shift AL = 20d

The SAL Instruction Used when numeric multiplication is intended Both SHL and SAL instructions generates same machine code. Example: Multiply AX by 8 MOV CL, 3 SAL AX, CL

The SHR Instruction Performs right shift on destination operand. A 0 is shifted into MSB and rightmost bit is shifted to CF. The effect on flag is same as SHL. Example: DH = 8Ah CL = 2 After executing instruction: SHR DH, CL: CF = 1 and DH = 22h Erase rightmost two bits and add two 0 bits to the left end If an unsigned interpretation is being given, use SHR.

The SAR Instruction Operates like SHR, with one difference: the MSB retains its original value. If number is even, one right shift is same as divide the number by 2. If number is odd, one right shift halves it and rounds down to nearest integer. Example: BL = 0000 0101b = 5d After one right shift: BL = 0000 0010b = 2d If an signed interpretation is being given, use SAR. (preserves the MSB)

Examples Use right shift to divide unsigned number 65143 by 4. Put quotient in AX. Solution: MOV AX, 65143 MOV CL, 2 SHR AX, CL If AL contains -15, give the decimal value of AL after SAR AL, 1 is performed. The instruction will divide –15 by 2 and round it down to –8 AL = 1111 0001b AL = 1111 0000b = – 8

Rotate Instructions ROL (Rotate Left) ROR (Rotate Right) MSB is shifted into the rightmost bit CF also gets the bit shifted out of the MSB Syntax: ROL destination, 1 ROL destination, CL ROR (Rotate Right) The rightmost bit is shifted into MSB and also into CF. ROR destination, 1 ROR destination, CL

Contd.. RCL (Rotate Carry Left) RCR (Rotate Carry Right) Shifts the bit of destination to the left The MSB is shifted into CF and the previous value of CF is shifted into the rightmost bit. Syntax: RCL destination, 1 RCL destination, CL RCR (Rotate Carry Right) Works just like RCL except that the bits are rotated to the right. RCR destination, 1 RCR destination, CL

Effects of Rotate Instruction on Flags SF, PF, ZF reflects the result AF is undefined CF = last bit shifted out OF = 1 if result changes sign on the last rotation

Example Use ROL to count the number of 1 bits in BX, without changing BX. Put answer in AX Solution: XOR AX, AX MOV CX, 16 TOP: ROL BX, 1 JNC NEXT INC AX NEXT: LOOP TOP

Example Suppose DH contains 8Ah, CF = 1, and CL contains 3. What are the values of DH and CF after the instruction RCR DH, CL is executed? Solution: CF DH Initial value 1 1000 1010 After 1 right rotation 0 1100 0101 After 2 right rotations 1 0110 0010 After 3 right rotations 0 1011 0001 = B1h

An application of reversing bit pattern AL = 1101 1100, Required = 0011 1011 MOV CX, 8 REVERSE: SHL AL, 1 RCR BL, 1 LOOP REVERSE MOV AL, BL

Binary Input Algorithm to read a binary number from keyboard and stored it in BX Clear BX Input a character While character <> CR Do Convert character to binary value Left shift BX Insert value into LSB of BX End_While

Contd.. Assembly Language Code for Binary Input: XOR BX, BX MOV AH, 1 INT 21h WHILE_: CMP AL, 0Dh JE END_WHILE AND AL, 0Fh ;convert to binary value SHL BX, 1 OR BL, AL JMP WHILE_ END_WHILE:

Binary Output Algorithm: FOR 16 TIMES DO ROTATE LEFT BX IF CF = 1 THEN ELSE OUTPUT ‘0’ END_IF END_FOR

Hex Input Assumptions: Algorithm for Hex Input: CLEAR BX Only uppercase letters Maximum four hex characters Algorithm for Hex Input: CLEAR BX Input Hex Character WHILE Character <> CR DO Convert Character To Binary Value Left Shift BX Four Times Insert Value Into Lower 4 Bits Of BX Input A Character END_WHILE

Hex Output Algorithm: For 4 Times Do Move BH to DL Shift DL 4 times to the right IF DL < 10 THEN Convert to character in ‘0’….’9’ ELSE Convert to character in ‘A’….’F’ END_IF Output Character Rotate BX left 4 times END_FOR