Department of Computer Science and Software Engineering

Slides:



Advertisements
Similar presentations
1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
Advertisements

Lecture 4 Basic Instructions Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
80x86 Instruction Set Dr. Qiang Lin.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
The 8086 Assembly Programming Data Allocation & Addressing Modes
Computer Organization And Assembly Language
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
CS2422 Assembly Language & System Programming September 28, 2006.
Shift and Rotate Instructions
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
Assembly Language for Intel-Based Computers
Lect 4: Instruction Set and Addressing Modes. 386 Instruction Set (3.4)  Basic Instruction Set : 8086/8088 instruction set  Extended Instruction Set.
CE302 Outline Multiplication Division Program Segment Prefix Command Line Parameters.
Assembly Language – Lab 5
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Multiplication and Division Instructions & the 0Ah function.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Copyright 2000ELEC 242 Arithmetic Instructions1 Arithmetic Instructions Arithmetic and logical instructions modify the contents of the Flag (Status) register.
Arithmetic Flags and Instructions
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.b: Arithmetic Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
Integer Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2007/12/24 with slides by Kip Irvine.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
Arithmetic and Logic Instructions. Outline Declarations Moving data The Flags register Logic instructions Addition & subtraction.
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.
Chapter 7: Integer Arithmetic. 2 Chapter Overview Shift and Rotate Instructions Shift and Rotate Applications Multiplication and Division Instructions.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
ICS 312 SET 10 Multiplication & Division & input using function 0Ah.
Introduction Arithmetic instructions are used to perform arithmetic operation such as Addition Subtraction Multiplication Division These operations can.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
Internal Programming Architecture or Model
Multiplication and Division instructions Dr.Hadi AL Saadi.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Addressing Modes Instruction – Op-code – Operand Addressing mode indicates a way of locating data or operands. – Any instruction may belong to one or more.
Data Transfers, Addressing, and Arithmetic
16.317: Microprocessor System Design I
Assembly Language for Intel-Based Computers, 5th Edition
8086 Microprocessor.
ADDRESSING MODES.
Microprocessor and Assembly Language
Microprocessor Systems Design I
Basic Assembly Language
Multiplication and Division Instructions
Assembly IA-32.
Assembly Language Programming Part 2
ADDRESSING MODES.
CS-401 Computer Architecture & Assembly Language Programming
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
X86’s instruction sets.
Chapter 4: Instructions
BIC 10503: COMPUTER ARCHITECTURE
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
اصول اساسی برنامه نویسی به زبان اسمبلی
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
Multiplication and Division Instructions
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture CST 250
Chapter 5 Arithmetic and Logic Instructions
Chapter 6 –Symbolic Instruction and Addressing
Multiplication and Division Instructions
Multiplication and Division Instructions
Division instruction.
Presentation transcript:

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

The MOV instruction Move data Syntax mov destination, source From memory to a register From a register to memory From a register to another register Never from memory to memory Note: source/destination must be of identical size Syntax mov destination, source

Addressing modes Register Immediate MOV AX, BX MOV AL, BL MOV DX, SI MOV DS, BX Immediate Load a value to a register or a memory location MOV AX, 1234h

Memory Addressing modes Direct Move data from a memory location to a register Example : MOV AX, [1234h] 1234h is an offset within the data segment DS Register Indirect (base relative, or indexed) Offset is saved in a register BX, SI, DI define offset in the data segment BP defines an offset in the stack segment! Examples: MOV AX,[BX] MOV AX,[BP] MOV AX,[SI] MOV AX,[DI]

Addressing modes Base plus index (base relative indexed) Example: MOV AX, [BX+DI] MOV AX, [BX+SI] Base can be BX or BP, index SI or DI Register relative MOV AX, [BX+1234h] Register on the left can be BX, BP, SI, or DI Base relative plus index MOV AX, [BX+DI+1234h] Registers can be one of BX or BP and one of SI or DI

Example: Memory and Labels mov al, [L1] ;copy byte at L1 into al mov eax, L1 ;eax = address of byte at L1 mov [L1], ah ;copy ah into byte at L1 mov eax, [L6] ;copy double word at L6 into eax add eax, [L6] ;eax += double word at L6 add [L6], eax ;double word at L6 += eax mov al, [L6] ;copy first byte of double word at L6 ;into al mov [L6],1 ;generates “operation size not ;specified” error mov dword[L6],1 ;stores 1 in double word at L6

Assembly I/O Routines %include “asm_io.inc” print_int prints out to the screen the value of the integer stored in EAX print_char prints out to the screen the character whose ASCII value stored in AL print_string prints out to the screen the contents of the string at the address stored in EAX. The string must be a Ctype string (i.e. null terminated) print_nl prints out to the screen a new line character read_int reads an integer from the keyboard and stores it into the EAX register read_char reads a single character from the keyboard and stores its ASCII code into the EAX register Uses a CALL instruction to invoke above routines

Important Flags Z – set when the result of the last operation was zero C – Set when there was a carry (or borrow) beyond the most significant bit in the last operation (unsigned overflow) O – Set when the last operation overflowed, when interpreting the operands as signed P – Indicates the parity of the result of the last operation (is set when the destination has an even number of 1 bits) S – The sign bit (MSB) of the result of the last operation D – direction flag, controls the direction of a string stored in memory (more later)

Addition ADD X,Y Some modified flags: S, C, Z, O,P Examples X=X+Y X, Y can be register or memory, but not both memory Y can also be immediate data Some modified flags: S, C, Z, O,P Examples ADD AX, BX ; register addition ADD AX, 5h ; immediate addition ADD [BX], AX ; addition to memory location ADD AX, [BX] ; memory location added to register ADD DI, MYVAR ; memory offset added to the register

Add with carry ADC X,Y X= X + Y + Carry flag X, Y can be register or memory, but not both memory Y can also be immediate Used to add numbers larger than 16 bits (in 16-bit mode) or larger than 32 bits in (32-bit mode) Examples ADD AX,CX ; produces a 32-bit sum ADC BX,DX ; of BX:AX + DX:CX -> BX:AX Some modified flags: S, C,Z, O, P

Subtraction SUB X,Y Some modified flags: S, C, Z, O,P Examples X=X-Y X, Y can be register or memory, but not both memory Y can also be immediate data Some modified flags: S, C, Z, O,P Examples SUB AX, BX ; register addition SUB AX, 5h ; immediate addition SUB [BX], AX ; addition to memory location SUB AX, [BX] ; memory location added to register SUB DI, MYVAR ; memory offset added to the register

Subtract with borrow SBB X,Y X=X - Y - Carry flag X, Y can be register or memory (not both memory) X can be immediate Used to subtract numbers which are wider than 16 bits (in 16-bit mode) or wider than 32 bits (in 32-bit mode) Some modified flags: S, C, Z, P, O Examples: SUB AX, DI ; this subtracts the 32-bit numbers SBB BX, SI ; BX:AX-SI:DI -> BX:AX

Increment INC X Some modified flags: S, Z, O, P Examples: X can be register or memory location X=X+1 Some modified flags: S, Z, O, P Examples: INC AX ; AX=AX+1 INC byte [BX] ; memory location increased by 1 INC word [BX] ; memory location increased by 1

Decrement DEC X Some modified flags: S, Z, P, O Examples X can be register or memory X=X-1 Some modified flags: S, Z, P, O Examples DEC AX ; AX=AX-1 DEC BYTE [BX] ; memory location decreased by 1 DEC WORD [BX] ; memory location decreased by 1

MUL Instruction The MUL (unsigned multiply) instruction multiplies an 8, 16, or 32-bit operand by either AL, AX, or EAX The instruction formats are: MUL Reg/Mem8 MUL Reg/Mem16 MUL Reg/Mem32 Results are saved as following

MUL Examples 100h * 2000h, using 16-bit operands: .data val1 WORD 2000h val2 WORD 100h .code mov ax,val1 mul val2 ; DX:AX = 00200000h, CF=1 The Carry flag indicates whether or not the upper half of the product contains significant digits. mov eax,12345h mov ebx,1000h mul ebx ; EDX:EAX = 0000000012345000h, CF=0 12345h * 1000h, using 32-bit operands: 16

Signed Integer Multiply IMUL (signed integer multiply ) multiplies an 8, 16, or 32-bit signed operand The instruction formats are: Imul source1 imul dest, source1 imul dest, source1, source2 17

IMUL Instruction 18

DIV Instruction The DIV (unsigned divide) instruction performs 8-bit, 16-bit, and 32-bit division on unsigned integers A single operand is supplied (register or memory operand), which is assumed to be the divisor Instruction formats: DIV Reg/Mem8 DIV Reg/Mem16 DIV Reg/Mem32 19

DIV Examples Divide 8003h by 100h, using 16-bit operands: mov dx,0 ; clear dividend, high mov ax,8003h ; dividend, low mov cx,100h ; divisor div cx ; AX = 0080h, DX = 3 Same division, using 32-bit operands: mov edx,0 ; clear dividend, high mov eax,8003h ; dividend, low mov ecx,100h ; divisor div ecx ; EAX = 00000080h, DX = 3 20

Unsigned Size Increase How about increasing the size of a 2-byte quantity to 4 byte? Therefore, there is an instruction called movzx (Zero eXtend), which takes two operands Destination: 16- or 32-bit register Source: 8- or 16-bit register, or 1 byte in memory, or 1 word in memory The destination must be larger than the source! 21

Using MOVZX movzx eax, ax ; extends ax into eax movzx eax, al ; extends al into eax movzx ax, al ; extends al into eax movzx ebx, ax ; extends ax into ebx movzx ebx, [L] ; gives a “size not specified” error movzx ebx, byte [L] ; extends 1-byte value at address L into ebx movzx eax, word [L] ; extends 2-byte value at address L into eax 22

Signed Size Increase There is no way to use movzx instructions to increase the size of signed numbers, because of the needed sign extension New conversion instructions with implicit operands CBW (Convert Byte to Word): Sign extends AL into AX CWD (Convert Word to Double): Sign extends AX into DX:AX CWDE (Convert Word to Double word Extended): Sign extends AX into EAX CDQ (Convert Double word to Quad word): Signs extends EAX into EDX:EAX (implicit operands) 23