Difference between revisions of "PM Opc DIV"
From SublabWiki
(→Execute) |
m (Sortable list) |
||
Line 1: | Line 1: | ||
== DIV = Divide == | == DIV = Divide == | ||
− | {| border="1" style="text-align:left" | + | {| border="1" style="text-align:left" class="sortable" |
!Hex | !Hex | ||
!Mnemonic | !Mnemonic | ||
Line 29: | Line 29: | ||
'''Note:''' | '''Note:''' | ||
− | Can throw Division by Zero if Divisor is 0 (We need to research more about this) | + | Can throw Division by Zero if Divisor is 0 (We need to research more about this). |
If Quotient can't fit in 8-Bits range, Overflow flag will be set and the result won't be saved. | If Quotient can't fit in 8-Bits range, Overflow flag will be set and the result won't be saved. | ||
Line 35: | Line 35: | ||
=== Description === | === Description === | ||
− | 16-Bits Register HL divide by 8-Bits Register A, Quotient will be stored at 8-Bits Register L and Remainder will be stored at 8-Bits Register H. | + | "16-Bits Register HL" divide by "8-Bits Register A", Quotient will be stored at "8-Bits Register L" and Remainder will be stored at "8-Bits Register H". |
=== Conditions === | === Conditions === | ||
Line 45: | Line 45: | ||
Overflow: Set when Quotient can't fit in 8-Bits range | Overflow: Set when Quotient can't fit in 8-Bits range | ||
− | Sign: Set when | + | Sign: Set when bit 7 of Quotient is 1 |
=== Examples === | === Examples === | ||
Line 54: | Line 54: | ||
; L = 0x03 (0x0007 / 0x02 = 0x03 (with rest 0x01)) | ; L = 0x03 (0x0007 / 0x02 = 0x03 (with rest 0x01)) | ||
; H = 0x01 (Remainder/Rest) | ; H = 0x01 (Remainder/Rest) | ||
− | ; F = (Zero = 0):(Carry = 0):(Overflow=0):(Sign=0) | + | ; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=0) |
; A = 0x00 | ; A = 0x00 | ||
Line 61: | Line 61: | ||
; (0x0007 / 0x00 = Division by Zero) | ; (0x0007 / 0x00 = Division by Zero) | ||
; HL = 0x???? (Unpredictable result!?) | ; HL = 0x???? (Unpredictable result!?) | ||
− | ; F = (Zero = ?):(Carry = ?):(Overflow=?):(Sign=?) | + | ; F = (Zero=?):(Carry=?):(Overflow=?):(Sign=?) |
; - Throw Division by Zero Exception | ; - Throw Division by Zero Exception | ||
Line 69: | Line 69: | ||
; (0xFFFD / 0x02 = 0x7FFE (with rest 0x01)) | ; (0xFFFD / 0x02 = 0x7FFE (with rest 0x01)) | ||
; HL = 0xFFFD (Results are unchanged since Quotient exceed 8-Bits range) | ; HL = 0xFFFD (Results are unchanged since Quotient exceed 8-Bits range) | ||
− | ; F = (Zero = 0):(Carry = 0):(Overflow=1):(Sign=1) | + | ; F = (Zero=0):(Carry=0):(Overflow=1):(Sign=1) |
[[PM_InstructionList|'''« Back to Instruction set''']] | [[PM_InstructionList|'''« Back to Instruction set''']] |
Revision as of 03:03, 19 April 2009
DIV = Divide
Hex | Mnemonic | Cycles |
---|---|---|
CE D9 | DIV HL, A | 52 |
Execute
; DIV HL, A ; ; HL is the Dividend ; A is the Divisor ; L will be the Quotient ; H will be the Remainder/Rest Ds = HL ÷ A IF Ds < 256 THEN L = Ds ; Quotient H = HL % A ; Remainder ENDIF
Note:
Can throw Division by Zero if Divisor is 0 (We need to research more about this).
If Quotient can't fit in 8-Bits range, Overflow flag will be set and the result won't be saved.
Description
"16-Bits Register HL" divide by "8-Bits Register A", Quotient will be stored at "8-Bits Register L" and Remainder will be stored at "8-Bits Register H".
Conditions
Zero: Set when result is 0
Carry: Always Clear
Overflow: Set when Quotient can't fit in 8-Bits range
Sign: Set when bit 7 of Quotient is 1
Examples
; A = 0x02 ; HL = 0x0007 DIV HL, A ; L = 0x03 (0x0007 / 0x02 = 0x03 (with rest 0x01)) ; H = 0x01 (Remainder/Rest) ; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=0)
; A = 0x00 ; HL = 0x0007 DIV HL, A ; (0x0007 / 0x00 = Division by Zero) ; HL = 0x???? (Unpredictable result!?) ; F = (Zero=?):(Carry=?):(Overflow=?):(Sign=?) ; - Throw Division by Zero Exception
; A = 0x02 ; HL = 0xFFFD DIV HL, A ; (0xFFFD / 0x02 = 0x7FFE (with rest 0x01)) ; HL = 0xFFFD (Results are unchanged since Quotient exceed 8-Bits range) ; F = (Zero=0):(Carry=0):(Overflow=1):(Sign=1)