28
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

NEG Instruction

  • Upload
    jera

  • View
    71

  • Download
    1

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: NEG Instruction

NEG InstructionChange operand content into two’s complement (negative value) and stored back into its operand

mov bl,00000001bneg bl ; bl = 11111111

mov ah,11001101bneg ah ; ah = 00110011

mov al,-128neg al ; al = 80h, OF=1

Page 2: NEG Instruction

MUL and IMUL InstructionMultiplication operation to multiply two numbers

Format : MUL Operand

IMUL Operand where operand might be general register or

memoryMUL : for unsigned multiplication operation

IMUL : for signed multiplication operation

Page 3: NEG Instruction

MUL/IMUL result will be stored in :

AX if byte type source

DX:AX if word type source

EDX:EAX if dword type source

Page 4: NEG Instruction

DIV and IDIV Instruction

Two division instruction:DIV operand : unsigned number

IDIV operand: signed number

Operand must be register or memory

Page 5: NEG Instruction

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

Page 6: NEG Instruction

Control bit instruction Logic instruction Shift instruction Rotate instruction

Page 7: NEG Instruction

Logik instructionTable 1. Boolean Instructions

Operation Description

AND Result is 1 only when both input bits are 1.

OR Result is 1 when either input bit is 1.

XOR Result is 1 only when the input bits are different (calledexclusive-OR).

NOT Result is the reverse of the input bit (in other words, 1 becomes0, and 0 becomes 1).

NEG Convert a number to its twos complement.

TEST Perform an implied AND operation on the destination operand,setting the flags appropriately.

BT, BTR, BTC,BTS

Copy bit n from the source operand to the Carry flag andtoggle/clear/set the same bit in the source operand.

CMP Compare two operands, setting the flags appropriately.

Page 8: NEG Instruction

AND Operation Truth table which shows operation

result of AND

1 0

1 1 0

0 0 0bit-1

bit-2

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

Page 9: NEG Instruction

Instruction Example

and ax,bxand var1,edxand bl,var2and dx,02FAhand al,00001111b

target source

Page 10: NEG Instruction

OR Instruction Truth table which show OR operation

result

1 0

1 1 1

0 1 0

bit-1

bit-2

op-1: 1 1 0 1 0 0 1 1op-2: 0 1 0 0 1 1 0 1result: 1 1 0 1 1 1 1 1

Page 11: NEG Instruction

Instruction example

or ax,bxor var1,edxor bl,var2or dx,02FAhor al,00001111b

target source

Page 12: NEG Instruction

XOR Instruction

Truth table shows XOR operation result

1 0

1 0 1

0 1 0

bit-1

bit-2

op-1: 1 1 0 1 0 0 1 1op-2: 0 1 0 0 1 1 0 1result: 1 0 0 1 1 1 1 0

Page 13: NEG Instruction

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

Page 14: NEG Instruction

Instruction example

mov al,10110011b xor al,10101100b ; AL = 00011111xor al,10101100b ; AL = 10110011

same

Page 15: NEG Instruction

NOT instruction Execute NOT operation at each bit at

operand

mov bh,11001101bnot bh ; bh = 00110010

Page 16: NEG Instruction

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

Page 17: NEG Instruction

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

Page 18: NEG Instruction

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

Page 19: NEG Instruction

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

Page 20: NEG Instruction

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

Page 21: NEG Instruction

ROR and ROL InstructionROL 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

Page 22: NEG Instruction

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

Page 23: NEG Instruction

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

Page 24: NEG Instruction

CMP Results CF ZF

Destination < source 1 0

Destination = source 0 1

Destination > source 0 0

Flags Set by the CMP Instruction

CMP Results ZF SF, OF

Destination < source ? SF <> OF

Destination = source 1 ?

Destination > source 0 SF = OF

Signed:

Unsigned:

Page 25: NEG Instruction

Jump Instruction There are two jump instruction

– Unconditional jump instruction– Conditional jump instruction

Format– Arahan_Lompat label

where Arahan_Lompat is an instructionlabel is the destination where jump will

target program execution (label is a name not a register,memory or any value)

Page 26: NEG Instruction

Some example of conditional jump instruction

Instruction Description

JMP Jump

JA Jump Above

JAE Jump Above or Equal

JB Jump Below

JBE Jump Below or Equal

JC Jump on Carry

JCXZ Jump if CX register is Zero

Page 27: NEG Instruction

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.

Page 28: NEG Instruction

LOOP instruction variations

Instruction Description

LOOPE/

LOOPZ

LOOP while Equal/LOOP while Zero

Jump to label if CX=0 and ZF=1

LOOPNE/

LOOPNZ

LOOP while Not Equal/LOOP while Not Zero

Jump to label if CX=0 and ZF=0