+ All Categories
Home > Documents > NEG Instruction Change operand content into two’s complement (negative value) and stored back into...

NEG Instruction Change operand content into two’s complement (negative value) and stored back into...

Date post: 14-Dec-2015
Category:
Upload: alanna-ledden
View: 219 times
Download: 0 times
Share this document with a friend
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
Transcript

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

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

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 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.

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

Instruction Example

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

target source

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

Instruction example

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

target source

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

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 = 00011111xor al,10101100b ; AL = 10110011

same

NOT instruction Execute NOT operation at each bit at

operand

mov bh,11001101bnot 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 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

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

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:

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)

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

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.

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


Recommended