Professional Documents
Culture Documents
Instruction Sets Arithmetic 16th-25th Feb 2023 For Lecture
Instruction Sets Arithmetic 16th-25th Feb 2023 For Lecture
Instruction Sets Arithmetic 16th-25th Feb 2023 For Lecture
T1. Barry B Brey, The Intel Microprocessors .Pearson, Eight Ed. 2009. Chapter 4-6, 8
2/25/2023 2
• Arithmetic Instructions
• Logical Instructions
2/25/2023 3
2/25/2023 4
2/25/2023 5
CF = 0, PF = 0, AF = 1, ZF = 0, SF = 1, OF = 1
ADC BX, DX
32 bit addition.
Addition-with-carry showing how the carry flag (C) links the two
16-bit additions into one 32-bit addition.
CF ZF SF
Equal 0 1 0
dest > source 0 0 0
dest < source 1 0 1
• The size of the data must be described by using the BYTE PTR,
WORD PTR directives.
• INC Destination
Ex: INC CX ; Add 1 to the contents of CX.
EX: INC BYTEPTR [BX] ; Increments the byte pointed to
by the contents of BX.
•INC BL
•INC BX
•INC EDX
2/25/2023 27
•DEC BL
•DEC BX
2/25/2023 28
use directive
• BYTE PTR, WORD PTR, DWORD PTR
• INC WORD PTR [BX]
• INC BYTE PTR[BX]
• BX-1000H DS-2000H
XADD BL, CL
2/25/2023 44
2/25/2023 45
AF undefined
CF =OF =0
PF=1, SF=1, ZF=0
TEST Destination,source
• TEST performs the AND operation.
– only affects the condition of the flag register,
which indicates the result of the test
– functions the same manner as a CMP
MOV CL, 05
SAL BP, CL
SAL EAX,12
• Addressing modes used with rotate are the same as those used
with shifts.
RCL
RCR
• ROL AX,1
• ROR BYTEPTR [SI], 1
• MOV CL, 04H
• ROL AX, CL
• ROL BYTEPTR [SI], CL
• ROL ECX, 12H 80386
ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION
Rotate
Flags Affected : CF
OF –If MSB changes –single bit rotate
.Model Tiny
.data
DATA1 DB 0A7H
RES1 DB ?
.code
.startup
SUB BL, BL ;clear BL
MOV CL, 8 ;rotate total of 8 times
MOV AL,DATA1
AGAIN: ROL AL,1 ;rotate it once
JNC NEXT ;check for 1
INC BL ;if CF=1 then inc count
NEXT: DEC CL ;go through this 8 times
JNZ AGAIN ;if not finished go back
MOV RES1, BL
.exit
end
ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION
STRING COMPARISONS
Memory is ES: DI
Operands not affected flags affected(subtraction)
SCASB
SCASW
SCASD
. MODEL TINY
.DATA
DAT1 DB 80 DUP (?)
.CODE
.STARTUP
MOV DI, OFFSET TEST STRING
MOV AL, 0DH
MOV CX, 50H • Scanning is repeated as
CLD long as bytes are not
REPNE SCASB equal or the end of the
.EXIT string not reached.
END
• If 0DH is found DI will
point to the next address
ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION
CMPS / CMPSB/ CMPSW
• Flags affected
• Direction flag used for auto increment or decrement
• Can be used with Prefix
• REPE CMPSB
• REPNE CMPSB