汇编语言-求分段函数值
计算函数值
- 题目:计算给定函数值
- 要求:编制程序,计算下面函数值
其中,从键盘输入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/output 11 12 cr EQU 0dh ; carriage return character 13 Lf EQU 0ah ; line feed 14 15 .STACK 4096 ; reserve 4096-byte stack 16 17 .DATA 18 promotX BYTE "Please enter a number as X ",0 19 promotY BYTE "Please enter a number as Y ",0 20 value BYTE 11 DUP(?) 21 answer BYTE "The a is" 22 rsa BYTE 11 DUP(?) 23 BYTE cr,Lf,0 24 .CODE 25 _start: 26 output promotX ;ebx = x 27 input value,11 28 atod value 29 mov ebx,eax 30 31 output promotY ;eax = y 32 input value,11 33 atod value 34 35 cmp ebx,0 36 jl lzero ;ebx < 0 37 38 cmp ebx,0 39 jg oo ;x>0 40 oo: 41 cmp eax,0 42 jl oneg ;y<0 43 cmp eax,0 ;ebx>=0 44 jge ltwozero ;eax>=0 45 lzero: 46 cmp eax,0 47 jl ltwzero ;eax < 0 48 oneg: 49 mov eax,0 50 dtoa rsa,eax 51 output answer 52 jmp endCMP 53 ltwzero: 54 mov eax,1 55 neg eax 56 dtoa rsa,eax 57 output answer 58 jmp endCMP 59 ltwozero: 60 mov eax,1 61 dtoa rsa,eax 62 output answer 63 endCMP: 64 65 INVOKE ExitProcess, 0 ; exit with return code 0 66 67 PUBLIC _start ; make entry point public 68 69 END ; end of source code
测试结果
书到用时方恨少,是非经过不知难。
博观而约取,厚积而薄发。@karllen 每天进步一点点。