Professional Documents
Culture Documents
Data transfer instruction Arithmetic instruction Bit manipulated instruction String instruction Iteration control instruction Branch instruction Data size conversion instruction Processor control instruction
MOV Instruction
Syntax: MOV destination, source Action: Copies the data from src to dest Src: Immediate data/reg/mem location Dest: reg/mem location Flags: No flags are affected
MOV AX, BX MOV AX, [BX] MOV AL,[1234H] MOV AL,BL MOV AL,A MOV SP, BP
MOV A,B MOV [BX],[SI] MOV 1234H,BX MOV IP, AX MOV CS, AX MOV DS, ES MOV DS, 1234H MOV AL,BX
Valid instruction
Invalid instruction
11H
22H 33H
11H
22H 33H
44H 55H
44H 55H
Memory read
MOV 1234H[BP],SI
Memory write BEFORE SI = 5678H BP = AB12H SS = 9000H SS Memory PA = 1234 + BP + (SS)*10H = 1234 + AB12 + 9000*10H 9BD43H = 9BD46H 9BD44H 9BD45H 9BD46H 9BD47H 9BD48H 9BD43H 9BD44H 9BD45H 9BD46H 9BD47H 9BD48H AFTER SI = 5678H BP = AB12H SS = 9000H SS Memory
11H
22H 33H
44H 55H
MOV CS:[BX][DI],53H
Memory write BEFORE DI = 1234H BX = AB12H CS = 9000H CS Memory PA = DI + BX + (CS)*10H = 1234 + AB12 + 9000*10H 9BD43H = 9BD46H 9BD44H 9BD45H 9BD46H 9BD47H 9BD48H 9BD43H 9BD44H 9BD45H 9BD46H 9BD47H 9BD48H AFTER DI = 1234H BX = AB12H CS = 9000H CS Memory
11H
22H 33H
44H 55H
MOV [BX],AL
Memory write BEFORE AL= 34H BX = 5678H DS = 9000H Memory PA = BX + (DS)*10H = 5678 + 9000*10H = 95678H AFTER AL = 34H BX = 5678H DS = 9000H Memory
95678H
99H
95678H
34H
Action: 1) instr copies the EA of the memory & it is transferred to the specified reg. 2) instr is reqd for initializing the memory pointers (BX,SI,DI,BP,SP) 3) instr does not transfer data from memory.
LEA BX, DS:1234H LEA BX, [1234H] LEA BX, MSG LEA CX, MSG LEA BP, MSG LEA SP, MSG
LEA DS, 56H[SI] LEA BX, SI LEA BX, 1234H LEA IP, MSG
Valid instruction
Invalid instruction
Action: 1) instr transfers 32-bit data from memory. 2) 1st 16-bits transferred to reg specified 3) 2nd 16-bits transferred to DS reg .
2nd word
Action: 1) instr transfers 32-bit data from memory. 2) 1st 16-bits transferred to reg specified 3) 2nd 16-bits transferred to ES reg .
2nd word
XLAT-Translate Instruction
Action: 1) instr is useful to convert from one code to another using lookup table 2) has no operands & is implied mode of addressing. So prior to execution of this instr, BX should be initialized to contain the start address of the lookup table & AL should contain the code to be converted. 3) After executing the instr, 1 byte data stored in offset address AL+BX in the DS memory is copied into AL ie (AL)Ds:[(BX) + (AL)] 4) AL contains the converted code.
XLAT
BEFORE AL = 0AH BX = 0100H DS = 9000H PA = (AL) + (BX) +(DS)*10H = 0AH + 0100H + 90000H = 9010AH Starting addr of DS Starting addr of lookup table 90000H -----90100 H Read from table LOOKUP TABLE AFTER AL = 41H BX = 0100H DS = 9000H
DS Memory
9010AH
41H
ZF
6
0
5
AF
4
0
3
PF
2
1
1
CF
0
; AX=0046H ; AX=0346H
STACK
PUSH BX
BEFORE SP = 1234H SS = 5000H BX = 5678H AFTER SP = 1232H SS = 5000H BX = 5678H
SS Memory
SS Memory
.. 5122FH
51232H
51234H
51234H
POP BX
BEFORE SP = 1232H SS = 5000H BX = 1234H AFTER SP = 1234H SS = 5000H BX = 5678H
SS Memory
SS Memory
.. 5122FH
51232H C3H
51234H
51234H
STRING INSTRUCTIONS
Data segment register (used as source segment) Extra segment register (used as destination segment)
Source index register(SI) should be associated with DS Destination index register(DI) should be associated with ES
During string manipulation, SI register should contain offset address of the source byte or word with respect to data segment.
STOSB -store byte from AL into string element addressed by DI in ES & updates DI (ES:[DI])
ES:[(DI)] [AL] No flags affected If DF=0 then DI=DI+1 If DF=1 then DI=DI-1 Segment for memory access : ES
12
DI=02
12
DI=03
12
DI=04
12
DI=05
12
DI=06
STOSW -store word from AX into string element addressed by DI in ES & updates DI (ES:[DI])
ES:[(DI)] [AX] No flags affected If DF=0 then DI=DI+2 If DF=1 then DI=DI-2 Segment for memory access : ES
1234
DI=02
1234
DI=04
1234
DI=06
1234
DI=08
1234
DI=0A
x db A, B , C , D , E
AL=44h
AL=45h
41
SI=02
42
SI=03
43
SI=04
44
SI=05
45
SI=06
AX=0333h
AX=0444h
AX=0555h
11 01
SI=02
22 02
SI=04
33 03
SI=06
44 04
SI=08
55 05
SI=0A
CLD ;set forward direction LEA SI, x y db 5 dup(0) x db 1, 2, 3, 4, 5 LEA DI, y MOV CX,5 REP MOVSB
01 Data Segment DS SI=01 02 SI=02 03 SI=03 04 SI=04 05 SI=05
00 02 DI=07
03 00 DI=08
04 00 DI=09
05 00 DI=0A
CLD ;set forward direction LEA SI, x y dw 5 dup(0) x dw 1, 2, 3, 4, 5 LEA DI, y MOV CX,5 REP MOVSW
01 00 Data Segment DS SI=02 02 00 SI=04 03 00 SI=06 04 00 SI=08 05 00 SI=0A
02 00 00 DI=09
03 00 00 DI=0A
04 00 00 DI=0C
05 00 00 DI=0E
CLD MOV AX,data MOV DS,AX MOV ES,AX MOV SI,STR1 MOV DI,STR2 MOV CX, size ;set counter to string length REPE CMPSB ;compare until equal JNZ not_equal MOV AL,y JMP exit not_equal: MOV AL,n exit: MOV AH,04CH INT 21H
CLD MOV AX,data STR1 Dw 1234h, 5678h, 9012h, 3456h MOV DS,AX STR2 Dw 1234h, 5678h, 9012h, 3456h MOV ES,AX MOV SI,STR1 MOV DI,STR2 MOV CX, size ;set counter to string length REPE CMPSW ;compare until equal JNZ not_equal MOV AL,y JMP exit not_equal: MOV AL,n exit: MOV AH,04CH INT 21H