8085 program to divide two 8 bit numbers
Problem – Write 8085 program to divide two 8 bit numbers.
Example –
Algorithm –
- Start the program by loading the HL pair registers with address of memory location.
- Move the data to B Register.
- Load the second data into accumulator.
- Compare the two numbers to check carry.
- Subtract two numbers.
- Increment the value of carry.
- Check whether the repeated subtraction is over.
- Then store the results(quotient and remainder) in given memory location.
- Terminate the program.
Program –
ADDRESS | MNEMONICS | COMMENT |
---|---|---|
2000 | LXI H, 2050 | |
2003 | MOV B, M | B<-M |
2004 | MVI C, 00 | C<-00H |
2006 | INX H | |
2007 | MOV A, M | A<-M |
2008 | CMP B | |
2009 | JC 2011 | check for carry |
200C | SUB B | A<-A-B |
200D | INR C | C<-C+1 |
200E | JMP 2008 | |
2011 | STA 3050 | 3050<-A |
2014 | MOV A, C | A<-C |
2015 | STA 3051 | 3051<-A |
2018 | HLT | terminate the program |
Explanation – Registers A, H, L, C, B are used for general purpose.
- LXI H, 2050 will load the HL pair register with the address 2050 of memory location.
- MOV B, M copies the content of memory into register B.
- MVI C, 00 assign 00 to C.
- INX H increment register pair HL.
- MOV A, M copies the content of memory into accumulator.
- CMP B compares the content of accumulator and register B.
- JC 2011 jump to address 2011 if carry flag is set.
- SUB B subtract the content of accumulator with register B and store the result in accumulator.
- INR C increment the register C.
- JMP 2008 control will shift to memory address 2008.
- STA 3050 stores the remainder at memory location 3050.
- MOV A, C copies the content of register into accumulator.
- STA 3051 stores the quotient at memory location 3051.
- HLT stops executing the program and halts any further execution.
Please Login to comment...