# 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 =

Slides:



Advertisements
Similar presentations
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Advertisements

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.
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.
© 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.
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.
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.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Arithmetic Flags and Instructions
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.
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.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Arithmetic Flags and Instructions Chapter 7 S. Dandamudi.
COMP 2003: Assembly Language and Digital Logic Chapter 2: Flags and Instructions Notes by Neil Dickson.
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
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.
Micro-Computer Applications: Arithmetic, Logic & Data Movement Instructions Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
K.K. Leung Fall 2008Introductory Pentium Programming1 Pentium Architecture: Introductory Programming Kin K. Leung
Practical Session 3 Computer Architecture and Assembly Language.
Computer Architecture and Assembly Language
Pertemuan 7 Bahasa Rakitan: III
Computer Architecture and Assembly Language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Computer Architecture and Assembly Language
16.317: Microprocessor System Design I
Homework Reading Labs PAL, pp
Today we are going to discuss about,
Chapter 4 Data Movement Instructions
Microprocessor Systems Design I
EE3541 Introduction to Microprocessors
Basic Assembly Language
INSTRUCTION SET.
Basic Microprocessor Architecture
Machine control instruction
Assembly IA-32.
INSTRUCTION SET.
Assembly Language Programming Part 2
ECE 353 Introduction to Microprocessor Systems
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Chapter 4: Instructions
Assembly Language: IA-32 Instructions
CS 301 Fall 2002 Computer Organization
Homework Reading Machine Projects Labs PAL, pp
More IA32 (AKA Pentium) Instructions
Assembly Language for Intel-Based Computers, 4th Edition
Computer Architecture CST 250
X86 Assembly Review.
80386 Instruction Set.
Chapter 5 Arithmetic and Logic Instructions
CNET 315 Microprocessor & Assembly Language
Chapter 8: Instruction Set 8086 CPU Architecture
Principles of Computers 18th Lecture
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
Presentation transcript:

# 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 = 0; N = 5; asm { LEA EBX,NUM1 MO V ECX,N MO V EAX,0 MO V EDI,0 ST AR T ADD: ADD EAX,[EBX + EDI*4] INC EDI DEC ECX JG ST AR T ADD MO V SUM,EAX } printf ("The sum of the list v alues is %ld \ n", SUM ); } Figure D.2. IA-32 Program in Figure 3.40a encapsulated in a C/C++ program.

Machine instructions Assembly language instructions (hexadecimal) 03 04 BB STARTADD: ADD EAX,[EBX + EDI*4] 47 INC EDI 49 DEC ECX 7F F9 JG ST AR T ADD (a) Loop body encoding OP code ModR/M byte SIB byte 03 04 BB 00000011 00 000 100 10 111 011 ADD (see T able D.2) (see Figure D.1 c ) (doubleword (b) ADD instruction OP code Offset 7F F9 01111111 111111001 JG 7 (short offset) (c) JG instruction Figure D.3. Encoding of the loop body in Figure D.2.

T ABLE D.1 Register field enco ding in IA-32 instructions Reg/Base/Index* Register field EAX 1 ECX 1 EDX 1 1 EBX 1 ESP 1 1 EBP 1 1 ESI 1 1 1 EDI *ESP (100) cannot be used as an index register.

IA-32 addressing modes selected by the ModR/M and SIB bytes ABLE D.2 IA-32 addressing modes selected by the ModR/M and SIB bytes ModR/M b yte Addressing mode Mod R/M field field b b b b b 7 6 2 1 Reg Register indirect EA = [Reg] 1 Reg Base with 8-bit displacement EA = [Reg] + Disp8 1 Reg Base with 32-bit displacement EA = [Reg] + Disp32 1 1 Reg Register EA = Reg Exceptions 1 1 Direct EA = Disp32 1 Base with index (uses SIB b yte) EA = [Base] + [Index]  Scale When Base = EBP the addressing mo de is: Index with 32-bit displacement EA = [Index]  Scale + Disp32 1 1 Base with index and 8-bit displacement (uses SIB b yte) EA = [Base] + [Index]  Scale + Disp8 1 1 Base with index and 32-bit displacemet (uses SIB b yte) EA = [Base] + [Index]  Scale + Disp32

T ABLE D.3 Scale field encoding in IA-32 SIB b yte Scale field Scale 1 1 2 1 4 1 1 8

^ Table D.4 – page 1 T ABLE D.4 IA-32 instructions Mnemonic Size Operands Operation CC flags (Name) performed affected dst src S Z O C ADC B,D reg reg dst  [dst] + [src] + [CF] x x x x (Add with reg mem carry) mem reg reg imm mem imm ADD B,D reg reg dst  [dst] + [src] x x x x (Add) reg mem mem reg reg imm mem imm AND B,D reg reg dst  [dst] ^ [src] x x (Logical reg mem AND) mem reg reg imm mem imm BT D reg reg bit# = [src]; x (Bit test) reg imm8 CF  bit# of [dst] mem reg mem imm8 BTC D reg reg bit# = [src]; x (Bit test and reg imm8 CF  bit# of [dst]; complement mem reg complement bit# mem imm8 of [dst] BTR D reg reg bit# = [src]; x  (Bit test reg imm8 CF bit# of [dst]; and reset) mem reg clear bit# of [dst] to mem imm8 Table D.4 – page 1

             Table D.4 – page 2 T ABLE D.4 ( Continued ) Mnemonic Size Operands Operation CC flags (Name) performed affected dst src S Z O C BTS D reg reg bit# = [src]; x  (Bit test reg imm8 CF bit# of [dst]; and set) mem reg set bit# of [dst] to 1 mem imm8  – CALL D reg ESP [ESP] 4;  (Subroutine mem [ESP] [EIP];  call) EIP EA of dst  CLC CF (Clear carry)  CLI IF (Clear int. flag)  CMC CF [CF] x (Compl. carry) CMP B,D reg reg [dst]  [src] x x x x (Compare) reg mem mem reg reg imm mem imm  DEC B,D reg dst [dst] – 1 x x x (Decrement) mem DIV B,D reg for B: ? ? ? ? (Unsigned mem [AL]/[src];  divide) AL quotient;  AH remainder for D: [EAX]/[src]; EAX  quotient;  ED X remainder Table D.4 – page 2

             Table D.4 – page 3 T ABLE D.4 ( Continued ) Mnemonic Size Operands Operation CC flags (Name) performed affected dst src S Z O C HL T Halts execution un til (Halt) reset or external in terrupt o ccurs IDIV B,D reg for B: ? ? ? ? (Signed mem [AL]/[src];  divide) AL quotient;  AH remainder for D: [EAX]/[src];  EAX quotient;  ED X remainder IMUL B,D reg (double-length product) ? ? x x (Signed mem for B:   m ultiplication) AX [AL] [src] for D:  ED X,EAX [EAX]  [src] D reg reg (single-length pro duct) ? ? x x  reg mem reg  [reg] [src]  IN B,D dst = AL AL or EAX [src] (Isolated or EAX input) src = imm8 or [D X] INC B,D reg dst  [dst] + 1 x x x (Increment ) mem INT D imm8 Push EFLA GS; (Software Push EIP;  in terrupt) EIP address (determined b y imm8) Table D.4 – page 3

^ ^ T ABLE D.4 ( Continued) Mnemonic Size Operands Operation CC flags (Name) performed affected dst src S Z O C IRET D P op EIP; x x x x (Return from P op EFLA GS in terrupt)  LEA D reg mem reg EA of src (Load effectiv e address)  LOOP D target ECX [ECX] – 1; (Lo op) If ( [ECX]  )  EIP target LOOPE D target ECX  [ECX] – 1; (Lo op on If ( [ECX]  equal/zero) ^ [Z] = 1 )  EIP target  LOOPNE D target ECX [ECX] – 1; (Lo op on If ( [ECX]  not equal/ ^ [Z]  1 )  not zero) EIP target MO V B,D reg reg dst  [src] (Mo v e) reg mem mem reg reg imm mem imm  MO VSX B reg reg reg sign extend [src] (Sign extend reg mem b yte in to register) Table D.4 – page 4

          Table D.4 – page 5 T ABLE D.4 ( Continued) Mnemonic Size Operands Operation CC flags (Name) performed affected dst src S Z O C  MO VZX B reg reg reg zero extend [src] (Zero extend reg mem b yte in to register) MUL B,D reg (double-length pro duct) ? ? x x (Unsigned mem for B:   m ultiplication) AX [AL] [src] for D:  ED X,EAX [EAX]  [src]  NEG B,D reg dst 2's-complement x x x x (Negate) mem [dst] NOP alias for: (No op eration) X CHG EAX,EAX  NOT B,D reg dst [dst ] (Logical mem complement) OR B,D reg reg dst  [dst]  [src] x x (Logical OR) reg mem mem reg reg imm mem imm  OUT B,D dst = imm8 dst [AL] or [EAX] (Isolated or [D X] output) src = AL or EAX Table D.4 – page 5

        Table D.4 – page 6 T ABLE D.4 ( Continued) Mnemonic Size Operands Operation CC flags (Name) performed affected dst src S Z O C  POP D reg dst [[ESP]];  (Pop off mem ESP [ESP] + 4 stack) POPAD D Pop eight doublewords (Pop off off stack in to stack in to EDI, ESI, EBP , discard, all registers EBX, EDX, ECX, EAX;  except ESP) ESP [ESP] + 32  – PUSH D reg ESP [ESP] 4; (Push on to mem [ESP]  [src] stac k) imm PUSHAD D Push contents of (Push all EAX, ECX, EDX, EBX, registers ESP , EBP , ESI, EDI on to stack) on to stack;  – ESP [ESP] 32 R CL B,D reg imm8 See Figure 2.32 b ; ? x (Rotate left reg CL src operand is with C flag) mem imm8 rotation count mem CL R CR B,D reg imm8 See Figure 2.32 d ; ? x (Rotate righ t reg CL src operand is with C flag) mem imm8 rotation count mem CL  RET EIP [[ESP]];  (Return from ESP [ESP] + 4 subroutine) Table D.4 – page 6

T ABLE D.4 (Continued) Mnemonic Size Operands Operation CC flags (Name) performed affected dst src S Z O C R OL B,D reg imm8 See Figure 2.32 a ; ? x (Rotate left) reg CL src operand is mem imm8 rotation count mem CL R OR B,D reg imm8 See Figure 2.32 c ; ? x (Rotate righ t) reg CL src operand is mem imm8 rotation count mem CL SAL B,D reg imm8 See Figure 2.30 a ; x x ? x (Shift reg CL src operand is arithmetic mem imm8 shift count left) mem CL same as SHL SAR B,D reg imm8 See Figure 2.30 c ; x x ? x (Shift reg CL src operand is arithmetic mem imm8 shift count right) mem CL  SBB B,D reg reg dst [dst] – [src] x x x x (Subtract reg mem – [CF] with b orrow) mem reg reg imm mem imm SHL B,D reg imm8 See Figure 2.30 a ; x x ? x (Shift reg CL src operand is left) mem imm8 shift count same as SAL mem CL Table D.4 – page 7

^ T ABLE D.4 (Continued) Mnemonic Size Operands Operation CC flags (Name) performed affected dst src S Z O C SHR B,D reg imm8 See Figure 2.30 b ; x x ? x (Shift reg CL src operand is righ t) mem imm8 shift coun t mem CL  STC CF 1 1 (Set carry flag)  STI IF 1 (Set in terrupt flag)  SUB B,D reg reg dst [dst] – [src] x x x x (Subtract) reg mem mem reg reg imm mem imm TEST B,D reg reg [dst] ^ [src]; x x (T est) mem reg set flags based reg imm on result mem imm X CHG B,D reg reg [reg]  [src] (Exchange) reg mem X OR B,D reg reg dst  [dst]  [src] x x (Exclusive reg mem OR) mem reg reg imm mem imm Table D.4 – page 8

    T ABLE D.5 IA-32 conditional jump instructions Mnemonic code name test JS Sign (negative) SF = 1 JNS No sign (positive or zero) SF = JE/JZ Equal/Zero ZF = 1 JNE/JNZ Not equal/Not zero ZF = JO Overflow OF = 1 JNO No overflow OF = JC/JB Carry/Unsigned below CF = 1 JNC/JAE No carry/Unsigned above or equal CF =  JA Unsigned above CF ZF =  JBE Unsigned below or equal CF ZF = 1 JGE Signed greater than or equal SF  OF = JL Signed less than SF  OF = 1  JG Signed greater than ZF (SF  OF) =  JLE Signed less than or equal ZF (SF  OF) = 1