; 8bit, works with dividend 0 .. (2^16 - 1) 64 KiB
MOV AX, 13 ; dividend
MOV CL, 5 ; divisor
DIV CL ; Remainder 3 is now in AH, quotient 2 is in AL.
; 16bit, works with dividend 0 .. (2^32 - 1) 4 GiB
MOV AX, 13 ; lower 16 bits of dividend
MOV DX, 0 ; higher 16 bits of dividend
MOV CX, 5 ; divisor
DIV CX ; Remainder 3 is now in DX, quotient 2 is in AX.
; 32bit, works with dividend 0 .. (2^64 - 1) 16 EiB
MOV EAX, 13 ; lower 32 bits of dividend
MOV EDX, 0 ; higher 32 bits of dividend
MOV ECX, 5 ; divisor
DIV ECX ; Remainder 3 is now in EDX, quotient 2 is in EAX.
; 64bit, works with dividend 0 .. (2^128 - 1) 256 ???
MOV RAX, 13 ; lower 64 bits of dividend
MOV RDX, 0 ; higher 64 bits of dividend
MOV RCX, 5 ; divisor
DIV RCX ; Remainder 3 is now in RDX, quotient 2 is in RAX.
1条答案
按热度按时间bvpmtnay1#
在大多数汇编器中,模运算符是**%或**。模运算表示被除数除以除数后的余数。
例如,当被除数为
13
,除数为5
时,则取模结果为13 % 5 = 3
。x86中的无符号除法由指令DIV提供,它取决于CPU模式:对于使用带符号除法IDIV的带符号数,它要复杂得多,请参阅文章Modulo on Wikipedia。