PowerPoint 프레젠테이션 - German University in Cairo

Download Report

Transcript PowerPoint 프레젠테이션 - German University in Cairo

ELECT 707
Micro-Computer Applications:
Arithmetic, Logic & Data Movement
Instructions
Dr. Eng. Amr T. Abdel-Hamid
Fall 2011
Instructions Types
Micro-Computer Applications





Arithmetic/Logic
Data Movement
Program Control (if,..)
Loop Control
Interrupts
Dr. Amr Talaat
ELECT 707
MOV et.al.
Micro-Computer Applications
 MOV is still the main data transfer instruction, b
ut there are many variations that perform speci
al tasks such as PUSH and POP.
 We do not often code in hexadecimal machine la
nguage, but an understanding tends to help wit
h learning the instruction set and the form of ins
tructions in the memory.
Dr. Amr Talaat
ELECT 707
The Opcode
Micro-Computer Applications
D W
Opcode
Feild
Mod
Reg
R/M
Description
Dr. Amr Talaat
D
the direction of data flow either from or to R/M from REG. If D =
0 REG  R/M and if D = 1 R/M  REG
W
specifies a word (16-bit mode) or a doubleword (32-bit mode).
W = 0 byte and W = 1 word/doubleword
MOD
specifies how R/M is used and whether a displacement exists.
MOD = 00 memory no displacement
MOD = 01 memory 8-bit displacement
MOD = 10 memory 16/32-bit displacement
MOD = 11 register
ELECT 707
Micro-Computer Applications
Dr. Amr Talaat
ELECT 707
Segment Register Moves
Micro-Computer Applications
 Although we do not often directly address segm
ent registers it is important to understand the li
mitations of the segment register MOV instructio
n.
 Immediate data cannot be moved into a se
gment register.
 CS cannot successfully be loaded with a se
gment register MOV.
Dr. Amr Talaat
ELECT 707
Addition
Micro-Computer Applications




The ADD instruction is used for binary addition.
The addition causes the flag bits to change.
Addition can be 8-, 16-, and 32-bits.
All of the addressing modes presented in Chapte
r 2 are used by addition.
ADD EAX,EBX
;EAX = EAX + EBX
Dr. Amr Talaat
C
Z
S
O P
A
r
r
r
r
r
r
ELECT 707
Flags
Micro-Computer Applications
 Flag Status After Instructions:
 1 - instruction sets this flag to 1.
 0 - instruction sets this flag to 0.
 r - flag value depends on result of the instruct
ion.
 ? - flag value is undefined (maybe 1 or 0)
Dr. Amr Talaat
ELECT 707
Increment
Micro-Computer Applications
 The INC instruction adds a one to a register or t
he contents of a memory location.
INC BX
;BX = BX + 1
INC BYTE PTR [EBX]
Dr. Amr Talaat
ELECT 707
Add with Carry
Micro-Computer Applications
 The ADC instruction adds the carry bit into the s
um. Used for wide additions (wider than 32-bits
) and other reasons.
ADC AX,DX
ADX ESI,[EBX]
;AX = AX + DX + C
Dr. Amr Talaat
ELECT 707
Micro-Computer Applications
Dr. Amr Talaat
ELECT 707
Subtraction
Micro-Computer Applications
 The SUB instruction performs subtraction and th
e flags change to reflect condition of the result.
 As with other arithmetic and logic instructions, s
ubtraction exists for 8-, 16-, and 32-bit data.
Dr. Amr Talaat
SUB AL,3
SUB ECX,ESI
;AL = AL - 3
ELECT 707
Decrement
Micro-Computer Applications
 The DEC instruction subtracts one from a registe
r or the contents of a memory location.
DEC EBX
;EBX = EBX - 1
DEC DWORD PTR [EAX]
Dr. Amr Talaat
ELECT 707
Subtract with Borrow
Micro-Computer Applications
 The SBB instruction subtracts with borrow (wher
e the borrow is held in the carry flag).
SBB EAX,EBX
;EAX = EAX – EBX – C
Dr. Amr Talaat
ELECT 707
Micro-Computer Applications
Dr. Amr Talaat
ELECT 707
Compare
Micro-Computer Applications
 The CMP instruction is a special form of the SUB
instruction. A compare does not result in a diffe
rence that is saved, on the flag bits change to re
flect the difference.
CMP
AL,3
;if AL = 3 the result to zero (flag)
Dr. Amr Talaat
ELECT 707
Multiplication
Micro-Computer Applications
 The MUL (unsigned) and IMUL (signed) instructi
on exist to perform 8-, 16-, or 32-bit multiplicati
on.
 The result is always a double wide result.
 The carry and overflow bits indicate conditions a
bout the multiplication.
 A special IMUL exists with 3 operands.
Dr. Amr Talaat
ELECT 707
Division
Micro-Computer Applications
 The DIV (unsigned) and IDIV (signed) instructio
n exist to perform division on 8-, 16-, or 32-bit
numbers.
 Division is always performed o a double wide div
idend.
 The result is always in the form of an integer qu
otient and an integer remainder.
Dr. Amr Talaat
ELECT 707
AND
Micro-Computer Applications
 The AND instruction performs logical multiplicati
on (the AND operation).
Dr. Amr Talaat
ELECT 707
OR
Micro-Computer Applications
 The OR instruction generates the logical sum (O
R operation).
Dr. Amr Talaat
ELECT 707
Exclusive OR
Micro-Computer Applications
 The XOR instruction performs the Exclusive OR
operation.
Dr. Amr Talaat
ELECT 707
NEG and NOT
Micro-Computer Applications
 The NEG (negate) instruction 2’s complements a
number,
 The NOT instruction 1’s complements a number.
NOT EAX
NEG DWORD PTR [EBX]
Dr. Amr Talaat
ELECT 707
Shifts
Micro-Computer Applications
 There are 4 shift instructions. Two are logical s
hifts and two are arithmetic shifts.
 The logical shifts reposition the bits in a number
. The arithmetic shifts multiply or divide signed
numbers by powers of two.
 SHR and SHL are logical and SAR and SAL are ar
ithmetic shifts.
SHL AL,3 or SHL AL,CL
Dr. Amr Talaat
ELECT 707
Micro-Computer Applications
Dr. Amr Talaat
ELECT 707
Rotates
Micro-Computer Applications
 Rotates are shifts that re-circulate the bit that m
oves out of an end of the register or memory loc
ation.
 Four rotates exist where two just rotate the targ
et and two rotate the target through the carry fl
ag.
ROL AL,3 or
RCL AL,3
Dr. Amr Talaat
ELECT 707
Micro-Computer Applications
Dr. Amr Talaat
ELECT 707
TEST
Micro-Computer Applications
 The TEST instruction is a special form of the AN
D instruction that produces no result except for
a change of the flags.
 This instruction is often used to test multiple bit
s of a number.
TEST AL,3 ;test the right two bits (if both are z
ero the result is zero)
Dr. Amr Talaat
ELECT 707
Bit Test Instructions
Micro-Computer Applications
 There are four bit test instructions BT (bit test),
BTR (bit test and reset), BTS (bit test and set),
and BTC (bit test and complement).
 Each tests the prescribed bit by moving it into c
arry. Then the bit is modified (except for BT)
BT AL,3
;bit 3 is moved to carry
BTS AL,3
;bit 3 is moved to carry then set
BTR AL,3 ;bit 3 is moved to carry then reset
BTC AL,3 ;bit 3 is moved to carry then inverted.
Dr. Amr Talaat
ELECT 707
PUSH and POP
Micro-Computer Applications
 PUSH and POP transfer data to and from the stack. The st
ack is an area of memory that is reused and grows in size
with each PUSH and shrinks in size with each POP.
 PUSH and POP function with either 16- or 32-bit data.
 PUSHF (PUSHFD) and POPF (POPFD) save and restore the
flags (EFLAGS)
 PUSHA (PUSHAD) and POPA (POPAD) save and restore all
the registers
Dr. Amr Talaat
ELECT 707
Load Segment and Index
Micro-Computer Applications
 LDS, LES, LSS, LFG, and LGS allow a segment r
egisters and a pointer to both be loaded from m
emory.
LDS BX,BOB
;loads DS and BX with the offset and segment add
ress stored in a 32-bit memory location called B
OB.
Dr. Amr Talaat
ELECT 707
LEA
Micro-Computer Applications
 The LEA instruction loads the effective ad
dress of a memory location into a pointer
or index register.
 At times we do the same operation with a
MOV and the keyword OFFSET
MOV BX,OFFSET FRED
LEA BX,FRED
Dr. Amr Talaat
Both instruction accomplish the same task.
ELECT 707
String Data Transfer Instructions
Micro-Computer Applications
Dr. Amr Talaat
 String data transfer instructions are: LOD
S, STOS, MOVS, INS, and OUTS.
 These instructions use the direction flag b
it to select the way that a pointer is modi
fied after the instruction. D = 0 auto-incr
ement and D = 1 auto-decrement.
 Many of these instructions can be prefixe
d with a REP (repeat) to repeat the instru
ction the number of times stored in the C
X register.
ELECT 707
Miscellaneous
Micro-Computer Applications
 NOP (does nothing)
 XCHG (swaps contents)
 CLC, STC, CMC (modify Carry)
Dr. Amr Talaat
ELECT 707
References:
Based on slides from B. Brey, The Intel Microprocessor: Archit
Micro-Computer Applications
ecture, Programming, and Interfacing, 8th Edition, 2009 & other
s
Dr. Amr Talaat
ELECT 707