Prev: 32768 Up: Map Next: 33300
33000: Divide
Input
HL Dividend
DE Divisor
Output
BC Quotient
Divide 33000 LD B,0 Set the sign to 0 in B.
33002 BIT 7,H Jump to Divide_0 if the dividend is positive.
33004 JR Z,Divide_0
33006 LD A,H Negate the dividend.
33007 CPL
33008 LD H,A
33009 LD A,L
33010 CPL
33011 LD L,A
33012 INC HL
33013 INC B Increment the sign by one.
Divide_0 33014 LD A,B Copy the sign to A.
33015 LD BC,0 Clear the quotient.
33018 EX AF,AF' Stash the sign in AF'.
33019 ADD HL,HL Shift the dividend left by four.
33020 ADD HL,HL
33021 ADD HL,HL
33022 ADD HL,HL
33023 LD A,L Move the low byte of the dividend into A.
33024 LD L,H Move the high byte of the dividend into L.
33025 LD H,0 Clear the high byte of the dividend.
Unrolled restoring divide into the quotient.
33027 RLA Jump to Divide_14 if this remainder bit does not fit.
33028 ADC HL,HL
33030 SBC HL,DE
33032 JP C,Divide_14
33035 SET 3,B Set bit 3 of the quotient.
33037 RLA Jump to Divide_15 if this remainder bit does not fit.
33038 ADC HL,HL
33040 SBC HL,DE
33042 JP C,Divide_15
Divide_1 33045 SET 2,B Set bit 2 of the quotient.
33047 RLA Jump to Divide_16 if this remainder bit does not fit.
33048 ADC HL,HL
33050 SBC HL,DE
33052 JP C,Divide_16
Divide_2 33055 SET 1,B Set bit 1 of the quotient.
33057 RLA Jump to Divide_17 if this remainder bit does not fit.
33058 ADC HL,HL
33060 SBC HL,DE
33062 JP C,Divide_17
Divide_3 33065 SET 0,B Set bit 0 of the quotient.
33067 XOR A Clear A.
33068 RLA Jump to Divide_18 if this remainder bit does not fit.
33069 ADC HL,HL
33071 SBC HL,DE
33073 JP C,Divide_18
Divide_4 33076 SET 7,C Set bit 7 of the quotient.
33078 RLA Jump to Divide_19 if this remainder bit does not fit.
33079 ADC HL,HL
33081 SBC HL,DE
33083 JP C,Divide_19
Divide_5 33086 SET 6,C Set bit 6 of the quotient.
33088 RLA Jump to Divide_20 if this remainder bit does not fit.
33089 ADC HL,HL
33091 SBC HL,DE
33093 JP C,Divide_20
Divide_6 33096 SET 5,C Set bit 5 of the quotient.
33098 RLA Jump to Divide_21 if this remainder bit does not fit.
33099 ADC HL,HL
33101 SBC HL,DE
33103 JP C,Divide_21
Divide_7 33106 SET 4,C Set bit 4 of the quotient.
33108 RLA Jump to Divide_22 if this remainder bit does not fit.
33109 ADC HL,HL
33111 SBC HL,DE
33113 JP C,Divide_22
Divide_8 33116 SET 3,C Set bit 3 of the quotient.
33118 RLA Jump to Divide_23 if this remainder bit does not fit.
33119 ADC HL,HL
33121 SBC HL,DE
33123 JP C,Divide_23
Divide_9 33126 SET 2,C Set bit 2 of the quotient.
33128 RLA Jump to Divide_24 if this remainder bit does not fit.
33129 ADC HL,HL
33131 SBC HL,DE
33133 JP C,Divide_24
Divide_10 33136 SET 1,C Set bit 1 of the quotient.
33138 RLA Jump to Divide_12 if this remainder bit does not fit.
33139 ADC HL,HL
33141 SBC HL,DE
33143 JP C,Divide_12
Divide_11 33146 SET 0,C Set bit 0 of the quotient.
Restore the sign of the quotient.
Divide_12 33148 EX AF,AF' Restore the sign from AF'.
33149 AND A Jump to Divide_13 if the sign is positive.
33150 JR Z,Divide_13
33152 LD A,C Negate the quotient.
33153 CPL
33154 LD C,A
33155 LD A,B
33156 CPL
33157 LD B,A
33158 INC BC
Divide_13 33159 RET Return.
Restore the remainder after a failed subtraction.
Divide_14 33160 RLA Restore the remainder.
33161 ADC HL,HL
33163 ADD HL,DE
33164 JP C,Divide_1 Jump to Divide_1 if carry is set.
Divide_15 33167 RLA Restore the remainder.
33168 ADC HL,HL
33170 ADD HL,DE
33171 JP C,Divide_2 Jump to Divide_2 if carry is set.
Divide_16 33174 RLA Restore the remainder.
33175 ADC HL,HL
33177 ADD HL,DE
33178 JP C,Divide_3 Jump to Divide_3 if carry is set.
Divide_17 33181 XOR A Clear A.
33182 RLA Restore the remainder.
33183 ADC HL,HL
33185 ADD HL,DE
33186 JP C,Divide_4 Jump to Divide_4 if carry is set.
Divide_18 33189 RLA Restore the remainder.
33190 ADC HL,HL
33192 ADD HL,DE
33193 JP C,Divide_5 Jump to Divide_5 if carry is set.
Divide_19 33196 RLA Restore the remainder.
33197 ADC HL,HL
33199 ADD HL,DE
33200 JP C,Divide_6 Jump to Divide_6 if carry is set.
Divide_20 33203 RLA Restore the remainder.
33204 ADC HL,HL
33206 ADD HL,DE
33207 JP C,Divide_7 Jump to Divide_7 if carry is set.
Divide_21 33210 RLA Restore the remainder.
33211 ADC HL,HL
33213 ADD HL,DE
33214 JP C,Divide_8 Jump to Divide_8 if carry is set.
Divide_22 33217 RLA Restore the remainder.
33218 ADC HL,HL
33220 ADD HL,DE
33221 JP C,Divide_9 Jump to Divide_9 if carry is set.
Divide_23 33224 RLA Restore the remainder.
33225 ADC HL,HL
33227 ADD HL,DE
33228 JP C,Divide_10 Jump to Divide_10 if carry is set.
Divide_24 33231 RLA Restore the remainder.
33232 ADC HL,HL
33234 ADD HL,DE
33235 JP C,Divide_11 Jump to Divide_11 if carry is set.
33238 JP Divide_12 Jump to Divide_12.
33241 NOP
33242 NOP
33243 NOP
33244 NOP
This entry point is used by the routine at Test_In_View.
Divide_25 33245 PUSH HL
33246 LD C,(HL)
33247 INC HL
33248 LD B,(HL)
33249 INC HL
33250 LD D,(HL)
33251 INC HL
33252 IN A,(C)
33254 OR 224
33256 INC A
33257 POP HL
33258 RET Z
33259 CP D
33260 INC HL
33261 INC HL
33262 INC HL
33263 RET Z
33264 LD HL,(57723)
33267 RET
33268 NOP
33269 NOP
33270 NOP
33271 NOP
33272 NOP
33273 NOP
33274 NOP
33275 NOP
33276 NOP
33277 NOP
33278 NOP
33279 NOP
33280 NOP
33281 NOP
33282 NOP
33283 NOP
33284 NOP
33285 NOP
33286 NOP
33287 NOP
33288 NOP
33289 NOP
33290 NOP
33291 NOP
33292 NOP
33293 NOP
33294 NOP
33295 NOP
33296 NOP
33297 NOP
33298 NOP
33299 NOP
Prev: 32768 Up: Map Next: 33300