采用對符號(hào)位單獨(dú)處理的辦法,處理步驟如下:
單獨(dú)處理被乘數(shù)和乘數(shù)的符號(hào)位,辦法是單獨(dú)取出被乘數(shù)符號(hào)位并與乘數(shù)符號(hào)位進(jìn)行異或操作,因?yàn)榉e的符號(hào)位的產(chǎn)生規(guī)則是同號(hào)相乘為正,異號(hào)相乘為負(fù)。
求被乘數(shù)和乘數(shù)的絕對值,并使兩絕對值相乘從而獲得積的絕對值,方法是分別判斷被乘數(shù)和乘數(shù)的符號(hào)位:若它為正,則其本身就是絕對值;若它為負(fù),則對它求補(bǔ)。
對積進(jìn)行處理。若積為正,則對積不進(jìn)行處理;若積為負(fù),則對積求補(bǔ),使之變?yōu)檠a(bǔ)碼的形式。
R0和R1中為兩個(gè)補(bǔ)碼形式的帶符號(hào)數(shù),R3R2為積 R0*R1=R3R2
?
ORG 0600H’
SBIT BIT 20H.0
SBIT1 BIT 20H.1
SBIT2 BIT 20H.2
?
MOV A,R0???????????? ;被乘數(shù)送A
RLC A?????????????????? ;被乘數(shù)符號(hào)送CY
MOV SBIT1,C??????? ;送入SBIT1
MOV A,R1???????????? ;乘數(shù)送A
RLC A?????????????????? ;乘數(shù)符號(hào)送CY
MOV SBIT2,C??????? ;送入SBIT2
ANL C,/SBIT1??????? ;SBIT1非 與 SBIT2 送CY
MOV SBIT,C????????? ;送入SBIT
MOV C,SBIT1??????? ;SBIT1送CY
ANL C,SBIT2????????? ;SBIT1 與 SBIT2非 送CY
ORL C,SBIT??????????? ;積的符號(hào)位送CY
MOV SBIT,C????????? ; 送入SBIT
MOV A,R0???????????? ;處理被乘數(shù)
JNB SBIT1,NCH1??? ;若她為正,則轉(zhuǎn)NCH1
CPL A?????????????????? ;若她為負(fù),則求補(bǔ)的絕對值
INC A?????????????????? ;
NCH1:??? MOV B,A????????????? ;被乘數(shù)絕對值送B
????????????? MOV A,R1???????????? :處理乘數(shù)
JNB SBIT2,NCH2??? ;若它為正,則轉(zhuǎn)NCH2
CPL A?????????????????? ;若她為負(fù),則求補(bǔ)的絕對值
ADD A,#01H???????? ;
NCH2:??? MUL AB??????????????? ;求積的絕對值
JNB SBIT,NCH3???? ;若積為正,則轉(zhuǎn)NCH3
CPL A?????????????????? ;若積為負(fù),則低字節(jié)求補(bǔ)
ADD A,#01H???????? ;
NCH3:??? MOV R2,A???????????? ;積的低字節(jié)存入R2
MOV A,B????????????? ;積的高字節(jié)送A
JNB SBIT,NCH4???? ;若積為正,則轉(zhuǎn)NCH4
CPL A?????????????????? ;若積為負(fù),則高字節(jié)求補(bǔ)
ADDC A,00H???????? ;
NCH4:??? MOV R3,A???????????? ;積的高字節(jié)存入R3
SJMP $
END
評(píng)論
查看更多