forked from YatinAdityaT/8085
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdivide16with8
54 lines (36 loc) · 807 Bytes
/
divide16with8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;DIVIDE 16BIT WITH 8BIT
; substract till the 16bit number is smaller than the 8bit number
JMP START
START: MVI A,10;
STA 2200;
MVI A,01;
STA 2201;
MVI A,6;
STA 2202;
LDA 2201; UPPER BYTE IN A
MOV B,A; UPPER BYTE IN B
LDA 2202; 8 BIT NUMBER IN A
MOV C,A;8 BIT NUMBER IN C
LDA 2200; LOWER BYTE IN A
LXI D,0000; CLEAR DE PAIR,USED AS Q
LXI H,0000; CLEAR HL PAIR
MAIN: CMP C; COMPARE 8 BIT WITH LOWER BYTE
JC JUMP1; IF CARRY THEN JUMP TO JUMP1
SUB C; A-C=>A
MOV H,A; STORE A
INX D; INCREMENT DE PAIR
JMP MAIN
JUMP1: DCR B; DEC UPPER BYTE
JZ EXIT; IF B BECOMES 0 THEN EXIT
ADI 16; ADD 16 TO LOWER BYTE
SUB C; A-C=>A
MOV H,A; STORE A
INX D; INCREMENT DE PAIR
JMP MAIN
EXIT: MOV A,H;GET D
STA 2302; LOWER BYTE OF REMAINDER
MOV A,E
STA 2300
MOV A,D
STA 2301
HLT