Вы находитесь на странице: 1из 23

Arithmetic Instructions

8086

DAA
The DAA instruction functions like
AAA
Handles packed BCD (binary code
decimal)
DAA's main purpose is to add strings
of BCD digits (with two digits per
byte).

The Algorithm
The algorithm for daa is
if ( (AL and 0Fh) > 9 or (AuxC = 1)) then
al := al + 6 AuxC := 1
carry.
endif

;Set Auxilliary

if ( (al > 9Fh) or (Carry = 1)) then


al := al + 60h
Carry := 1; ;Set carry flag.
endif

Program Example
AL = 53
ADD AL,CL

DAA
C>9)

CL = 29
;AL <- (AL)+(CL)
;AL <- 7C
;AL<- 7C+06(AS
;AL = 82

AL = 73

CL = 29

ADD AL, CL
; AL <- AL+ CL

; AL <- 73+29

; AL<- 9C;

;AL <- 02 CF = 1
DAA
; AL<-02 AND CF = 1

AL = 73 CL = 29
AL + CL = 9C
9 C + 06 = A 2 msb> 9
So A2 + 60 GIVES CF = 1 ; SET CF
AND 02 IN AL or AL<- 02

DAS
The DAS instruction handles DECIMAL
ADJUST BCD values,
algorithm:
if ( (AL and 0Fh) > 9 or (AuxC = 1)) then
al := al -6
AuxC = 1

endif
if ((AL AND F0h )>9or Carry = 1) then
al := al - 60h
Carry := 1 ;Set the Carry flag.

endif

AL = 75

BH = 46

SUB AL, BH
; AL<- 2 F = (AL)-(BH)

;AF = 1

;AL <- 29(as F>9 , F-6 = 9)


DAS
; AL<- 29 (as F>9, F-6 =9)

AL = 38 CH = 61
SUB AL, CH
;AL <- D7 CF
=1(BORROW )
DAS
; AL<- 77( as D>9 , D-6 =7)

;CF = 1(borrow)

NEG
Negate Instruction
takes the two's complement of a byte or word.
It takes a single (destination) operation and
negates it.
The syntax for this instruction is
NEG DEST

It computes the following:


DEST := 0 - DEST
This effectively reverses the sign of the destination
operand.

If OF flag is set Operation is not Successful

If the operand is zero, its sign does not


change, although this clears the carry
flag.
Negating any other value sets the carry
flag.
Negating a byte containing -128, a word
containing -32,768, or a double word
containing -2,147,483,648 does not
change the operand, but will set the
overflow flag.
NEG always updates the A, S, P, and Z
flags.

The allowable forms are:


NEG REG
NEG MEM

The operands may be eight, sixteen, or


(on the 80386 and later) thirty-two bit
values.
Some examples: ;
J := - J
NEG J ;

J := -K
MOV AX, K
NEG AX
MOV J, AX

MUL
Unsigned Multiplication
MUL multiplies an unsigned byte or
word by the contents of AL
The unsigned byte or word in any of
the GPR
Result in AX
All Flags modified
Immediate operand not allowed
If MSB or word is 0 CF and OF set

Unsigned Multiplication
MUL REG
MUL MEM

Examples
MUL BH
;(AX) <- (AL)x(BH)
MUL CX
;(DX)(AX) <-(AX)(CX)
MUL WORD PTR[SI]
;(DX) (AX) <(AX)x([SI])

IMUL

Similar to MUL
OPERANDS ARE SIGNED
PRODUCT IS ALSO SIGNED
SOURCE = GPR, MEMORY OPERAND,
INDEX REGISTER OR BASE REGISTER
NO IMMEDIATE DATA
IF RESULT = 32 BIT HIGEHER ORDER
WORD IS STORED IN DX LOWER
WORD IN AX

THE AF , PF , SF AND ZF FLAGS


UNDEFINED BY IMUL
IF AH AND DX CONTAINS PARTS OF
16 AND 32-BIT RESULTS
RESPECTIVELY CF = 1 OF = 1
IMPLICIT OPERANDS AL AND AX FOR
8BIT , 16 BIT MULTIPLICATIONS
UNUSED HIGHER BITS ARE FILLED BY
SIGN BIT AND CF = 0, AF = 0
EG : - IMUL BH , IMUL CX, IMUL [SI]

CBW, CWD
CONVERT SIGNED BYTE TO WORD
CONVERT SIGNED WORD TO DOUBLE WORD
All these instructions sign-extend a short value
into a longer one, by replicating the top bit of
the original value to fill the extended one.
CBW extends AL into AX by repeating the top
bit of AL in every bit of AH. CWD extends AX
into DX:AX by repeating the top bit of AX
throughout DX. CWDE extends AX into EAX,
and CDQ extends EAX into EDX:EAX.

CONDITIONAL BRANCHING

JZ/JE
JNZ/JNE
JS
JNS
JO
JNO
JP/JPE
JNP

JBE/JNA
JNBE/JA
JL/JNGE
JNL/JGE
JLE/JGC
JNLE/JE
JB/JNAE/JC
JNB/JAE/JNC

JA
JAE
JB
JBE
JC
JE

Above
Above or equal
Bellow
Bellow or equal
Carry
Equality

JG

Greater(s)

JGE
JL
JLE
JNA

Greater of equal(s)
Less(s)
Less equal(s)
Not above
Neither above nor
CF
equal
Not bellow
CF = 0
Neither bellow nor
CF = 0 and ZF = 0
equal

JNAE
JNB
JNBE

CF = 0 and ZF = 0
CF = 0
CF
CF or ZF
CF
ZF
ZF = 0 and SF =
OF
SF = OF
SF OF
ZF or SF OF
CF or ZF

JNC
JNE
JNG
JNGE
JNL
JNLE
JNO
JNP
JNS
JNZ
JO
JP
JPE
JPO
JS

Not carry
Not equal
Not greater
Neither greater
nor equal
Not less

CF = 0
ZF = 0
ZF or SF OF
SF OF

SF = OF
ZF = 0 and SF =
Not less nor equal
OF
Not overflow
OF = 0
Not parity
PF = 0
Not negative
SF = 0
Not zero
ZF = 0
Overflow(s)
OF
Parity
PF
Parity EVEN
PF
Parity ODD
PF = 0
Negative(s)
SF

JUMPS = SHORT JUMP , FAR JUMP ,


NEAR JUMP
SHORT JUMP SPECIAL CASE OF NEAR
JUMP
NEAR JUMP = SAME SEGMENT
FAR JUMP = DIFFERENT SEGMENT
ALL CONDITIONAL JUMPS ARE SHORT
JUMPS
DIRECTIVE SHORT CAN BE USED FOR
SURE CASES OF SHORT JUMP
SHORT JUMP -> FORMAT -> JMP
destination

Near jump range within +/- 32K


bytes
In direct jump
jump location = signed displacement
from current IP to destination address
Ie assembler calculates this
displacement, addds it to the current IP
value
Jump address is relative / relocate-able

For forward jump -> displacement =


positive
For backward jump -> displacement
= negative

Short jumps
Displacement is 8 bit only
(signed)jump destination = -128 to
127 bytes displaced from the current
value of IP
NEW IP = CURRENT IP +
OFFSET(8bit)
Eg:

BEGIN : MOV AH, 01


INT 21H
MOV DL, AL
JMP SHORT THERE

OTHER JUMPS
UNCONDITIONAL
JMP REG16
INDIRECR JUMP
REG16 = AX,BX,CX,DX, ETC
REG16 = DESTIONATION
ADDRESS(OFFSET)
NOT A RELATIVE JUMP
IP = VALUE IN REG16
EG JMP BX, JMP SI

JMP [REG16]
DOUBLE INDIRECT JUMP
REGIG POINTS TO AN ADDRESS WHICH
CONTAINS THE JUMP LOCATION
EG JMP [SI]
JUMP TO THE ADDRESS WHICH IS STORED IN
THE MEMORY LOCATION POINTED BY SI
IF SI = 0987H , THE DEST ADDRS IS TAKEN
FROM THE DATA SEGMENT AT LOCATIONS
0987H AND 0988H. IP IS REPLACED BY THE
VALUE AT THESE ADDRESSES

Вам также может понравиться