100 likes | 109 Views
Arithmetic and Logic Instructions First and Third Group. أعداد: م.م. سمر أميل يوسف. First Group Instruction. ADD , SUB,CMP, AND, TEST, OR, XOR REG , memory memory , REG REG , REG memory , immediate REG , immediate These instructions affect these flags only:
E N D
Arithmetic and Logic Instructions First and Third Group أعداد: م.م. سمر أميل يوسف
First Group Instruction ADD, SUB,CMP, AND, TEST, OR, XOR REG, memory memory, REG REG, REG memory, immediate REG, immediate These instructions affect these flags only: CF, ZF, SF, OF, PF, AF.
First Group Instruction CMP - Subtract second operand from first for flags only. MOV AX,5555H MOV [BX], 2222H CMP [BX],AX CMP AX,[BX] CMP [BX],1111H
First Group Instruction AND - Logical AND between all bits of two operands. The rules apply: 1 AND 1 = 1 1 AND 0 = 0 0 AND 1 = 0 0 AND 0 = 0 As you see we get 1 only when both bits are 1. MOV AX,1111H MOV BX ,0FFFH ; try 0000H AND AX,BX RET
First Group Instruction TEST - The same as AND but for flags only. MOV AX,1111H TEST AX,BX RET
First Group Instruction OR - Logical OR between all bits of two operands. The rules apply: 1 OR 1 = 1 1 OR 0 = 1 0 OR 1 = 1 0 OR 0 = 0 As you see we get 1 every time when at least one of the bits is 1. MOV BX,1111H OR AX,BX RET
First Group Instruction XOR - Logical XOR (exclusive OR) between all bits of two operands. The rules apply: 1 XOR 1 = 0 1 XOR 0 = 1 0 XOR 1 = 1 0 XOR 0 = 0 As you see we get 1 every time when bits are different from each other. MOV BX,0101H MOV AX,1111H XOR AX,BX RET
Third Group Instructions INC, DEC, NOT, NEG REG Memory • INC, DEC instructions affect these flags only: ZF, SF, OF, PF, AF. • NOT instruction does not affect any flags! • NEG instruction affects these flags only: CF, ZF, SF, OF, PF, AF.
Third Group Instructions The NOT instruction inverts each bit (forms the 1’s complement) of a byte or word in the specified destination. The destination can be a register or a memory location. This instruction does not affect any flag. NOT AX NOT CL NOT [BX] RET
Third Group Instructions The NEG instruction replaces the number in a destination with its 2’s complement. The destination can be a register or a memory location. It gives the same result as the invert each bit and add one algorithm. MOV AX,10100110b NEG AX RET