Micro-Computer Applications: Arithmetic, Logic & Data Movement Instructions Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.

Slides:



Advertisements
Similar presentations
Instruction Set of 8086 Engr. M.Zakir Shaikh
Advertisements

1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
Micro-Computer Applications: Jumping and Loop Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Chapter four – The 80x86 Instruction Set Principles of Microcomputers 2015年5月14日 2015年5月14日 2015年5月14日 2015年5月14日 2015年5月14日 2015年5月14日 1 Chapter Four.
Department of Computer Science and Software Engineering
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
80x86 Instruction Set Dr. Qiang Lin.
Data Movement Instructions
Computer Organization And Assembly Language
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Practical Session 3 Computer Architecture and Assembly Language.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
Intel’s 8086 instruction-set
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 4 Data Movement Instructions by.
Shift and Rotate Instructions
Microcomputer & Interfacing Lecture 3
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Chapter four – The 80x86 Instruction Set Principles of Microcomputers 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 1 Chapter.
5. Assembly Language. Basics of AL Program data Pseudo-ops Array Program structures Data, stack, code segments.
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.
Integer Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2007/12/24 with slides by Kip Irvine.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
26-Nov-15 (1) CSC Computer Organization Lecture 6: Pentium IA-32.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
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.
MOV Instruction MOV destination,source  MOV AX,BX  MOV SUM,EAX  MOV EDX,ARRAY[EBX][ESI]  MOV CL,5  MOV DL,[BX]
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
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
Microprocessor & Assembly Language
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Data Movement Instructions A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Practical Session 3 Computer Architecture and Assembly Language.
Stack Operations Dr. Hadi AL Saadi.
Computer Architecture and Assembly Language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Microprocessor Systems Design I
16.317: Microprocessor System Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Chapter 4 Data Movement Instructions
Microprocessor Systems Design I
EE3541 Introduction to Microprocessors
Machine control instruction
INSTRUCTION SET.
Assembly Language Programming Part 2
# include < stdio.h > v oid main(void) { long NUM1[5]; long SUM; long N; NUM1[0] = 17; NUM1[1] = 3; NUM1[2] =  51; NUM1[3] = 242; NUM1[4] = 113; SUM =
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Chapter 4: Instructions
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Chapter 8 Central Processing Unit
Assembly Language for Intel-Based Computers, 4th Edition
80386 Instruction Set.
Chapter 5 Arithmetic and Logic Instructions
Chapter 5: Arithmetic and Logic Instructions
CNET 315 Microprocessor & Assembly Language
Presentation transcript:

Micro-Computer Applications: Arithmetic, Logic & Data Movement Instructions Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Instructions Types  Arithmetic/Logic  Data Movement  Program Control (if,..)  Loop Control  Interrupts

Dr. Amr Talaat ELECT 707 Micro-Computer Applications MOV et.al.  MOV is still the main data transfer instruction, b ut there are many variations that perform speci al tasks such as PUSH and POP.  We do not often code in hexadecimal machine la nguage, but an understanding tends to help wit h learning the instruction set and the form of ins tructions in the memory.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications The Opcode WD OpcodeModRegR/M DescriptionFeild the direction of data flow either from or to R/M from REG. If D = 0 REG  R/M and if D = 1 R/M  REG D specifies a word (16-bit mode) or a doubleword (32-bit mode). W = 0 byte and W = 1 word/doubleword W specifies how R/M is used and whether a displacement exists. MOD = 00 memory no displacement MOD = 01 memory 8-bit displacement MOD = 10 memory 16/32-bit displacement MOD = 11 register MOD

Dr. Amr Talaat ELECT 707 Micro-Computer Applications

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Segment Register Moves  Although we do not often directly address segm ent registers it is important to understand the li mitations of the segment register MOV instructio n.  Immediate data cannot be moved into a se gment register.  CS cannot successfully be loaded with a se gment register MOV.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Addition  The ADD instruction is used for binary addition.  The addition causes the flag bits to change.  Addition can be 8-, 16-, and 32-bits.  All of the addressing modes presented in Chapte r 2 are used by addition. ;EAX = EAX + EBX ADD EAX,EBX ;EAX = EAX + EBX APOSZC rrrrrr

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Flags  Flag Status After Instructions:  1 - instruction sets this flag to 1.  0 - instruction sets this flag to 0.  r - flag value depends on result of the instruct ion.  ? - flag value is undefined (maybe 1 or 0)

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Increment one  The INC instruction adds a one to a register or t he contents of a memory location. ;BX = BX + 1 INC BX;BX = BX + 1 INC BYTE PTR [EBX]

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Add with Carry  The ADC instruction adds the carry bit into the s um. Used for wide additions (wider than 32-bits ) and other reasons. ;AX = AX + DX + C ADC AX,DX;AX = AX + DX + C ADX ESI,[EBX]

Dr. Amr Talaat ELECT 707 Micro-Computer Applications

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Subtraction  The SUB instruction performs subtraction and th e flags change to reflect condition of the result.  As with other arithmetic and logic instructions, s ubtraction exists for 8-, 16-, and 32-bit data. ;AL = AL - 3 SUB AL,3;AL = AL - 3 SUB ECX,ESI

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Decrement one  The DEC instruction subtracts one from a registe r or the contents of a memory location. ;EBX = EBX - 1 DEC EBX;EBX = EBX - 1 DEC DWORD PTR [EAX]

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Subtract with Borrow  The SBB instruction subtracts with borrow (wher e the borrow is held in the carry flag). ;EAX = EAX – EBX – C SBB EAX,EBX ;EAX = EAX – EBX – C

Dr. Amr Talaat ELECT 707 Micro-Computer Applications

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Compare  The CMP instruction is a special form of the SUB instruction. A compare does not result in a diffe rence that is saved, on the flag bits change to re flect the difference. CMP AL,3 ;if AL = 3 the result to zero (flag)

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Multiplication  The MUL (unsigned) and IMUL (signed) instructi on exist to perform 8-, 16-, or 32-bit multiplicati on.  The result is always a double wide result.  The carry and overflow bits indicate conditions a bout the multiplication.  A special IMUL exists with 3 operands.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Division  The DIV (unsigned) and IDIV (signed) instructio n exist to perform division on 8-, 16-, or 32-bit numbers.  Division is always performed o a double wide div idend.  The result is always in the form of an integer qu otient and an integer remainder.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications AND  The AND instruction performs logical multiplicati on (the AND operation).

Dr. Amr Talaat ELECT 707 Micro-Computer Applications OR  The OR instruction generates the logical sum (O R operation).

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Exclusive OR  The XOR instruction performs the Exclusive OR operation.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications NEG and NOT  The NEG (negate) instruction 2’s complements a number,  The NOT instruction 1’s complements a number. NOT EAX NEG DWORD PTR [EBX]

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Shifts  There are 4 shift instructions. Two are logical s hifts and two are arithmetic shifts.  The logical shifts reposition the bits in a number. The arithmetic shifts multiply or divide signed numbers by powers of two.  SHR and SHL are logical and SAR and SAL are ar ithmetic shifts. SHL AL,3 or SHL AL,CL

Dr. Amr Talaat ELECT 707 Micro-Computer Applications

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Rotates  Rotates are shifts that re-circulate the bit that m oves out of an end of the register or memory loc ation.  Four rotates exist where two just rotate the targ et and two rotate the target through the carry fl ag. ROL AL,3or RCL AL,3

Dr. Amr Talaat ELECT 707 Micro-Computer Applications

Dr. Amr Talaat ELECT 707 Micro-Computer Applications TEST  The TEST instruction is a special form of the AN D instruction that produces no result except for a change of the flags.  This instruction is often used to test multiple bit s of a number. test the right two bits (if both are z ero the result is zero) TEST AL,3 ;test the right two bits (if both are z ero the result is zero)

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Bit Test Instructions  There are four bit test instructions BT (bit test), BTR (bit test and reset), BTS (bit test and set), and BTC (bit test and complement).  Each tests the prescribed bit by moving it into c arry. Then the bit is modified (except for BT) ;bit 3 is moved to carry BT AL,3;bit 3 is moved to carry ;bit 3 is moved to carry then set BTS AL,3;bit 3 is moved to carry then set ;bit 3 is moved to carry then reset BTR AL,3;bit 3 is moved to carry then reset ;bit 3 is moved to carry then inverted. BTC AL,3;bit 3 is moved to carry then inverted.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications PUSH and POP  PUSH and POP transfer data to and from the stack. The st ack is an area of memory that is reused and grows in size with each PUSH and shrinks in size with each POP.  PUSH and POP function with either 16- or 32-bit data.  PUSHF (PUSHFD) and POPF (POPFD) save and restore the flags (EFLAGS)  PUSHA (PUSHAD) and POPA (POPAD) save and restore all the registers

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Load Segment and Index  LDS, LES, LSS, LFG, and LGS allow a segment r egisters and a pointer to both be loaded from m emory. LDS BX,BOB ;loads DS and BX with the offset and segment add ress stored in a 32-bit memory location called B OB.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications LEA  The LEA instruction loads the effective ad dress of a memory location into a pointer or index register.  At times we do the same operation with a MOV and the keyword OFFSET MOV BX,OFFSET FRED LEA BX,FRED Both instruction accomplish the same task.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications String Data Transfer Instructions  String data transfer instructions are: LOD S, STOS, MOVS, INS, and OUTS.  These instructions use the direction flag b it to select the way that a pointer is modi fied after the instruction. D = 0 auto-incr ement and D = 1 auto-decrement.  Many of these instructions can be prefixe d with a REP (repeat) to repeat the instru ction the number of times stored in the C X register.

Dr. Amr Talaat ELECT 707 Micro-Computer Applications Miscellaneous  NOP (does nothing)  XCHG (swaps contents)  CLC, STC, CMC (modify Carry)

Dr. Amr Talaat ELECT 707 Micro-Computer Applications References: Based on slides from B. Brey, The Intel Microprocessor: Archit ecture, Programming, and Interfacing, 8 th Edition, 2009 & other s