Mul: Unsigned Multiplication  
    
; Influence of, CF flag bit; Command Format:; Mul R/m; parameter is the multiplier; if the parameter is R8/M8, the Al will be used as the multiplier and the result will be placed in ax; if the parameter is R16/M16, ax will be used as the multiplier and the result will be placed in eax; if the parameter is R32/M32, eax will be used as the multiplier and the result will be placed in edX: eax
  
   
 ; Test27_1.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data Val dd 8. codemain proc; 8-bit mov Al, 0ffh Mul byte PTR Val printhex ax; 07f8; 16-bit mov ax, 0 ffffh Mul word PTR Val printhex DX; 0007 printhex ax; fff8; 32-bit mov eax, 0 ffffffffh Mul Val printhex edX; 00000007 printhex eax; fffffff8 retmain endpend main
  
   
 The above example is slightly modified (mul-> imul) and different results are obtained:; test27_2.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data Val dd 8. codemain proc; 8-bit mov Al, 0ffh imul byte PTR Val printhex ax; fff8; 16-bit mov ax, 0 ffffh imul word PTR Val printhex DX; FFFF printhex ax; fff8; 32-bit mov eax, 0 ffffffffh imul Val printhex edX; ffffffff printhex eax; fffffff8 retmain endpend main
  
   
 
 
 
Imul: signed Multiplication
 
    
; Influence of and CF flag bits; First Command Format:; imul R/m; single operand; if the parameter is R8/M8, the Al will be used as the multiplier and the result will be placed in ax; if the parameter is R16/M16, ax will be used as the multiplier and the result will be placed in eax; if the parameter is R32/M32, eax will be used as the multiplier and the result will be placed in edX: eax; these are all the same as Mul, but the calculation results are sometimes the same and sometimes different .; imul has two other command formats: imul R16/R32, R16/R32/M16/M32/I; dual operands, (1) * (2)-> (1 ); imul R16/R32, R16/R32/M16/M32, I; three operands, (2) * (3)-> (1); where the number of bits of constant I can be other operands
  
   
 ; Test27_3.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data Val dd 8. codemain proc; imul two operands mov eax, 7 imul eax, Val printdec eax; 56; imul three operands imul eax, Val, 9 printdec eax; 72 retmain endpend main
  
   
 ; Mul and imul results are inconsistent:; test27_4.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. data Val dB 7fh. codemain proc; if the operands do not have a signed bit, the result is consistent with mov Al, 7fh Mul Val printhex ax; 3f01 mov Al, 7fh imul Val printhex ax; 3f01; if one of the operands has a signed bit, inconsistent results: mov Al, 80 h Mul Val printhex ax; 3f80 mov Al, 80 h imul Val printhex ax; c080; if the operands all have symbol bits, the results are also consistent with INC Val mov Al, 80 h Mul Val printhex ax; 4000 mov Al, 80 h imul Val printhex ax; 4000 retmain endpend main
  
   
 
 
 
Div and idiv: unsigned and signed
 
    
; They do not define the effect on eflags; their command format:; Div R/m; the parameter is divisor; if the parameter is R8/M8, ax will be used as the divisor; quotient-> Al, remainder-> Ah; if the parameter is R16/M16, DX: ax will be used as the divisor; quotient-> ax, remainder-> DX; if the parameter is R32/M32, EDX: eax will be used as the divisor; quotient-> eax, remainder-> edX
  
   
 ; Div test; test27_5.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. codemain proc; divisor: 8-bit mov ax, 17; divisor mov Cl, 3; divisor Div Cl printdec al; 5-vendor printdec Ah; 2-remainder; the divisor is 16-bit mov dx, 0; MoV ax, 17; DX: ax is the divisor mov CX, 3; CX is the divisor Div CX printdec ax; 5-vendor printdec DX; 2-remainder; divisor: 32-bit mov edX, 0; MoV eax, 17; edX: eax: divisor mov ECx, 3; ECx: divisor Div ECx printdec eax; 5-vendor printdec edX; 2-remainder retmain endpend main
  
   
 ; Idiv test; test27_6.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. codemain proc; the divisor is an 8-bit mov Al,-17 CBW; ax is the divisor mov Cl, 3; divisor idiv Cl printdec al;-5-vendor printdec Ah;-2-remainder; the divisor is 16-bit mov ax,-17 CWD; DX: ax is the divisor mov CX, 3; CX is the divisor idiv CX printdec ax;-5-vendor printdec DX; -2-remainder; divisor: 32-bit mov eax,-17 CDQ; edX: eax: divisor mov ECx, 3; ECx: divisor idiv ECx printdec eax; -5-vendor printdec edX;-2-remainder retmain endpend main