Here we will see how to divide two 16 bit numbers using 8085.
Write 8085 Assembly language program to divide two 16-bit numbers.
8085 has no division operation. To perform division, we have to use repetitive subtraction. To perform 16-bit division, we have to do the same but for the register pairs. As the register pairs are used to hold 16-bit data.
The Divisor is stored at location FC00 and FC01, the dividend is stored at FC02 and FC03. After division, the quotient will be stored at FC04 and FC05, and the remainder will be stored at FC06 and FC07.
|F000||01, 00, 00|| ||LXI B,0000H||Clear BC register pair|
|F003||2A, 02, FC|| ||LHLD FC02H||Take the Divisor into HL first|
|F006||EB|| ||XCHG||Exchange DE and HL|
|F007||2A, 00, FC|| ||LHLD FC00H||Take the dividend|
|F00A||7D||LOOP||MOV A,L||Load L into A|
|F00B||93|| ||SUB E||Subtract E from A|
|F00C||6F|| ||MOV L,A||Store A into L|
|F00D||7C|| ||MOV A,H||Load H into A|
|F00E||9A|| ||SBB D||Subtract B from A with Borrow|
|F00F||67|| ||MOV H,A||Store A into H again|
|F010||DA, 17, F0|| ||JC SKIP||If CY is 1, Skip|
|F013||03|| ||INX B||Increase B by 1|
|F014||C3, 0A, F0|| ||JMP LOOP||Jump to Loop|
|F017||19||SKIP||DAD D||Add HL and DE|
|F018||22, 06, F0|| ||SHLD FC06H||Store remainder into FC06 and FC07|
|F01B||69|| ||MOV L,C||Load C into L|
|F01C||60|| ||MOV H,B||Load B into H|
|F01D||22, 04, FC|| ||SHLD FC04H||Store quotient into FC04 and FC05|
|F020||76|| ||HLT||Terminate the program|