INCLUDE"P16F877.INC"ORG 0000HGOTO A1ORG 002BHA1 MOVLW 00HMOVWF 40H;數(shù)據(jù)處理寄存器高位(乘積高8位)MOVLW 00HMOVWF 41H;數(shù)據(jù)處理寄存器低位(乘積高中8位)MOVLW 0FFHMOVWF 42H;被乘數(shù)高位(乘積低中8位)MOVLW 0FFH MOVWF 43H;被乘數(shù)低位(乘積低8位)MOVLW 0FFHMOVWF 44H;乘數(shù)高位MOVLW 0FFHMOVWF 45H;乘數(shù)低位MOVLW D16MOVWF 4AH;循環(huán)次數(shù)--8位二進(jìn)制數(shù)相乘8次4位則4次A2 CLRF 4BH;清標(biāo)志BTFSS 43H,0;判斷被乘數(shù)第0位是否為0是則不用相加 GOTO A3MOVFW 45H;不為0則相加ADDWF 41H,1;乘數(shù)低位與處理后數(shù)據(jù)低位相加數(shù)據(jù)存回數(shù)據(jù)處理低位寄存器MOVFW 44H;BTFSC STATUS,C;判斷是否溢出INCF 44H,0;是則加1BTFSC STATUS,Z;判斷加1后是否溢出BSF 4BH,1;是則置為標(biāo)志ADDWF 40H,1;乘數(shù)低位與處理后數(shù)據(jù)高位相加上面相加可能溢出所以用ADDC數(shù)據(jù)存回數(shù)據(jù)處理高位寄存器BTFSC 4BH,1;判斷溢出標(biāo)志BSF STATUS,C;溢出則置位CA3 RRF 40H,1;先右移高位相加可能溢出RRF循環(huán)帶C右移RRF 41H,1;再右移低位把高位的數(shù)移入低位RRF 42H,1;將處理后的數(shù)移到被乘數(shù)高位RRF 43H,1;將處理后的數(shù)移到被乘數(shù)低位DECFSZ 4AH,1;是否完成GOTO A2NOPNOPNOPGOTO $END
評論