刚写的三字节除法程序,程序是调通了,但觉得自己算法太差。希望 高人指导下。
;--------------------------------三字节除法 Divisor_AND_Residue_H EQU 30H ;被除数和余数 Divisor_AND_Residue_M EQU 31H Divisor_AND_Residue_L EQU 32H
Dividend_DATA_H EQU 33H ;除数寄存器 Dividend_DATA_M EQU 34H Dividend_DATA_L EQU 35H
Quotient_DATA_H EQU 36H ;商数 Quotient_DATA_M EQU 36H Quotient_DATA_L EQU 37H
DIV_FLAG BIT 21H.0 ;除法结束标志位
ORG 0000H AJMP MAIN ORG 0300H MAIN:
MOV SP,#70H MOV Divisor_AND_Residue_H,#0F0H MOV Divisor_AND_Residue_M,#0F3H MOV Divisor_AND_Residue_L,#067H
MOV Dividend_DATA_H,#05h MOV Dividend_DATA_M,#023h MOV Dividend_DATA_L,#22h
MOV Quotient_DATA_H,#00H MOV Quotient_DATA_M,#00H MOV Quotient_DATA_L,#00H
CLR DIV_FLAG
LCALL DIV33 MOV R1,Quotient_DATA_H MOV R2,Quotient_DATA_M MOV R3,Quotient_DATA_L
MOV R4,Divisor_AND_Residue_H MOV R5,Divisor_AND_Residue_M MOV R6,Divisor_AND_Residue_L AJMP $
DIV33: ;三字节除法程序 SUBB_LOOP: ;循环做减法 CALL SUBB_Judge ;比较被减数是否大于减数 JB DIV_FLAG,DIV_OVER CLR C INC Quotient_DATA_L MOV A,Quotient_DATA_M ADDC A,#00H MOV Quotient_DATA_M,A MOV A,Quotient_DATA_H ADDC A,#00H AJMP SUBB_LOOP DIV_OVER: RET
SUBB_Judge: CLR C MOV A,Divisor_AND_Residue_H SUBB A,Dividend_DATA_H JC SUBB_STOP JNZ SUBB33 CLR C MOV A,Divisor_AND_Residue_M SUBB A,Dividend_DATA_M JC SUBB_STOP JNZ SUBB33 CLR C MOV A,Divisor_AND_Residue_L SUBB A,Dividend_DATA_L JC SUBB_STOP
SUBB33: ;三字节减法 MOV A,Divisor_AND_Residue_L CLR C SUBB A,Dividend_DATA_L MOV Divisor_AND_Residue_L,A MOV A,Divisor_AND_Residue_M SUBB A,Dividend_DATA_M MOV Divisor_AND_Residue_M,A MOV A,Divisor_AND_Residue_H SUBB A,Dividend_DATA_H MOV Divisor_AND_Residue_H,A RET
SUBB_STOP:
SETB DIV_FLAG RET
END |