Chap#3
80x86 Instructions, Part1:
Addressing Mode, Flags,
Data Transfer and String Instructions
Objective
:
-
Style of source files
-
Different addressing mode
-
Operation and use of flag
-
Data transfer and string instruction
3.1 Introduction
-
Detailed look at the data transfer and string instructions
3.2 Assembly Language Programming
-
Assembler
-
Source format : 4 field
* label
* opcode
* operand
* comment (preceded by semicolon '
; ')
-
Assembler perform 2 pass
* 1st pass :
determine the length of instruction
& data areas, assign values to all symbols
* 2nd pass
: generating the machine codes
-
Assembler directives
ORG, SEGMENT, ENDS, ASSUME, and END
-
[.model] type
-
Linker
3.3 Instruction Types
For purpose of discussion
divided into 7 groups
-
1) data transfer
-
2) strings
-
3) arithmetic
-
4) bit manipulation
-
5) loops & jumps
-
6) subroutine &
interrupt
-
7) processor control
3.4 Addressing Mode
@ Effective Address
-
instruction fetch : EA = (CS * 16) + (IP)
-
data fetch : EA = (DS * 16) + (OFFSET)
@ Initial DS Register
@ Addressing Mode :
3.5 The Processor Flags (condition
code)
3.6 Data Transfer Instructions
-
1) MOV
Destination, Source (move data)
e.g. MOV AL, 30H ==> AL = 30
MOV AX, 30H ==> AX = 0030
MOV BYTE PTR [SI], 0 ==> m = 00
MOV WORD PTR [SI], 0 ==> m = 0000
MOV DWORD PTR [SI], 0 ==> m = 00000000
-
2) MOVSX
D, S (move with sign extended)
e.g. AL = 36H
BX = C3EEH
MOVSX AX,AL ==> AX = 0036
MOVSX EBX,BX ==> EBX = FFFFC3EE
-
3) MOVZX
D, S (move with zero extended)
e.g. AL = 36H
BX = C3EEH
MOVZX AX,AL ==> AX = 0036
MOVZX EBX,BX ==> EBX = 0000C3EE
-
4) PUSH
Source (push word onto stack)
-
5) PUSHW/PUSHD
Source (push W/DW onto stack)
PUSHA/PUSHAD(Push all registers/Push all double-registers) (push
order)
-
6) POP
Destination (pop data off stack)
-
7) POPA/POPAD
Destination (pop all Reg/pop all double -Reg.) (pop
order)
-
8) IN
Accumulator,Port ( input byte or word from port)
-
9) INS
Destination,Port (input string from port)
-
10) OUT
Port,Accumulator ( output byte or word to port)
-
11) OUTS
DX,Source (output string to port)
-
12) LEA
D, S (Load Effective Address)
-
13) PUSHF/PUSHFD
(pusf flag(16/32) onto stack)
-
14) POPF/POPFD
(pop flag(16/32) off stack)
-
15) XCHG
D, S (exchange data)
-
16) BSWAP
Destination (byte swap)
-
17) XLAT
Translate-Table (translate byte)
-
18) LDS
D, S (load pointer using DS)
-
19) LES/LFS/LGS/LSS
D, S (load pointer using ES/FS/GD/SS)
-
20) LAHF (load
AH Register from Flags)
-
21) SAHF (store
AH Register into Flags)
@ Assembler Directives
:
OFFSET, BYTE PTR, WORD PTR, DWORD PTR, FWORD, and SEG
3.7
String Instructions
-
1)
Initializing the String Pointers
e.g.
MOV AX, 510H
MOV DS, AX
MOV SI, 0
- - -
MOV AX, 4A8H
MOV ES, AX
MOV DI, 0
- - -
LDS SI, StringA
LES DI, StringB
- - -
CLD
REP CMPSB
- - -
-
2)
REP/REPE/REPZ/REPNE/REPNZ
-
3)
MOVS D-string, S-string (Move String)
-
4)
MOVSB/MOVSW/MOVSD(Move String)
-
5)
CMPS D-string, S-string (Compare String)
-
6)
SCAS D-string (Scan String)
-
7)
LODS S-string (Load String)
-
8)
STOS D-string (Store String)
-
@
INS/OUTS (I/O String)
e.g.
DS = 0400 ES = 0600 CX = 0003
SI = 0100 DI = 0200 DX = 03E0
Execute
: REP INS;
REP OUTSW
3.8
Troubleshooting Techniques
-
Summary
( page
102 )
-
Study
Questions ( #3,
#5, #7, #9, #13, #23, #27, #29, #31 )