码迷,mamicode.com
首页 > 编程语言 > 详细

汇编语言-求分段函数值

时间:2014-05-19 16:11:03      阅读:426      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   code   c   

 计算函数值

  1. 题目:计算给定函数值
  2. 要求:编制程序,计算下面函数值
    bubuko.com,布布扣

其中,从键盘输入x,y,输出数据为a。

输入输出时候都要求有提示信息。

考查知识点:分支结构的应用。

代码如下:

bubuko.com,布布扣
 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
bubuko.com,布布扣

测试结果

bubuko.com,布布扣

 

 

汇编语言-求分段函数值,布布扣,bubuko.com

汇编语言-求分段函数值

标签:des   style   blog   class   code   c   

原文地址:http://www.cnblogs.com/Forever-Kenlen-Ja/p/3735043.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!