Www.advancedmsinc.com EZ-COURSEWARE State-of-the-Art Teaching Tools From AMS Teaching Tomorrow’s Technology Today.

Slides:



Advertisements
Similar presentations
Addressing Mode Wannachai Wannasawade Department of Computer Education
Advertisements

Instruction Set of 8086 Engr. M.Zakir Shaikh
COMP 2003: Assembly Language and Digital Logic
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.
Introduction to Assembly Here we have a brief introduction to IBM PC Assembly Language –CISC instruction set –Special purpose register set –8 and 16 bit.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
Intel’s 8086 instruction-set
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.
Microcomputer & Interfacing Lecture 3
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Ch. 7 Logic, Shift and Rotate instr.
Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF.
Types of Registers (8086 Microprocessor Based)
Faculty of Engineering, Electrical Department,
Strings, Procedures and Macros
5. Assembly Language. Basics of AL Program data Pseudo-ops Array Program structures Data, stack, code segments.
Arithmetic Flags and Instructions
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.b: Arithmetic Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
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.
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]
ECE 353 Introduction to Microprocessor Systems Michael J. Schulte Week 6.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
Micro-Computer Applications: Arithmetic, Logic & Data Movement Instructions Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
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.
Microprocessor Systems Design I
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Chapter instruction description and assembler directives from Microprocessors and Interfacing by Douglas Hall.
Today we are going to discuss about,
Microprocessor Systems Design I
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
Microprocessor Systems Design I
EE3541 Introduction to Microprocessors
EE3541 Introduction to Microprocessors
INSTRUCTION SET.
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 =
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
4.4 Bit Manipulation Instructions
Introduction to Assembly Language
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
ارايه دهنده : حسن عسكرزاده
اصول اساسی برنامه نویسی به زبان اسمبلی
Data formats or Instruction formats of 8086:
ADDITION Register Addition. ADD AX,BX AX=AX+BX 2. Immediate Addition.
Introduction to 8086 Assembly Language Programming
Chapter 5 Arithmetic and Logic Instructions
CNET 315 Microprocessor & Assembly Language
Chapter 8: Instruction Set 8086 CPU Architecture
Ravindra College of Engineering for women
UNIT-II ADDRESSING MODES & Instruction set
Presentation transcript:

EZ-COURSEWARE State-of-the-Art Teaching Tools From AMS Teaching Tomorrow’s Technology Today

Lect 4: Instruction Encoding and Instruction Set

Instruction Encoding T T T T mod TTT r/m ss index base d32| 16 | 8 | nonedata32 |16 |8 | none opcode (one or two bytes) (T represents an opcode bit.) “mode r/m” byte “s-i-b” byte register and address mode specifier address displacement immediate data General Instruction Format

Encoding of Operand Length Field w FieldOperation SizeOperation SizeDuring 16-bit Data Operations 0 8 Bits 8 Bits 1 16 Bits 16 Bits Encoding of reg Field When w Field is not present in Instruction

Encoding of 16-bit Address Mode with “mod r/m” Byte

Encoding of 32-bit Address Mode with “mod r/m” Byte (no ‘s-i-b’)

Encoding of 32-bit Address Mode( “mod r/m” byte and “s-i-b” byte present): * Important Note: When index field is 100, indicating no index register, then ss field MUST equal 00. If index is 100 and ss does not equal 00, the effective address is undefined.

Encoding the instruction in Machine code Example: –MOV BL, AL ; MOV opcode byte: dw d = 0 REG field is source; w =1 for word operation; mod r/m = ; REG = 000 First byte : (88H); Second byte: (C3H) –ADD [BX][DI]+1234H, AX; ADD opcode byte : dw d=0 REG field is source; w =1 for word operation; mod r/m = ; REG = 000 First byte : (01H); Second byte: (81H) Resulting Machine code: H

Encoding the instruction in Machine code –MOV ECX,2 ; MOV opcode byte: 1011w reg (immediate to reg short form) MOV AX,[EBX+2*ECX] MOV opcode byte: w (reg/mem to reg) MOV ECX,2 ; (B9H) MOV AX, [EBX+2*ECX] First byte : Second Byte: Third byte: mod REG r/m ss index base The Resulting Machine code: 8B044B Address size prefix : (67) ; Operand size prefix: (66) The Result: 66 | B | 8B 04 4B

Instruction Set base instruction set encoding table: See Fig 4.5 Instruction Types –General Data Transfer –Arithmetic/Logic –Shift/Rotate –Bit test and bit scan –Flag Control –Control Transfer –String handling –System Control

Data Transfer Instructions –MOV : 8 instructions ; operation: (dest)  (src), Flags Affected: none MOV AX,[BP] mod reg r/m displacement There are several machine codes to represent one MOV instruction. The assembler must choose an efficient one. –MOVSX: sign-extend MOVSX EBX, AX (reg from reg/mem) –MOVZX: zero-extend MOVZX CX, DATA (reg from reg/mem) General Data Transfer

General Data Transfer –XCHG operation (dest)  (src) ; flags affected : none reg/mem with reg, reg with accumulator (short form) XCHG AX,DX –XLAT : Translate String ; operation (AL)  ((AL)+(BX)) ; flags affected: none –Load Effective Address and Load Pointer Instructions LEA : Load effective address ; LEA SI, [DI+BX+5H] LDS, LSS, LES, LFS, LGS : Load full pointer (offset: SBA) into reg and seg reg –PUSH operation : ((SP))  (src) (SP)  (SP)-2 flags affected: none –POP –PUSHA, POPA (all general registers onto/from stack) –PUSHF, POPF

Arithmetic Instructions ADD, ADC, INC, AAA, DAA SUB, SBB, DEC, NEG, AAS, DAS MUL, IMUL, AAM, DIV, IDIV, AAD, CBW, CWD –AAA : ASCII adjust for addition; flags affected: AF, CF, OF, SF, ZF, PF undefined operation: ALcarry  (AL) >0F9H; if ((AL)&0FH) >9 or (AF) = 1 then (AL)  (AL)+6)&0FH; (AH)  (AH)+1+ALcarry; (AF)  1; (CF)  1; else AF  0; CF  0; (AL)  (AL)&0FH ;

Arithmetic Instructions Example : AL : 32H ASCII code for number 2; BL: 34H ASCII code for 4 ADD AL,BL ---- AL :66H AAA AL : 6H –DAA (Decimal adjust for addition: two packed decimal) operation: if ((AL)&0FH)>9 or (AF)=1 then (AL)  (AL)+6, (AF)  1 if ((AL)&0F0H) >90H or (CF) =1 then (AL)  (AL)+60H, (CF)  1

Logic Instructions –AND, OR, XOR, NOT Shift Instructions –SAL/SHL, SHR/SAR, SHLD, SHRD: –SHL AX, 1; SAR AX, CL Rotate Instructions –ROL, ROR, RCL, RCR –ROR AX,1; ROL AX, CL

Bit Test Instructions Bit Test and Bit Scan Instructions –BT(Bit Test), BTR(Bit test and reset), BTS(Bit test and set), BTC(Bit test and complement), BSF(Bit scan forward), BSR(Bit scan reverse) –BT D, S ; CF  BIT[D,S]; saves the value of the bit indicated by the first operand and the bit offset into the CF flag –BSF r16,r/m16 or BSF r32, r/m32 ; scans the bits in the second word or double word operand starting with bit 0. The ZF flag is set if all the bits are 0; otherwise, the ZF flag is cleared and the destination register is loaded with the bit index of the first set bit.

Flag Control Set Flag-Control Instructions –LAHF(Load AH from flags), SAHF(Store AH into flags), CLC, STC, CMC, CLI, STI –AH : |SF|ZF| - |AF| - |PF| - |CF| Compare and Set Instructions –CMP –SETcc r/m8: if condition then r/m8  1(not FF) else r/m8  0; SETA, SETAE,.....

Control Transfer Jump Instructions –Unconditional(JMP) and Conditional Jumps(JA, JAE,.... ) –JMP : Intrasegment jump, Intersegment jump Intrasegment jump : short(8-bit displacement: -126 to +129), direct within segment (16-bit or 32-bit relative), r/m indirect with segment Intersegment jump : direct intersegment (full offset and selector), indirect intersegment –Jcc : conditional jump; 8-bit or full displacement JA, JAE,....

Control Transfer Subroutines and Subroutine-Handling Instructions –CALL and Return Instructions –CALL : intrasegment and intersegment call; Intrasegment : CALL rel16, or rel32, CALL indirect within segment Intersegment : CALL direct intersegment, CALL indirect intersegment –RET Intrasegment : RET within segment, RET within segment Adding Immediate to SP Intersegment : RET, RET adding immediate to SP

Control Transfer –Stack Frame Instructions: ENTER and LEAVE to allocate and deallocate a data area called a stack frame ENTER : make a stack frame –ENTER imm16,0; Make procedure stack frame –ENTER imm16,1; Make stack frame for procedure parameter –ENTER imm16,imm8: Make stack frame for procedure parameter –first operand : the number of bytes to be allocated on the stack for local data storage second operand: lexical nesting level of the routine

Control Transfer Procedure AProcedure B Enter 32, 1Enter 12, 2 Leave Ret Procedure C Enter 16, 3 Leave Ret Leave Ret Data for Proc. C (16 bytes) BP for Proc. C BP for Proc. B BP for Proc. A BP for Proc. B Ret addr for proc. B Data for Proc. B (12 bytes) BP for Proc. B BP for Proc. A Ret addr for proc. A Data for Proc. A (32 bytes) BP for Proc. A Old BP Stack frame for A Stack frame for C Stack frame for B BP when executing Procedure C BP when executing Procedure B BP when executing Procedure A

String Handling Loop and Loop-handling Instructions –LOOP, LOOPE/Z, LOOPNE/NZ: CX must be preloaded with a count String and String-Handling Instructions –MOVSB/W/D, compare string, scan string, load string, store string –the contents of both SI and DI are automatically incremented or decremented. –REP : repeat string; Check Array Index Against Bounds –BOUND r16, m16&16 : check if r16 is within bounds –BOUND r32, m32&m32: check if r32 is within bounds operation: if (LeftSRC [RightSRC+OperandSize/8]) then Interrupt 5;