Assembly Language for Intel-Based Computers, 5th Edition

Slides:



Advertisements
Similar presentations
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Advertisements

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
Irvine: Assembly Language for Intel-Based Computers (1999) Symbolic Constants Equal-sign Directive EQU Directive TEXTEQU Directive.
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
CS2422 Assembly Language & System Programming September 28, 2006.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
CSC 221 Computer Organization and Assembly Language
Assembly Language for x86 Processors 7th Edition
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
Assembly Language for x86 Processors 7 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and copy this.
LAB Flag Bits and Register
Lecture 4 ( Assembly Language).
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Copyright 2000ELEC 242 Arithmetic Instructions1 Arithmetic Instructions Arithmetic and logical instructions modify the contents of the Flag (Status) register.
Arithmetic Flags and Instructions
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.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 4: Data Transfers, Addressing, and Arithmetic Lecture 15: ADD, SUB, NEG and how they.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, All rights reserved. You may modify.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
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.
Introduction to Microprocessors Chapter 3. Programming Model (8086)  Shows the various internal registers that are accessible to the programmer.
Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags.
CS2422 Assembly Language and System Programming 0 Week 9 Data Transfers, Addressing, and Arithmetic.
Assembly Language for x86 Processors 6th Edition
Data Transfers, Addressing, and Arithmetic
Data Representation Binary Numbers Binary Addition
ICS312 SET 7 Flags.
The FLAGS Register An x bit means an unidentified value 9/12/2018
Instruction System - Bit Manipulation Instruction
Assembly Language Lab (4).
More on logical instruction and
Assembly Language for x86 Processors
4.2 Arithmetic Instructions
CS-401 Assembly Language Programming
COAL Chapter 1,2,3.
Arithmetic Instructions
Assembly Language for Intel-Based Computers, 4th Edition
Introduction to Assembly Language
Chapter 4: Instructions
Lecture 4 ( Assembly Language).
Flags Register & Jump Instruction
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Data Transfers, Addressing, and Arithmetic
Chapter 11 © 2011, The McGraw-Hill Companies, Inc.
University of Gujrat Department of Computer Science
Basic Instructions.
Shift & Rotate Instructions)
Assembly Language for Intel-Based Computers, 4th Edition
Lecture 06 Programming language.
University of Gujrat Department of Computer Science
8051 ASSEMBLY LANGUAGE PROGRAMMING
Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Chapter 8: Instruction Set 8086 CPU Architecture
Number Systems and Circuits for Addition
Shift and Rotate Instructions.
Part I Data Representation and 8086 Microprocessors
Ch. 5 – Intel 8086 – study details from Yu & Marut
Part IV The FLAGS Register
Presentation transcript:

Assembly Language for Intel-Based Computers, 5th Edition Kip Irvine Chapter 4: Data Transfers, Addressing, and Arithmetic (c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.

Flags Affected by Arithmetic The ALU has a number of status flags that reflect the outcome of arithmetic (and bitwise) operations based on the contents of the destination operand Essential flags: Zero flag – set when destination equals zero Sign flag – set when destination is negative result Carry flag – set when unsigned value is out of range Overflow flag – set when signed value overflow The MOV instruction never affects the flags.

arithmetic & bitwise operations Concept Map CPU part of executes executes ALU conditional jumps arithmetic & bitwise operations attached to used by provide affect status flags branching logic You can use diagrams such as these to express the relationships between assembly language concepts.

Zero Flag (ZF) The Zero flag is set when the result of an operation produces zero in the destination operand. mov cx,1 sub cx,1 ; CX = 0, ZF = 1 mov ax,0FFFFh inc ax ; AX = 0, ZF = 1 inc ax ; AX = 1, ZF = 0 Remember... A flag is set when it equals 1. A flag is clear when it equals 0.

Sign Flag (SF) The Sign flag is set when the destination operand is negative. The flag is clear when the destination is positive. mov cx,0 sub cx,1 ; CX = -1, SF = 1 add cx,2 ; CX = 1, SF = 0 The sign flag is a copy of the destination's highest bit: mov al,0 sub al,1 ; AL = 11111111b, SF = 1 add al,2 ; AL = 00000001b, SF = 0

Signed and Unsigned Integers A Hardware Viewpoint All CPU instructions operate exactly the same on signed and unsigned integers The CPU cannot distinguish between signed and unsigned integers YOU, the programmer, are solely responsible for using the correct data type with each instruction

Carry Flag (CF) The Carry flag is set when the result of an operation generates an unsigned value that is out of range (too big or too small for the destination operand). Carry flag: set when the result of an addition or subtraction exceeds fixed number of bits allocated mov al,0FFh add al,1 ; CF = 1, AL = 00 ; Try to go below zero: mov al,0 sub al,1 ; CF = 1, AL = FF

Your turn . . . For each of the following marked entries, show the values of the destination operand and the Sign, Zero, and Carry flags: mov ax,00FFh add ax,1 ; AX= SF= ZF= CF= sub ax,1 ; AX= SF= ZF= CF= add al,1 ; AL= SF= ZF= CF= mov bh,6Ch add bh,95h ; BH= SF= ZF= CF= mov al,2 sub al,3 ; AL= SF= ZF= CF= 0100h 0 0 0 00FFh 0 0 0 00h 0 1 1 01h 0 0 1 FFh 1 0 1

Overflow Flag (OF) The Overflow flag is set when the signed result of an operation is invalid or out of range. Overflow: result of addition or subtraction overflows into the sign bit ; Example 1 mov al,+127 add al,1 ; OF = 1, AL = ?? ; Example 2 mov al,7Fh ; OF = 1, AL = 80h add al,1 The two examples are identical at the binary level because 7Fh equals +127. To determine the value of the destination operand, it is often easier to calculate in hexadecimal.

A Rule of Thumb When adding two integers, remember that the Overflow flag is only set when . . . Two positive operands are added and their sum is negative Two negative operands are added and their sum is positive What will be the values of the Overflow flag? mov al,80h add al,92h ; OF = mov al,-2 add al,+127 ; OF = 1

Your turn . . . What will be the values of the given flags after each operation? mov al,-128 neg al ; CF = OF = mov ax,8000h add ax,2 ; CF = OF = mov ax,0 sub ax,2 ; CF = OF = mov al,-5 sub al,+125 ; OF = 1 1 0 0 1 0 1