320 likes | 809 Views
80x86 Instruction Set. Dr. Qiang Lin. Most of assembler instructions presented are supported by all of the following Intel processors: 80186, 80286, 80386, 80486, Pentium (80586) Five major instruction categories: Transfer and Set Arithmetic Logic Jump Miscellaneous. Overview.
E N D
80x86 Instruction Set Dr. Qiang Lin
Most of assembler instructions presented are supported by all of the following Intel processors: 80186, 80286, 80386, 80486, Pentium (80586) Five major instruction categories: Transfer and Set Arithmetic Logic Jump Miscellaneous Overview
Example 1: MOV AX,0006h ; Move immediate data to AX register MOV BX,AX ; Move AX register data to BX register This small program moves the value of 0006H to the AX register, then it moves the content of AX (0006h) to the BX register Example 2: MOV AX,2000h ; Move immediate data to AX register MOV DS,AX ; Load DS segment register MOV SI, 100h ; Load immediate data to SI index register MOV DI, 120h ; Load immediate data to DI index register MOV CX, 10h ; Load immediate data to CX register MOV AH, [SI], ; Move memory data pointed by [SI] to AH register MOV [DI], AH ; Move AH register to memory located at [DI] Transfer Instructions Examples 1
Bool := ((A <= B) and (D = E)) or (F <> G) MOV AX, A CMP AX, B SETLE BL MOV AX, D CMP AX, E SETE BH AND BL, BH MOV AX, F CMP AX, G SETNE BH OR BL, BH MOV Bool, BH Set Instructions Example
Example 1: PUSH DS ; Push current DS content to stack MOV AX,0 ; Move immediate data to AX register PUSH AX ; Push 0 to stack MOV AL, 0A1H CBW CWD Example 2: IN AL, 60h ; Read keyboard port MOV DX,378h ; Point at LPT1: data port IN AL, DX ; Read data from printer port INC AX ; Bump ASCII code by one OUT DX, AL ; Write data in AL to printer port Transfer Instructions Examples 2
Example 1: J = K + M MOV AX, K ADD AX,M MOV J, AX Example 2: J = K + M + N + P MOV AX, K ADD AX,M ADD AX,N ADD AX,P MOV J, AX Arithmetic Instructions Examples 1
Example 1: J = K - J MOV AX, K SUB J, AX MOV J, AX Example 1: J = J - (K + M) MOV AX, J SUB AX, K SUB AX, M MOV J, AX or MOV AX, K ADD AX, M SUB J, AX Arithmetic Instructions Examples 2
Example 1: ((J*7 + K) * 6 + M) * 2 MOV BX, J IMUL BX, 7 ADD BX, K IMUL BX, 6 ADD BX, M ADD BX, BX Example 2: J = K/ M (unsigned) MOV AX, K MOV DX, 0 ; Zero extend unsigned value in AX to DX DIV M MOV J, AX Arithmetic Instructions Examples 3
SHL/SAL Move each bit in destination operand one bit to left by No. of times specified by count operand Zeros fill vacated positions at L.O. bit; H.O. bit shifts into carry flag SHL AH, 4 ; Move L.O. bits to H.O. position SAR Move each bit in destination operand one bit to right by No. of times specified by count operand H.O. bit fills vacated position at H.O. bit; L.O. bit shifts into carry flag SAR AH, 4 SHL\SAL\SAR Instructions
RCL RCR ROL ROR RCL\RCR\ROL\ROR Instructions
Except NOT, AND, OR and XOR instructions affect flags as follows: Clear carry flag Clear overflow flag Set zero flag if result is zero and clear it otherwise Copy H.O. bit of result into sign flag Set parity flag according to parity (number of one bits) in result Scramble auxiliary carry flag NOT instruction does not affect any flags 80x86 Logic Instructions 2
SHR\SHLD\SHRD Instructions • SHR • SHLD/SHRD • Provide double precision shift left and right operations, respectively • Available only on 80386 and later processors with forms of SHLD operand1, operand2, immediate SHLD operand1, operand2, CL SHRD operand1, operand2, immediate SHRD operand1, operand2, CL
SHRD Instruction Example • Let • ax contains a value in range 0..99 representing a year (1900..1999) • bx contains a value in the range 1..31 representing a day, and • cx contains a value in the range 1..12 representing a month • Pack these data into dx as follows: SHRD DX, AX, 7 SHRD DX, BX, 5 SHRD DX, CX, 4
80x86 Miscellaneous Instructions • LEA - Loads specified 16 or 32 bit general purpose register with effective • address of the specified memory location using formats of: • LEA reg16, mem or LEA reg32, mem(only for 80386 or later processors) • Examples: • LEA AX, [BX] • LEA BX, 3[BX] • LEA AX, 3[BX] • LEA BX, 4[BP+SI] • LEA AX, -123[DI]
Example POP AX JMP AX Example CALL SUB CALL DwordTbl[BX] Example SUB: PUSH AX PUSH BX …. POP BX POP AX RET Jump Instructions Examples 1