This is another way:
;
; File: main.asm
; Target: PIC16F877A
; IDE: MPLABX v5.25
; Assembler: MPASM v5.84
;
; Description:
;
; Show implementation and test of integer division.
;
;
; Notes:
;
; Forum post: https://electronics.stackexchange.com/questions/463950/how-do-i-perform-division-of-two-numbers-in-pic16f877a-in-assembly-language
;
;
list r=dec,n=0,c=132
errorlevel -302, -312
;
#include "p16F877A.inc"
__CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
#define FOSC (4000000)
#define FCYC (FOSC/4)
;
; Define macros to help
; with bank selection
;
#define BANK0 (h'000')
#define BANK1 (h'080')
#define BANK2 (h'100')
#define BANK3 (h'180')
;
;**********************************************************************
RESET_VECTOR code 0x000 ; processor reset vector
nop
goto start ; begin PIC initialization
;------------------------------------------------------------------------
start:
clrf INTCON ; Disable all interrupt sources
clrf TMR0
banksel BANK1
clrf PIE1
clrf PIE2
movlw b'11000000' ; Pull-ups off, INT edge low to high, WDT prescale 1:1
movwf OPTION_REG ; TMR0 clock edge low to high, TMR0 clock = FCY, TMR0 prescale 1:2
movlw b'11111111' ;
movwf TRISA
movlw b'01111111' ;
movwf TRISB
movlw b'11111111' ;
movwf TRISC
movlw b'11111111' ;
movwf TRISD
; disable comparators
movlw b'00000111'
movwf CMCON
; Set all ADC inputs for digital I/O
movlw b'00000110'
movwf ADCON1
banksel BANK0
pagesel main
goto main
;
; Interger 8x8 division with remainder
;
; Quotient = Dividen / Divisor, with Remainder
;
; Input: Dividen
; Divisor
;
; Output: Quotient in WREG
; Remainder
;
Div8x8_DATA udata 0x20
Divisor res 1
Dividen
Quotient res 1
Remainder res 1
BitCount res 1
Div8x8_CODE code
Div8x8:
banksel BitCount
movlw 8
movwf BitCount
clrf Remainder
Div8x8Loop:
clrc
rlf Dividen,F
rlf Remainder,F
movf Divisor,W
subwf Remainder,W
skpnz
goto BigEnough
skpc
goto TooSmall
BigEnough:
movwf Remainder
bsf Dividen,0
TooSmall:
decfsz BitCount,F
goto Div8x8Loop
movf Quotient,W
return
;
; Main application loop
;
MAIN_DATA udata
Value1 res 1
Value2 res 1
MAIN_CODE code
main:
;
; Loop here forever testing Dividen and Divisors
;
ProcessLoop:
;
;
banksel Value1
clrf Value1
decf Value1,F
clrf Value2
decf Value2,F
TestLoop:
banksel Value1
movf Value1,W
banksel Divisor
movwf Divisor
banksel Value2
movf Value2,W
banksel Dividen
movwf Dividen
call Div8x8
banksel Value1
decfsz Value1,F
goto TestLoop
decf Value1,F
banksel Value2
decfsz Value2,F
goto TestLoop
decf Value2,F
goto ProcessLoop
end
If you are going to crib this for you homework at least you can add the comments.