320 likes | 644 Views
NEG Instruction. Change operand content into two’s complement (negative value) and stored back into its operand. mov bl,00000001b neg bl ; bl = 11111111 mov ah,11001101b neg ah ; ah = 00110011 mov al,-128 neg al ; al = 80h, OF=1. MUL and IMUL Instruction.
E N D
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl,00000001b neg bl ; bl = 11111111 mov ah,11001101b neg ah ; ah = 00110011 mov al,-128 neg al ; al = 80h, OF=1
MUL and IMUL Instruction • Multiplication operation to multiply two numbers • Format : MUL Operand • IMUL Operand where operand might be general register or memory • MUL : for unsigned multiplication operation • IMUL : for signed multiplication operation
MUL/IMUL result will be stored in : • AX if byte type source • DX:AX if word type source • EDX:EAX if dword type source
DIV and IDIV Instruction • Two division instruction: • DIV operand : unsigned number • IDIV operand: signed number • Operand must be register or memory
Example DIV and IDIV Instruction • DX = 0000h, AX = 0005h, BX = FFFEh: • Instruction Quot. Rem. AX DX • div bx 0 5 0000 0005 • idiv bx -2 1 FFFE 0001 • DX = FFFFh, AX = FFFBh, BX = 0002h: • Instruction Quot. Rem. AX DX • idiv bx -2 -1 FFFE FFFF • div bx Divide Overflow
Control bit instruction • Logic instruction • Shift instruction • Rotate instruction
Logik instruction • Table 1. Boolean Instructions
AND Operation • Truth table which shows operation result of AND bit-2 bit-1 op-1: 1 1 0 1 0 0 1 1 op-2: 0 1 0 0 1 1 0 1 result:0 1 0 0 0 0 0 1
Instruction Example target source and ax,bx and var1,edx and bl,var2 and dx,02FAh and al,00001111b
OR Instruction • Truth table which show OR operation result bit-2 bit-1 op-1: 1 1 0 1 0 0 1 1 op-2: 0 1 0 0 1 1 0 1 result:1 1 0 1 1 1 1 1
Instruction example target source or ax,bx or var1,edx or bl,var2 or dx,02FAh or al,00001111b
XOR Instruction • Truth table shows XOR operation result bit-2 bit-1 op-1: 1 1 0 1 0 0 1 1 op-2: 0 1 0 0 1 1 0 1 result:1 0 0 1 1 1 1 0
Instruction example mov al,10110011b xor al,11111111b ; AL = 01001100 XORing any bit with 0 leaves the bit unchanged: mov al,10110011b xor al,00000000b ; AL = 10110011
Instruction example mov al,10110011b xor al,10101100b ; AL = 00011111 xor al,10101100b ; AL = 10110011 same
NOT instruction • Execute NOT operation at each bit at operand mov bh,11001101b not bh ; bh = 00110010
Shift instruction • To shift one bit to left • SHL O1, O2 • Each bit is shifted one place to the left • Right most will be filled with 0 • Bit output from left most is inserted to carry flag, CF (original CF content will disappear) • Example: • mov bl,80h ; BX = 0080h • shl bl,1 ; BX = 0000h, CF=1
Shift bit right • To shift right, with method: • SHR O1, O2 O1= first operand (general register or memory) O2=second operand (immediate or valid value) O1 content change after operation
SAL Instruction • As SHL instruction • Format • SAL O1, O2 O1= first operand, • O2= second operand • Eg: SAL AH,CL where AH=42H, CL=2 CF=0 • This instruction will caused 8-bit in AH is shifted 2-bit to the left. • Output bit at the right most is inserted to CF and bit which is emptied will be replaced by 0 • Last result, AH=O8H
SAR Instruction • As in SHR • Format • SAR O1,O2 O1= first operand, • O2= second operand • Eg: SAR AH, 1 where AH=35H, CF=0 • This instruction will caused bit in AH is shifted 1-bit to the right • Output bit is inserted to CF and empty bit is replace with sign bit • Last result, AH=1AH
Rotate Instruction • Similar to shift instruction, but rotate instruction will input again bit which has been exited at other end • There are 4 instructions • ROR – rotate right • ROL – rotate left • RCR – rotate right with carry • RCL – rotate left with carry
ROR and ROL Instruction • ROL rotate bits to the left • Format : ROL O1, O2 • ROR rotate bits to the right • Format : ROR O1, O2 • Final bit is also stored in CF
RCR and RCL Instruction • RCL rotate left and take CF into consideration • Format RCL O1, O2, • RCR rotate right and take CF into consideration • Format RCR O1, O2
Compare Instruction • Its function is to set flag register as ready stae before conditional jump instruction is executed • Format : CMP OD,OS ;OD= destination operand ;OS= source operand • Both operand must be general register, memory or immediate value
Flags Set by the CMP Instruction Unsigned: Signed:
Jump Instruction • There are two jump instruction • Unconditional jump instruction • Conditional jump instruction • Format • Arahan_Lompat label • where Arahan_Lompat is an instruction • label is the destination where jump will target program execution (label is a name not a register,memory or any value)
Loop instruction • One method that can represent high level language instruction such as “do_while” and “repeat_until” • Format • LOOP Operand where Operand=label for instruction at the beginning of the loop • Instructions will be executed until loop counter CX=0.