Docsity

Microprocessor Instructions, Lecture notes of Microprocessors

Toggle sidebar
bg1
0LFURSURFHVVRU/D
E
Instruction Set:
Instructions Operands Description
MOV
REG, memor y
memory, REG
REG, REG
memory, immediate
REG, immediate
SREG, memo ry
memory, SREG
REG, SREG
SREG, REG
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 gener al register first).
•Copy immediate value to segment register (should
copy to general register first).
Algorithm: operand1 = operand2
Ex: Mov AX,BX ;Copy contents of BX to AX
Mov si,00h ;load Si with 00h
MUL REG
Memory
Unsigned Multiply.
Multiply the contents of REG/Memory with contents of AL
register.
Algorithm:
When operand is a byte:
AX = AL * operand.
When operand is a word:
(DX: AX) = AX * o perand.
CMP
REG, memor y
memory, REG
REG, REG
memory, immediate
REG, immediate
Compare.
Algorithm: operand1 - operand2
Result is not stored anywhere, flags are set (OF, SF, ZF, AF,
PF, CF) according to result.
JMP Label
Unconditional Jump.
Transfers control to another part of the program. 4-byte address
may be entered in this form: 1234h: 5678h, first value is a
segment second value is an offset.
Algorithm: always jump
JA Label
Jump If Above.
Short Jump if first operand is Above second operand (as set by
CMP instruction). Unsigned.
Algorithm: if (CF = 0) and (ZF = 0) then jump
JAE Label
Jump If Above Or Equal
Short Jump if first operand is Above or Equal to second
operand (as set by CMP instruction). Unsigned.
Algorithm:
if CF = 0 then jump
JB Label
Jump If Below.
Short Jump if first operand is Below second operand (as set by
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Microprocessor Instructions and more Lecture notes Microprocessors in PDF only on Docsity!

Instruction Set:

Instructions Operands Description

MOV

REG, memory memory, REG REG, REG memory, immediate REG, immediate

SREG, memory memory, SREG REG, SREG SREG, REG

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).

Algorithm: operand1 = operand

Ex: Mov AX,BX ;Copy contents of BX to AX

Mov si,00h ;load Si with 00h

MUL REG

Memory

Unsigned Multiply. Multiply the contents of REG/Memory with contents of AL register. Algorithm:

When operand is a byte: AX = AL * operand.

When operand is a word: (DX: AX) = AX * operand.

CMP

REG, memory memory, REG REG, REG memory, immediate REG, immediate

Compare.

Algorithm: operand1 - operand

Result is not stored anywhere, flags are set (OF, SF, ZF, AF, PF, CF) according to result.

JMP Label

Unconditional Jump.

Transfers control to another part of the program. 4-byte address may be entered in this form: 1234h: 5678h, first value is a segment second value is an offset.

Algorithm: always jump

JA Label

Jump If Above.

Short Jump if first operand is Above second operand (as set by CMP instruction). Unsigned.

Algorithm: if (CF = 0) and (ZF = 0) then jump

JAE Label

Jump If Above Or Equal

Short Jump if first operand is Above or Equal to second operand (as set by CMP instruction). Unsigned. Algorithm:

if CF = 0 then jump

JB Label

Jump If Below.

Short Jump if first operand is Below second operand (as set by

CMP instruction). Unsigned.

Algorithm:

if CF = 1 then jump

JBE Label

Jump If Below Or Equal

Short Jump if first operand is Below second operand (as set by CMP instruction). Unsigned.

Algorithm:

if CF = 1 then jump

JC Label

Jump If Carry

Short Jump if Carry flag is set to 1.

Algorithm:

if CF = 1 then jump

JE Label

Jump If Equal.

Short Jump if first operand is Equal to second operand (as set by CMP instruction). Signed/Unsigned.

Algorithm:

if ZF = 1 then jump

JG Label

Jump If Greater

Short Jump if first operand is Greater then second operand (as set by CMP instruction). Signed.

Algorithm:

if (ZF = 0) and (SF = OF) then jump

JGE Label

Jump If Greater Or Equal.

Short Jump if first operand is Greater or Equal to second operand (as set by CMP instruction). Signed.

Algorithm:

if SF = OF then jump

JL Label

Jump If Less than.

Short Jump if first operand is Less then second operand (as set by CMP instruction). Signed.

Algorithm:

if SF <> OF then jump

JLE Label

Jump If Less Or Equal.

Short Jump if first operand is Less or Equal to second operand (as set by CMP instruction). Signed.

Algorithm:

OR REG, memory memory, REG REG, REG memory, immediate REG, immediate

Logical OR between all bits of two operands. Result is stored in first operand.

These rules apply:

1 OR 1 = 1; 1 OR 0 = 1 0 OR 1 = 1; 0 OR 0 = 0

SUB

REG, memory memory, REG REG, REG memory, immediate REG, immediate

Subtract.

Algorithm:

operand1 = operand1 - operand

DAA No Operands

Decimal adjust After Addition. Corrects the result of addition of two packed BCD values.

Algorithm: if low nibble of AL > 9 or AF = 1 then:

  • AL = AL + 6
  • AF = 1

if AL > 9Fh or CF = 1 then:

  • AL = AL + 60h

• CF = 1

DAS No Operands

Decimal adjust After Subtraction. Corrects the result of subtraction of two packed BCD values.

Algorithm: if low nibble of AL > 9 or AF = 1 then:

  • AL = AL - 6
  • AF = 1

if AL > 9Fh or CF = 1 then:

  • AL = AL - 60h

• CF = 1

INC REG

memory

Increment.

Algorithm: operand = operand + 1

DEC REG

Memory

Decrement.

Algorithm: operand = operand – 1

DIV

REG

Memory

Unsigned Divide.

Algorithm:

when operand is a byte: AL = AX / operand AH = remainder (modulus) when operand is a word: AX = (DX AX) / operand DX = remainder (modulus)

SHL

memory, immediate REG, immediate

memory, CL REG, CL

Shift Left.

Shift operand1 Left. The number of shifts is set by operand2.

Algorithm:

  • Shift all bits left, the bit that goes off is set to CF.
  • Zero bit is inserted to the right-most position.

SHR

memory, immediate REG, immediate

memory, CL REG, CL

Shift Right.

Shift operand1 Right. The number of shifts is set by operand2.

Algorithm:

  • Shift all bits right, the bit that goes off is set to CF.
  • Zero bit is inserted to the left-most position.

ROL

memory, immediate REG, immediate

memory, CL REG, CL

Rotate Left.

Rotate operand1 left. The number of rotates is set by operand2.

Algorithm:

Shift all bits left, the bit that goes off is set to CF and the same bit is inserted to the right-most position.

ROR

memory, immediate REG, immediate

memory, CL REG, CL

Rotate Right.

Rotate operand1 right. The number of rotates is set by operand2.

Algorithm:

Shift all bits right, the bit that goes off is set to CF and the same bit is inserted to the left-most position.

CALL

procedure name label

Transfers control to procedure, return address is (IP) pushed to stack.

RET No operands Or even immediate date

Return from near procedure.

Algorithm:

  • Pop from stack: o IP

if immediate operand is present: SP = SP + operand

IN

AL, im.byte AL, DX AX, im.byte AX, DX

Input from port Into AL or AX. Second operand is a port number. If required to access port number over 255 - DX register should be used.

OUT

AL, im.byte AL, DX AX, im.byte AX, DX

Output from AL or AX to port. First operand is a port number. If required to access port number over 255 - DX register should be used.

AAS No Operands

Algorithm:

if low nibble of AL > 9 or AF = 1 then:

  • AL = AL - 6
  • AH = AH - 1
  • AF = 1
  • CF = 1

else

  • AF = 0
  • CF = 0

in both cases: cLear the high nibble of AL.

Example: MOV AX, 02FFh ; AH = 02, AL = 0FFh AAS ; AH = 01, AL = 09

AAM No Operands

ASCII Adjust after Multiplication. Corrects the result of Multiplication of two BCD values.

Algorithm:

• AH = AL / 10

  • AL = remainder

Example: MOV AL, 15 ; AL = 0Fh AAM ; AH = 01, AL = 05

DOS Interrupt INT 2lH Function Calls

01H READ THE KEYBOARD

Entry AH = 01H

Exit AL = ASCII character

Notes If Al = 00H, the function call must be invoked again to read an

extEnded ASCII character. This function call automatically

echoes whatever is typed to the video screen.

02H WRITE TO STANDARD OUTPUT DEVICE

Entry AH = 02H

DL = ASCII character to be displayed

Notes This function displays character on video display

06H DIRECT CONSOLE READ/WRITE

Entry AH = 06H

DL = 0FFH or DL = ASCII character

Exit AL = ASCII character

Notes If DL = 0FFH on entry, then this function reads the console. If

DL = ASCII character, then this function displays the ASCII

character on the console (CON) video screen.

09H DISPLAY A CHARACTER STRING

Entry AH = 09H

DS:DX = Address of the character string

Exit AL = ASCII character

Notes The character string must End with an ASCII $ (24H). The

character string can be of any length and may contain control

characters such as carriage return (0DH) and line feed (0AH).

2CH READ SYSTEM TIME

Entry AH = 2CH

Exit CH = Hours (0-23)

CL = Minutes

DH = Seconds

DL = Hundredth of seconds

Notes All times are returned in binary form, and hundredths of

seconds may not be available.

3CH CREATE A NEW FILE

Entry AH = 3CH

CX = Attribute word

DS:DX = Address of ASCII-Z string file name

Exit AX = Error code if carry set

AX = File handle if carry cLeared

Notes The attribute word can contain any of the following(adding

together) :