1 / 28

NEG Instruction

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.

jera
Download Presentation

NEG Instruction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. MUL/IMUL result will be stored in : • AX if byte type source • DX:AX if word type source • EDX:EAX if dword type source

  4. DIV and IDIV Instruction • Two division instruction: • DIV operand : unsigned number • IDIV operand: signed number • Operand must be register or memory

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

  6. Control bit instruction • Logic instruction • Shift instruction • Rotate instruction

  7. Logik instruction • Table 1. Boolean Instructions

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

  9. Instruction Example target source and ax,bx and var1,edx and bl,var2 and dx,02FAh and al,00001111b

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

  11. Instruction example target source or ax,bx or var1,edx or bl,var2 or dx,02FAh or al,00001111b

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

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

  14. Instruction example mov al,10110011b xor al,10101100b ; AL = 00011111 xor al,10101100b ; AL = 10110011 same

  15. NOT instruction • Execute NOT operation at each bit at operand mov bh,11001101b not bh ; bh = 00110010

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

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

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

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

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

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

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

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

  24. Flags Set by the CMP Instruction Unsigned: Signed:

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

  26. Some example of conditional jump instruction

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

  28. LOOP instruction variations

More Related