计算分段函数: A,B的值从键盘输入,Y的值送显示器输出(∧表示“并且”,∨表示“或者”)。
正确答案:
INCLUDE YLIB.H
DATA SEGEMNT
MESS1 DB 0DH,0AH,“InputthevalueofAplease:$”
MESS2 DB 0DH,0AH,“InputthevalueofBplease:$”
MESS3 DB 0DH,0AH,“Y=:$”
A DW ?
B DW ?
DATA ENDS
CODES EGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MESS 1
CALL READINT;输入A
MOV A,AX
LEA DX,MESS2
CALL READINT;输入B
MOV B,AX
AND AX,AX
JL L1;B<0,转L1
CMP A,0
JL L1;A<0,转L1
JNZ SKIP1
CMP B,0
JZ L2;A=0&&B=0,转L2
JMP EXIT;A=0&&B≠0,无定义,转EXIT
SKIP1:CMP B,0
JLE EXIT;A≠0&&B=0,无定义,转EXIT
L3:MOV AX,A
SUB AX,B
JMP DISP
L2:MOV AX,2
JMP DISP
L1:MOV AX,A
ADD AX,B
DISP:LEA DX,MESS2
CALL WRITEINT;输出Y的值
CALL CRLF
EXIT:MOV AX,4C00H
INT 21H
CODEENDS
END START
说明:如果把A、B看作是平面直角坐标的两根轴,那么这个函数在A,B的正轴上无定义。无法计算,也无法输出结果。
DATA SEGEMNT
MESS1 DB 0DH,0AH,“InputthevalueofAplease:$”
MESS2 DB 0DH,0AH,“InputthevalueofBplease:$”
MESS3 DB 0DH,0AH,“Y=:$”
A DW ?
B DW ?
DATA ENDS
CODES EGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MESS 1
CALL READINT;输入A
MOV A,AX
LEA DX,MESS2
CALL READINT;输入B
MOV B,AX
AND AX,AX
JL L1;B<0,转L1
CMP A,0
JL L1;A<0,转L1
JNZ SKIP1
CMP B,0
JZ L2;A=0&&B=0,转L2
JMP EXIT;A=0&&B≠0,无定义,转EXIT
SKIP1:CMP B,0
JLE EXIT;A≠0&&B=0,无定义,转EXIT
L3:MOV AX,A
SUB AX,B
JMP DISP
L2:MOV AX,2
JMP DISP
L1:MOV AX,A
ADD AX,B
DISP:LEA DX,MESS2
CALL WRITEINT;输出Y的值
CALL CRLF
EXIT:MOV AX,4C00H
INT 21H
CODEENDS
END START
说明:如果把A、B看作是平面直角坐标的两根轴,那么这个函数在A,B的正轴上无定义。无法计算,也无法输出结果。
答案解析:有
微信扫一扫手机做题