只要在程序执行时输入0-999范围里的整数就可以得到结果。
X为十进制度数对待,在SIN函数里不化成弧度。得到的结果是2位数。
DATA SEGMENT
MESS1 DB ' PLEASE ENTER A NUMBER X (1--999)',0DH,0AH,'$'
MESS2 DB 0DH,0AH,' WROUNG NUMBER !',0DH,0AH,'$'
MESS3 DB 0DH,0AH,' SIN(X)+345*X/67'
DB 0DH,0AH,' RESULT=$'
D3 DB 10
DB ?
DB 10 DUP (?)
D4 DB 10 DUP (?) ;X的非压缩BCD码
D5 DB 30 DUP (?)
D10 DB 30 DUP(?) ;相乘的结果及最后的相加结果
D6 DB 0
D7 DW ? ;SIN值
D8 DB ?
D9 DW ?
TUP DB 00
DB 02,04,05,07,09,11,12,14,16,17
DB 19,21,23,24,26,28,29,31,33,34
DB 36,38,39,41,42,44,45,47,49,50
DB 52,53,55,56,57,59,60,62,63,64
DB 66,67,68,70,71,72,73,74,76,77
DB 78,79,80,81,82,83,84,85,86,87
DB 88,88,89,90,91,91,92,93,93,94
DB 95,95,96,96,97,97,97,98,98,99
DB 99,99,99,99,100,100,100,100,100,100
DATA ENDS
STACK SEGMENT STACK
STA DW 100 DUP(?)
TOP LABEL WORD
STACK ENDS
CODE SEGMENT
MAIN PROC FAR
ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
START:
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET TOP
MOV AX,DATA
MOV DS,AX
MOV ES,AX
L0: MOV DX,OFFSET MESS1 ;提示输入,必须A键开始
MOV AH,09H ;且位数小于4
INT 21H
MOV DX,OFFSET D3
MOV AH,0AH
INT 21H
MOV BX,DX
MOV CL,[BX+1]
MOV CH,CL
CMP CL,3
JBE CONTU
MOV AH,09H
MOV DX,OFFSET MESS2
INT 21H
JMP L0
CONTU:ADD BX,2
MOV SI,BX
MOV DI,0
L1: MOV D8,CH ;转化为非压缩BCD,转存到D4,长度存入D8单元
MOV AL,[SI]
AND AL,0FH
MOV D4[DI],AL
INC SI
INC DI
DEC CL
JNZ L1
MOV SI,0
MOV BX,DI
LOOP1:MOV CH,D4[BX-1] ;D4中值一位一位和515相乘,调用MMUL
CALL MMUL
INC SI
DEC BX
JNZ LOOP1
MOV SI,DX
MOV D9,DX
MOV BX,0 ;相乘结果反相存入D10
DEC SI
L9: MOV AL,D5[SI]
MOV D10[BX],AL
INC BX
DEC SI
CMP SI,0
JNL L9
DEC BX
MOV SI,BX
CALL PSIN ;调用SIN子函数
CLC
XOR DX,DX ;两部分相加或相减合成
XOR BX,BX
MOV DX,D7
MOV BX,DX
CMP DH,0
JZ L5
MOV CH,3
JMP L7
L5: MOV CH,2
L7: AND DL,0FH
CMP D6,0
JNZ L6
MOV AL,D10[SI]
ADC AL,DL
AAA
JMP L8
L6: MOV AL,D10[SI]
SBB AL,DL
AAS
L8: MOV CL,4
MOV DX,BX
SHR DX,CL
DEC SI
DEC CH
CMP CH,0
JNZ L7
JNC L10
CMP D6,0
JZ L11
SBB D10[SI],1
JMP L10
L11: ADD D10[SI],1
L10: MOV DX,OFFSET MESS3 ;以十进制显示
MOV AH,09H
INT 21H
MOV BX,D9
MOV SI,0
L4: OR D10[SI],30H
MOV DL,D10[SI]
MOV AH,2
INT 21H
INC SI
DEC BX
CMP BX,2
JNZ L4
MOV DL,2EH ;输出小数点
MOV AH,2
INT 21H
L3: OR D10[SI],30H
MOV DL,D10[SI]
MOV AH,2
INT 21H
INC SI
DEC BX
JNZ L3
EXIT:
MOV AH,8
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP ;主程序结束
MMUL PROC NEAR ;两个多位数十进制相乘,
PUSH SI
MOV AL,05H
CALL MULS
CALL DOUT
INC SI
MOV AL,01H
CALL MULS
CALL DOUT
INC SI
MOV AL,05H
CALL MULS
CALL DOUT
INC SI
POP SI
RET
MMUL ENDP
MULS PROC NEAR ;两个一位十进制数相乘,结果以非压缩BCD
PUSH BX ;码形式保留在AX中
MOV BL,CH
AND AL,0FH
AND BL,0FH
MUL BL
AAM
POP BX
RET
MULS ENDP
DOUT PROC NEAR ;累加部分
PUSH SI
NEXT:ADD AL,D5[SI]
AAA
MOV D5[SI],AL
MOV AL,AH
XOR AH,AH
INC SI
MOV DX,SI
CMP AL,0
JNZ NEXT
POP SI
RET
DOUT ENDP
PSIN PROC NEAR ;SIN子函数
PUSH BX
PUSH SI
PUSH DX
PUSH AX
PUSH DI
PUSH CX
MOV SI,OFFSET TUP
MOV DX,0
MOV AX,0
MOV DI,OFFSET D4 ;将D4单元中内容移入DX,AX
MOV CL,D8
CMP CL,1
JNZ Y1
MOV AL,[DI]
MOV BX,AX
JMP P4
Y1: CMP CL,2
JNZ Y2
MOV AH,[DI]
MOV AL,[DI+1]
CMP AX,90
JA P0
MOV BX,AX
JMP P4
Y2: MOV DL,[DI]
MOV AH,[DI+1]
MOV AL,[DI+2]
P0: MOV BX,0900H ;相除,看X在1,2,3,4那个象限中
AAD ;并确定寻址,结果存如D7中
DIV BX
MOV BX,DX
MOV CH,4
AAD
DIV CH
XOR CX,CX
CMP AH,0
JNZ P1
P4: MOV CX,[SI+BX]
MOV D7,CX
JMP EXIT1
P1: CMP AH,1
JNZ P2
MOV DX,5AH
SUB DX,BX
MOV BX,DX
MOV CX,[BX+SI]
MOV D7,CX
JMP EXIT1
P2: CMP AH,2
JNZ P3
MOV CX,[SI+BX]
MOV D6,1
MOV D7,CX
JMP EXIT1
P3: CMP AH,3
JNZ EXIT1
MOV DX,5AH
SUB DX,BX
MOV BX,DX
MOV CX,[BX+SI]
MOV D6,1
MOV D7,CX
EXIT1: POP CX
POP DI
POP AX
POP DX
POP SI
POP BX
RET
PSIN ENDP
CODE ENDS
END START
|