Difference between revisions of "PM Opc DIV"

From SublabWiki
Jump to: navigation, search
(Conditions)
m (Examples)
 
(2 intermediate revisions by the same user not shown)
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 20: Line 20:
 
  ; H will be the Remainder/Rest
 
  ; H will be the Remainder/Rest
 
   
 
   
  L = HL / A
+
  Ds = HL ÷ A
  H = HL % A
+
  IF Ds < 256 THEN
 +
  L = Ds          ; Quotient
 +
  H = HL % A     ; Remainder
 +
ENDIF
 
   
 
   
or
 
 
L = HL DIV A
 
H = HL MOD A
 
  
 
'''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 36: 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 46: 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 7th bit of Quotient is 1
+
Sign: Set when bit 7 of Quotient is 1
  
 
=== Examples ===
 
=== Examples ===
Line 52: Line 51:
 
  ; A = 0x02
 
  ; A = 0x02
 
  ; HL = 0x0007
 
  ; HL = 0x0007
  DIV HL, A
+
  '''DIV HL, A'''
 
  ; 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
 
  ; HL = 0x0007
 
  ; HL = 0x0007
  DIV HL, A
+
  '''DIV HL, A'''
 
  ;          (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
  
 
  ; A = 0x02
 
  ; A = 0x02
 
  ; HL = 0xFFFD
 
  ; HL = 0xFFFD
  DIV HL, A
+
  '''DIV HL, A'''
 
  ;          (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''']]

Latest revision as of 00:25, 21 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)

« Back to Instruction set