Instructions moving data

Similar documents
Defining and Using Simple Data Types

Week /8086 Microprocessor Programming I

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

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

8088/8086 Programming Integer Instructions and Computations

Basic Pentium Instructions. October 18

Chapter 7 Integer Arithmetic

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

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

Signed number Arithmetic. Negative number is represented as

3.1 DATA MOVEMENT INSTRUCTIONS 45

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

Arithmetic and Logic Instructions And Programs

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

Integer Arithmetic Part2

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

We will first study the basic instructions for doing multiplications and divisions

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

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

16.317: Microprocessor Systems Design I Fall 2013

16.317: Microprocessor Systems Design I Spring 2014

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

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

Computer Architecture and System Programming Laboratory. TA Session 3

Arithmetic Instructions

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

EECE.3170: Microprocessor Systems Design I Spring 2016

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

22 Assembly Language for Intel-Based Computers, 4th Edition. 3. Each edge is a transition from one state to another, caused by some input.

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.

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

Introduction to 8086 Assembly

Assembler lecture 4 S.Šimoňák, DCI FEEI TU of Košice

EC 333 Microprocessor and Interfacing Techniques (3+1)

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

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

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

Intel 8086: Instruction Set

Basic Assembly Instructions

Basic Assembly SYSC-3006

EEM336 Microprocessors I. Arithmetic and Logic Instructions

Computer Architecture and Assembly Language. Practical Session 3

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

Week /8086 Microprocessor Programming

Introduction to 8086 Assembly

Chapter 12. Selected Pentium Instructions

Lecture (07) x86 programming 6

8086 INSTRUCTION SET

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

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

APPENDIX C INSTRUCTION SET DESCRIPTIONS

CMSC 313 Lecture 05 [draft]

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.

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

Lecture 2 Assembly Language

Week /8086 Microprocessor Programming II

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing

Step 1: Add the least significant digits together: produces with carry 1.

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

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

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

Lecture (08) x86 programming 7

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Logical and Bit Operations. Chapter 8 S. Dandamudi

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

UNIT III MICROPROCESSORS AND MICROCONTROLLERS MATERIAL OVERVIEW: Addressing Modes of Assembler Directives. Procedures and Macros

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

ASSEMBLY LANGUAGE PROGRAMMING OF THE MICROCOMPUTER

8086 ASSEMBLY LANGUAGE PROGRAMMING

Microprocessor & Computer Architecture / Lecture

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

Logical and bit operations

Language of x86 processor family

Lab 4: Basic Instructions and Addressing Modes

ASSEMBLY - QUICK GUIDE ASSEMBLY - INTRODUCTION

The x86 Architecture

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Lab 3. The Art of Assembly Language (II)

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5

Shift and Rotate Instructions

COMPUTER ENGINEERING DEPARTMENT

Overview of Assembly Language

LAB 5 Arithmetic Operations Simple Calculator

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

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

Assembly Language LAB

UNIT II. 2 Marks. 2. List out the various register of IA- 32 Register structure. 3. Write about General purpose registers

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

Assembly Language: IA-32 Instructions

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

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

Basic Intel x86 Assembly Language Programming

ELEC 242 Time Delay Procedure

Adding Binary Integers. Part 4. Negative Binary. Integers. Adding Base 10 Numbers. Adding Binary Example = 10. Arithmetic Logic Unit

SOEN228, Winter Revision 1.2 Date: October 25,

COMPUTER ENGINEERING DEPARTMENT

Lecture Notes on Assembly Language - J. Vaughan

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

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Assembly Language Lab # 4 Data Transfer & Arithmetic (1)

Transcription:

do not affect flags. Instructions moving data mov register/mem, register/mem/number (move data)

The difference between the value and the address of a variable mov al,sum; value 56h al mov ebx,offset Sum; address 4069D0h ebx AL 4069D0h address of variable Sum (offset in the data segment) 56h 56h

When moving data to and from memory, the EAX register (or its part) is usually used, because: One DB 1 mov bl,one 8A 1D D0 69 40 00 mov al,one A0 D0 69 40 00 better! Hyde, R.: The Art of Assembly Language Programming, cap. 5.4 Encoding 80x86 Instructions

Operator offset cannot be used to get the address of a memory location pointed to by an indirect addressing mode (using a base or index register). Store the address of variable Table increased by EDI to EBX. mov ebx,offset Table[edi] Does not work! ( Invalid operand for offset. )

lea register,memory (load effective address) loads the offset of a memory location to a generalpurpose register. lea ebx,table is the same as mov ebx,offset Table lea ebx,table 8D 1D 10 60 40 00 mov ebx,offset Table BB 10 60 40 00 better! lea ebx,table[edi]; store the address of variable Table increased by EDI to EBX

movzx register, register/memory (move with zero-extend) copies the right operand into the lower half of the left operand and sets the upper half to 0 movzx bx,dl is the same as mov bl,dl mov bh,0

movsx register, register/memory (move with sign-extend) copies the right operand into the lower half of the left operand and duplicates the highest order bit of the right operand throughout the upper half of the left operand. Number DB -5 movsx ax,number; ax = 1111 1111 1111 1011 is the same as mov al,number mov ah,0ffh

xchg register/memory, register/memory (exchange) exchanges the contents of the operands

Arithmetic instructions affect flags ZF, CF, OF, SF, AC, PF add register/memory, register/memory/number (add) adds the operands, stores the result to the left operand sub register/memory, register/memory/number (subtract) subtracts the right operand from the left one, stores the result to the left operand

adc register/mem,register/mem/number (add with carry) adds the operands and CF, stores the result to the left operand useful when adding operands longer than a general-purpose register X DQ 0FEDCBA98h ; 98 BA DC FE 00 00 00 00 Y DQ 10000000h ; 00 00 00 10 00 00 00 00 Z DQ?; Z = X + Y 1. 2. mov eax,dword ptr X; eax = FEDCBA98 add eax,dword ptr Y; eax = 0EDCBA98, CF = 1 mov dword ptr Z,eax mov eax,dword ptr X+4; eax = 0 adc eax,dword ptr Y+4; eax = 1 mov dword ptr Z+4,eax

sbb register/memory,register/memory/number (subtract with borrow) subtracts the right operand and CF from the left operand, stores the result to the left operand useful when subtracting operands longer than a generalpurpose register inc register/memory (increment) increments the operand by 1 does not affect CF! add edi,1 83 C7 01 inc edi 47 better!

dec register/memory (decrement) decrements the operand by 1 does not affect CF! cmp register/memory, register/memory/number (compare) compares the operands: subtracts the right operand from the left one, sets flags according to the result (does not store the result itself)

mul register/memory (unsigned multiply) Operand type Multiplied by Result byte AL AX word AX DX:AX dword EAX EDX:EAX If the upper half of the result is 0, then OF and CF are set to 0. Otherwise OF and CF are set to 1.

imul register/memory (signed multiply) multiplication of signed numbers implicit operands as mul imul register, register/memory/number left operand = left * right Both operands must be of the same type (word or dword). imul dx,word ptr [edi] imul register, register/memory, number left operand = intermediate * right The leftmost and intermediate operands must be of the same type (word or dword). If the upper half of the result is a signed extension of the lower half, then OF and CF are set to 0, otherwise to 1.

div register/memory (unsigned divide) integer division of unsigned numbers Dividend Type of the operand (divisor) Quotient Remainder AX byte AL AH DX:AX word AX DX EDX:EAX dword EAX EDX Divide decimal number 4001 in the AX register by ten. mov dx,0 mov bx,10 div bx; ax = 400, dx = 1 If the divisor is zero or the quotient does not fit into the implicit register, an internal interrupt is generated.

idiv register/memory (signed divide) integer division of signed numbers implicit operands as div

Sign extension If you want to divide signed operands of the same type, you must sign extend the dividend. cbw (convert byte to word) Converts the byte in AL to a word in AX via sign extension (bit 7 of the AL register is copied into all bits of the AH register). Divide decimal number -15 in BH by 7 in BL. mov al,bh; al = 0F1h = -15 cbw; ax = 0FFF1h = -15 idiv bl; al = 0FEh = -2, ah = 0FFh = -1

cwd (convert word to doubleword) Converts the word in AX to a doubleword in DX:AX. cwde (convert word to doubleword extended) Converts the word in AX to a doubleword in EAX. cdq (convert doubleword to quadword) Converts the doubleword in EAX to the quadword in EDX:EAX. Instructions cbw,... do not affect flags.

neg register/memory (two s complement negation) switches the sign of the operand (replaces the operand by its two s complement) mov al,-15 ; al = -15 = 11110001b neg al ; al = 15 = 00001111b mov bl,al ; bl = 15 neg bl ; bl = -15

Logical instructions perform logical operations on the corresponding bits of the operands. The result is stored to the left operand. set flags: CF and OF to 0 ZF, SF, PF according to the result of the operation AC remains undefined

and register/memory, register/memory/number is useful when a single bit (several bits) of the left operand are to be set to 0. The right operand is a mask having 0 in the given bits and 1 in the other bits. Set the 3rd bit of BL to zero. and bl,11110111b Convert the ASCII code of a digit to the value. 0 = 00110000b, 1 = 00110001b,... mov al, 9 and al,00001111b; 9 9

or register/memory, register/memory/number is useful when a single bit (several bits) of the left operand are to be set to 1. The right operand is a mask having 1 in the given bits and 0 in the other bits. Set the 3rd bit of BL to 1. or bl,00001000b Convert a number to the ASCII code of the corresponding digit: mov al,9 or al,110000b; 9 9

xor register/memory, register/memory/number is useful when a single bit (several bits) of the left operand are to be inverted. 1 in the mask inverts the corresponding bit, 0 leaves the bit unchanged. Invert the upper 4 bits of the BL register. mov bl,01010101b xor bl,11110000b ; bl = 10100101b Set the ECX register to zero: mov ecx,0 B9 00 00 00 00 xor ecx,ecx 33 C9 better!

test register/memory, register/memory/number (logical compare) AND without saving the result is useful when we want to branch the execution according to the value of a chosen bit of the left operand. Branch according to the 3rd bit of the BL register. test bl,00001000b jz Zero; 3rd bit is 0 One:... not register/memory (one s complement negation) inverts all bits of the operand does not change flags

Shift and rotate instructions The left operand is a register or memory location (byte, word or doubleword), whose bits are shifted or rotated to the left or right. The right operand is a constant or register CL. The right operand determines the number of positions to shift.

Shift instructions set flags: CF, OF, ZF, SF, PF according to the result of the operation AC - undefined shl register/memory, number/cl (shift logical left) sal register/memory, number/cl (shift arithmetic left) useful for fast doubling (or multiplying by 4, 8 or 16) unsigned numbers. shl dx,4; dx = 16*dx

shr register/memory, number/cl (shift logical right) halving (or dividing by 4, 8 or 16) unsigned numbers sar register/memory, number/cl (shift arithmetic right) halving (or dividing by 4, 8 or 16) signed numbers mov bl,-4 ; bl = -4 = 11111100b sar bl,1 ; bl = -2 = 11111110b

set CF and OF Rotate instructions rol register/memory, number/cl (rotate left) ror register/memory, number/cl (rotate right)

rcl register/memory, number/cl (rotate left through carry) useful when doubling operands longer than 32 bits. Because one operation can shift at most 32 bits, shifts of longer operands must be done by parts. Double variable BigNumber of type qword. shl dword ptr BigNumber,1 rcl dword ptr BigNumber + 4,1 rcr register/memory, number/cl (rotate right through carry)

Bit set To store a set in bits we need as many bits as there are all possible elements of the set. Example: Let variable setx is a bit set representing a subset of all integers 0, 31. Further, let the AL register store number a 0, 31. Add number a to the set setx.