计算函数值
- 题目:计算给定函数值
- 要求:编制程序,计算下面函数值
其中,从键盘输入x,y,输出数据为a。
输入输出时候都要求有提示信息。
考查知识点:分支结构的应用。
代码如下:
1 ; Example assembly language program -- 2 ; Author: karllen 3 ; Date: revised 5/2014 4 5 .386 6 .MODEL FLAT 7 8 ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD 9 10 INCLUDE io.h ; header file for input/output11 12 cr EQU 0dh ; carriage return character13 Lf EQU 0ah ; line feed14 15 .STACK 4096 ; reserve 4096-byte stack16 17 .DATA18 promotX BYTE "Please enter a number as X ",019 promotY BYTE "Please enter a number as Y ",020 value BYTE 11 DUP(?)21 answer BYTE "The a is"22 rsa BYTE 11 DUP(?)23 BYTE cr,Lf,024 .CODE25 _start:26 output promotX ;ebx = x27 input value,1128 atod value29 mov ebx,eax30 31 output promotY ;eax = y32 input value,1133 atod value34 35 cmp ebx,036 jl lzero ;ebx < 037 38 cmp ebx,039 jg oo ;x>040 oo: 41 cmp eax,0 42 jl oneg ;y<043 cmp eax,0 ;ebx>=044 jge ltwozero ;eax>=045 lzero:46 cmp eax,047 jl ltwzero ;eax < 0 48 oneg:49 mov eax,050 dtoa rsa,eax51 output answer52 jmp endCMP 53 ltwzero:54 mov eax,155 neg eax56 dtoa rsa,eax57 output answer58 jmp endCMP59 ltwozero:60 mov eax,161 dtoa rsa,eax62 output answer63 endCMP:64 65 INVOKE ExitProcess, 0 ; exit with return code 066 67 PUBLIC _start ; make entry point public68 69 END ; end of source code
测试结果