UNIT: 2 INSTRUCTION SET OF 8086.

Slides:



Advertisements
Similar presentations
Machine Instructions Operations
Advertisements

NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
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.
Computer Organization & Assembly Language
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.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Microcomputer & Interfacing Lecture 3
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Faculty of Engineering, Electrical Department,
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Department of Computer Science and Software Engineering
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.
Logical and Bit Operations Chapter 9 S. Dandamudi.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
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.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Microprocessor & Assembly Language
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Chapter four – The 80x86 Instruction Set Principles of Microcomputers 2016年3月17日 2016年3月17日 2016年3月17日 2016年3月17日 2016年3月17日 2016年3月17日 1 Chapter Four.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Assembly language programming
Computer Architecture and Assembly Language
Instruction set Architecture
Introduction to assembly programmıng language
Format of Assembly language
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
Microprocessor Systems Design I
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Chapter 3 Bit Operations
EE3541 Introduction to Microprocessors
Machine control instruction
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
Microcomputer Programming
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
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.
CS-401 Computer Architecture & Assembly Language Programming
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
CS 301 Fall 2002 Computer Organization
Shift & Rotate Instructions)
Symbolic Instruction and Addressing
Shift & Rotate Instructions)
Chapter 5 Arithmetic and Logic Instructions
Assembler Directives end label end of program, label is entry point
Chapter 6 –Symbolic Instruction and Addressing
Microprocessor and Assembly Language
Computer Organization and Assembly Language
CNET 315 Microprocessor & Assembly Language
Chapter 8: Instruction Set 8086 CPU Architecture
Shift and Rotate Instructions.
Introduction to 8086 Assembly Language
CS-401 Computer Architecture & Assembly Language Programming
Presentation transcript:

UNIT: 2 INSTRUCTION SET OF 8086

Contents Assembler instruction format. Data transfer and arithmetic. Branch type Loop NOP & HALT Flag manipulation. Logical and shift and rotate instructions. Directives and operators

OBJECTIVES Basic instruction format for data processing in 8086 To use arithmetic and logic operations to accomplish simple binary,BCD and ASCII aritmetic. To use shift and rotate instructions Procedure for assembling a program..

Assembler instruction format General format of an assembler instruction is: Label: Mnemonic Operand,Operand ;Comment. Illustration of instruction format BRADDR: ADD AX, COUNT[BX] ; ADD ELEMENT OF COUNT TO AX Label-Provides a means of branching to this instruction Comment Mnemonic Source Operand Destination operand

Data Transfer and arithmetic The MOV instruction is used to transfer 8 and 16-bit data to and from registers. Either the source or destination has to be a register. The other operand can come from another register, from memory, from immediate data Instruction:MOV Operand :REG, memory memory, REG REG, REG memory, immediate REG, immediate SREG, memory memory, SREG REG, SREG SREG, REG

MOV instruction Example: Description Copy operand2 to operand1. ORG 100h MOV AX, 0B800h ; set AX = B800h (VGA memory). MOV DS, AX ; copy value of AX to DS. MOV CL, 'A' ; CL = 41h (ASCII code). MOV CH, 01011111b ; CL = color attribute. MOV BX, 15Eh ; BX = position on screen. MOV [BX], CX ; w.[0B800h:015Eh] = CX. RET ; returns to operating system. Description Copy operand2 to operand1. The MOV instruction cannot set the value of the CS and IP registers. copy value of one segment register to another segment register (should copy to general register first). copy immediate value to segment register (should copy to general register first).

Branch Type A branch instruction transfers contro from the normal sequence of instructions by putting the address of the instruction to be branched in the program counter. They are of two types: Conditional branch Unconditional branch

Conditional branch instructions

UnConditional branch instructions Instruction Description Condition

The LOOP Instruction This instruction decrements the cx register and then branches to the target location if the cx register does not contain zero. Since this instruction decrements cx then checks for zero, if cx originally contained zero, any loop you create using the loop instruction will repeat 65,536 times. For example, the following loop initializes a 256 element array of bytes to the values 1, 2, 3, ... mov ecx, 255 ArrayLp: mov Array[ecx], cl loop ArrayLp mov Array[0], 0

The LOOPE/LOOPZ Instruction Loope/loopz (loop while equal/zero, they are synonyms for one another) will branch to the target address if cx is not zero and the zero flag is set. The 80x86 Instruction Set after cmp or cmps instruction, and is marginally faster than the comparable 80386/486 instructions if you use all the features of this instruction. For example, the following loop scans through an array looking for the first non-zero byte, but it does not scan beyond the end of the array: mov cx, 16 ;Max 16 array elements. mov bx, -1 ;Index into the array . SearchLp: inc bx ;Move on to next array element. cmp Array[bx], 0 ;See if this element is zero. loope SearchLp ;Repeat if it is. je AllZero ;Jump if all elements were zero.

NOP and HALT Example: Description Description Example ; do nothing, 3 times: NOP RET Description NOP No operands No Operation. HALT Description HLT has No operands. It Halts the System. Example MOV AX, 5 HLT

Logical and Shift and Rotate and Instructions The 80x86 family provides five logical instructions. four rotate instructions. three shift instructions. The logical instructions are : and, or, xor, test, and not. The rotate instructions are: ror, rol, rcr, and rcl. The shift instructions are: shl/sal, shr, and sar.

The Logical Instructions: AND, OR, XOR, and NOT The 80x86 logical instructions operate on a bit-by-bit basis. Both eight, sixteen, and thirty-two bit versions of each instruction exist. The and, not, or, and xor instructions do the following: and dest, source ;dest := dest and source or dest, source ;dest := dest or source xor dest, source ;dest := dest xor source not dest ;dest := not dest. The specific variations are and reg, reg and mem, reg and reg, mem and reg, immediate data and mem, immediate data

The Shift Instructions: SHL/SAL, SHR, SAR, SHLD, and SHRD The 80x86 supports three different shift instructions: Shl(Shift left) Sal(shift arithmatic left) Shr(shift right) . The general format for a shift instruction is shl dest, count sal dest, count shr dest, count sar dest, count Dest is the value to shift and count specifies the number of bit positions to shift. For example, the shl instruction shifts the bits in the destination operand to the left the number of bit positions specified by the count operand. The shld and shrd instructions use the format: shld dest, source, count shrd dest, source, count

SAR(Shift arithmetic right) Description Example MOV AL, 0E0h ; AL = 11100000b SAR AL, 1 ; AL = 11110000b, CF=0. MOV BL, 4Ch ; BL = 01001100b SAR BL, 1 ; BL = 00100110b, CF=0. RET Operands include memory, immediate REG, immediate memory. Shift Arithmetic operand1 Right. The number of shifts is set by operand2. Shift all bits right, the bit that goes off is set to CF. The sign bit that is inserted to the left-most position has the same value as before shift.

The shr instruction shifts all the bits in the destination operand to the right one bit shifting a zero into H.O. bit. If the shift count is zero, the shr instruction doesn’t affect any flags. The carry flag contains the last bit shifted out of the L.O. bit of the operand. If the shift count is one, the overflow flag will contain the value of the H.O. bit of the operand prior to the shift. The zero flag will be one if the shift produces a zero result. The sign flag will contain the H.O. bit of the result, which is always zero. The parity flag will contain one if there are an even number of one bits in the L.O. byte of the result. The auxiliary carry flag is always undefined after the shr instruction.

The SHLD and SHRD Instructions The shld and shrd instructions provide double precision shift left and right operations, respectively. These instructions are available only on 80386 and later processors. Their generic forms are shld operand1, operand2, immediate shld operand1, operand2, cl shrd operand1, operand2, immediate shrd operand1, operand2, cl Operand2 must be a sixteen or thirty-two bit register. Operand1 can be a register or a memory location. Both operands must be the same size. The immediate operand can be a value in the range zero through n-1, where n is the number of bits in the two operands; it specifies the number of bits to shift.

The SHLD and SHRD Instructions Cont… The shld instruction sets the flag bits as follows: • If the shift count is zero, the shld instruction doesn’t affect any flags. • The carry flag contains the last bit shifted out of the H.O. bit of the operand1. • If the shift count is one, the overflow flag will contain one if the sign bit of operand1 changes during the shift. If the count is not one, the overflow flag is undefined. • The zero flag will be one if the shift produces a zero result. • The sign flag will contain the H.O. bit of the result. The shld instruction is useful for packing data from many different sources.

The Rotate Instructions: RCL, RCR, ROL, and ROR The rotate instructions shift the bits around, just like the shift instructions, except the bits shifted out of the operand by the rotate instructions recirculate through the operand. They include rcl(rotate through carry left). ror(rotate through carry right). rol (rotate left). ror(rotate right)

RCL The rcl (rotate through carry left) s, rotates bits to the left, through the carry flag, and back into bit zero on the right. The rcl instruction sets the flag bits as follows: The carry flag contains the last bit shifted out of the H.O. bit of the operand. If the shift count is one, rcl sets the overflow flag if the sign changes as a result of the rotate. If the count is not one, the overflow flag is undefined. The rcl instruction does not modify the zero, sign, parity, or auxiliary carry flags.

RCR The rcr(rotate through carry right ) instruction is the complement to the rcl instruction. It shifts its bits right through the carry flag and back into the H.O. bit. This instruction sets the flags in a manner analogous to rcl: The carry flag contains the last bit shifted out of the L.O. bit of the operand. If the shift count is one, then rcr sets the overflow flag if the sign changes. The rcr instruction does not affect the zero, sign, parity, or auxiliary carry flags

ROL The rol instruction is similar to the rcl instruction in that it rotates its operand to the left the specified number of bits. The rol instruction sets the flags identically to rcl. Other than the source of the value shifted into bit zero, this instruction behaves exactly like the rcl instruction Like shl, the rol instruction is often useful for packing and unpacking data.

DIRECTIVES AND OPERATOR Assembler: is a program that accepts an assembly language program as input and converts it into an object module and prepares for loading the program into memory for execution. Loader (Linker) further converts the object module prepared by the assembler into executable form, by linking it with other object modules and library modules. The final executable map of the assembly language program is prepared by the loader at the time of loading into the primary memory for actual execution.

Procedure for assembling a program Assembling a program proceeds statement by statement sequentially. The first phase of assembling is to analyze the program to be converted. This phase is called Pass1 defines and records the symbols, pseudo operands and directives. The second phase looks for the addresses and data assigned to the labels. It also finds out codes of the instructions from the instruction machine, code database and the program data. It processes the pseudo operands and directives. It is the task of the assembler designer to select the suitable strings for using them as directives, pseudo operands or reserved words and decides syntax.

Assembler Directives Directives are also called as pseudo operations that control the assembly process. end label end of program, label is entry point proc far|near begin a procedure; far, near keywords specify if procedure in different code segment (far), or same code segment (near) endp end of procedure page set a page format for the listing file title title of the listing file .code mark start of code segment .data mark start of data segment .stack set size of stack segment

Directive for string data in a memory segment DB define byte DW define word DD define double word DQ define 10 bytes Example Data1 DB 10H,11H,12H Data2 DW 1234H SEGMENT: statement to indicate the start of the program and its symbolic name.

Summary Basic assembler instruction format for programming purpose. Data movement instruction transfer data between registers, a register and a memory. Branch type instructions used for change of control sequence. Various types of operators used in rotate and shift operations are included. Procedure for real time assembling a program is illustrated.