Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Instruction Format
Addressing Modes
Immediate
Direct
Register
Register indirect
Indexed
Register relative
Based indexed
Relative based indexed
Intrasegment direct mode
Intrasegment indirect mode
Intersegment direct mode
Intersegment indirect mode
Immediate
Ex: MOV AX,0005H
MOV AH, 12H : Move to AH the byte value 12H
MOV AX, 1234H : Move to AX the value 1234H
MOV AX, CONST :Move to AX the constant defined as CONST
MOV AX, OFFSET x : Move to AX the address (offset) of variable x
Direct
Ex : MOV AX,[5000H]
MOV AX, [1234H] :Move to AX value at memory location 1234H
MOV AX, x :Move to AX the value of M[x]
MOV x, AX :Move to M[x] the value of AX
(all the above uses default seg, DS)
Register
Ex : MOV AX,BX
MOV AX, BX :Move to AX the 16-bit value in BX
MOV AX, DI :Move to AX the 16-bit value in DI
MOV AH, AL :Move to AH the 8-bit value in AL
Register indirect
Ex : MOV AX,[BX]
MOV AX, [DI] :Move to AX the value at M[DI] (uses default segment, DS)
MOV [DI], AX : Move to M[DI] the value AX (uses default segment, DS)
Indexed
EX : MOV AX,[SI ] 10H*DS+[SI]
Register relative
Ex : MOV AX, 50H[BX] 10H*DS+50H+[BX]
Based indexed
Ex : MOV AX, [BX] [SI] 10H*DS+[BX]+[SI]
Instruction set
Data copy/transfer instructions
Arithmetic and logical instructions
Shift and Rotate instructions
Branch instructions
Loop instructions
Machine control instructions
Flag manipulation instructions
String instructions
MOV : MOV
MOV dest, src dest src
transfers data ( byte/ word) from source to destination.
source can be register/memory/immediate
destination can be register/memory
both can not refer to memory location
must be of same data type ( byte/word)
flags affected none
ex:
MOV AX,CX
MOV AH,AL
MOV DS,AX
MOV Ax,100H
MOV BX,[5300H]
MOV DL,[BX]
MOV BP,SS
XCHG : Exchange
XCHG dest, src ; dest src
swaps the content of a source with destination
Source cab be register/memory
Destination can be register/memory
Both cannot be memory location
Must be of same data type
ex:
XCHG AX,CX
XCHG AL,AH
XCHG Amount ,BX
Ex : LAHF
Ex : SAHF
Ex : PUSHF
EX : POP AX
POP SI
Ex:
POPF
ADD : addition
ADD dest , src dest src + dest
Adds the content of source with destination, stores the result in destination
Source can be register/memory/immediate
Destination can be register/memory
Must be of same data type
Both cannot refer to memory
Flags affected AF, CF, OF, PF, SF, ZF
Ex :
ADD AX,0008h ; immediate
ADD AX,BX ; register
ADD AX,[SI] ; register indirect
ADD AX, [5000h] ; direct
ADD 0111h ; destination (accu) implicit
INC : increment
INC dest dest dest +1
SUB : subtraction
SUB dest , src dest dest - src
Subtracts the content of source from destination, stores the result in destination
Source can be register/memory/immediate
Destination can be register/memory
Must be of same data type
Both cannot refer to memory
Flags affected AF, CF, OF, PF, SF, ZF
Ex:
SUB AX,0008h ; immediate
SUB AX,BX ; register
SUB AX, [5000h] ; direct
DEC : decrement
DEC dest dest dest -1
Subtracts 1 from dest (register/memory) and stores the result in dest
CF will not affected
Flags affected AF, OF, PF, SF, ZF
DEC AX ;register
DEC [5000h] ;direct
CMP : compare
CMP dest , src dest – src (data not modified)
Perform a non destructive subtraction
Compare the content source with destination
Source can be register/memory/immediate
destination can be register/memory
Both cannot refer memory
Must be of same data type
Sets the flags based on the magnitude of the operands
Used with conditional JUMP instruction
Flags affected AF, CF, OF, PF, SF, ZF
Ex :
CMP BX,0100h
CMP AX,CX
CMP [5000h],0100h
CMP BX,[SI]
NEG : negate
NEG dest dest 0 – dest
Change sign of the operand
Performed by subtraction of destination operand from 0, and placing the result in
dest.
Replaces the number in the dest with its equivalent 2’s compliment
Destination can be register/memory
Flags affected AF, CF, OF, PF, SF, ZF
Ex:
NEG AL
NEG AX
NEG BYTE PTR[BX]
NEG count
AL = AL + 6
AH = AH + 1
AF = 1
CF = 1
else
AF = 0
CF = 0
In both cases:
clear the high nibble of AL.
AL = AL - 6
AH = AH - 1
AF = 1
CF = 1
else
AF = 0
CF = 0
in both cases:
clear the high nibble of AL.
Algorithm:
AL = (AH * 10) + AL
AH = 0
Algorithm:
AH = AL / 10
AL = remainder
DAA can be used to change the content of AL register to pair of valid packed
decimal digit
Instruction should be issued after addition instruction
Flags affected AF, CF, PF, ZF
Flags undefined OF
Ex : DAA
Algorithm:
AL = AL + 6
AF = 1
AL = AL + 60h
CF = 1
Ex : DAS
Algorithm:
if low nibble of AL > 9 or AF = 1 then:
AL = AL - 6
AF = 1
AL = AL - 60h
CF = 1
MUL : multiplication
MUL src
Byte : AX ( AL * src8)
Word : DX:AX ( AX * src16)
Perform unsigned multiplication of the source operand with the accumulator
Source can be register/memory
DIV : division
DIV src
Byte : AL (AX / src8)
AH (AX mod src8)
Word : AX (DX : AX / src16)
DX (DX:AX mod src16)
Division by 0 result too large causes interrupt type 0 (INT 00H)
Perform an unsigned division of accumulator and its extension by the source
operand
Source can be register/memory
Flags affected none
Flags affected AF, CF, OF, PF, SF, ZF
Ex:
DIV CL
DIV CX
EX:
IDIV CL
Instruction must be executed before a signed byte in AL is divided by another signed byte
with the instruction IDIV
Ex:
CBW
EX:
TEST AL,BL
OR : logical OR
OR dest , src dest dest | src
Performs logical OR of 2 operands, places the result in the destination
Source can be register/memory/immediate
Destination can be register/memory
Both should not refer to memory
Must be of same data type
CF & OF are set to 0 on execution of this instruction
Flags affected CF, OF, PF, SF, SF
Ex :
OR AH,CH
OR BX,00FFh
OR CX,[SI]
Ex:
SHL AX,2
SHL BL,1
Ex:
SHR AX,2
SHR BL, 1
Ex:
SAR AX,2
SAR BL, 1
Ex:
ROL AX,2
ROL BL,1
Ex:
ROR AX,2
ROR BL,1
Ex:
RCL AX,2
RCL BL,1
RCR AX,2
RCR BL,1
Branch instructions
LOOP : loop
LOOP short_label
Instruction used to execute the group of instruction repeatedly a specified number
of times
CX is decremented by 1 automatically
This are short jumps
LOOPE/LOOPZ short_label
CX CX-1, jump if (CX !=0 and ZF =1)
LOOPNZ/LOOPNE short_label
CX CX-1, jump if (CX !=0 and ZF =0)
JL/JNGE : Jump less than/jump not greater than or equal if (SF != OF) after signed math
JA/JNBE : jump on above/jump on not below or equal if CX=0 and ZF =0 after unsigned math
JAE/JNB/JNC : jump on above or equal/ jump on not below/ jump on not carry if
CF =0 after unsigned math
JG/JNLE : jump on greater than / jump on not less or equal if SF=OF and ZF =0 after signed math
JGE/JNL : jump on greater or equal / jump on not less if SF = OF after signed math
JLE / JNG : jump on less than or equal / jump on not greater if SF != OF or ZF=1 after signed math
JO : jump on overflow if OF = 1
JS : jump on sign if SF = 1
CALL sub_name
near procedure in the same code segment ,address 2 byte long
far procedure is not in the same code segment, address 4 byte long
transfers the control to a subprogram or a procedure by saving the return address on the
stack
Flags affected none.
Near CALL
SP SP – 2
Save IP on the stack
IP address of the called procedure
Far CALL
SP SP – 2, save CS on the stack
CS new segment address, procedure
SP SP – 2 , save IP on the stack
IP offset address of the called procedure
EX : CALL BX
CALL WORD PTR [BX]
RET : Return
RET
Return the control from the procedure to calling program
Near return
If (intra segment RET)
IP contents of the top of the stack
SP SP +2
Far return
If (inter segment RET)
IP contents of the top of the stack
SP SP +2
CS contents of the top of the stack
SP SP + 2
RET n
perform near or far return
SP SP +n
EX :
RET
RET 2
INT : interrupt
INT Type
Perform a software interrupt ( invokes a system call)
PUSHF
IF 0, TF 0
PUSH CS , PUSH IP
IP 0000 [type * 4]
CS 0000 [(type * 4)+2]
Flags affected none
function
SP SP-2 ; save flag
SP SP-2 ; save CS
SP SP-2 ; save IP
New IP [type number * 4]
New CS [type number * 4 +2]
TF0, IF 0
HLT : halt
HLT – halt the processing ( perform NOP’s until an interrupt occurs)
NOP : No operation
NOP – perform no operation, waits for 3 clock cycle
WAIT : wait
WAIT – wait for TEST line active, causes the processor to enter into an ideal state
In multiple byte or word loads, the number of elements to be loaded placed in the CX
register
In case of multiple movement, LODS/LODSB/LODSW is prefixed with the repeat string
instruction, REP,REPE
Flags affected none
EX: LODSB
LODSW