Difference between revisions of "PM Opc DIV"

From SublabWiki
Jump to: navigation, search
(Execute)
(Execute)
Line 21: Line 21:
 
   
 
   
 
  L = HL / A
 
  L = HL / A
 +
H = HL % A
 +
 +
or
 +
 +
L = HL DIV A
 
  H = HL MOD A
 
  H = HL MOD A
  

Revision as of 17:17, 9 November 2008

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

L = HL / A
H = HL % A

or

L = HL DIV A
H = HL MOD A

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 result can't fit in 8-Bits range

Sign: Set when 7th bit 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