汇编语言-计算立方值

1. 题目:计算给定数字的立方值

2. 要求:从键盘输入0至9中任一自然数x,求其立方值。若输入的字符不是0至9之间的数字,则显示错误信息,并要求重新输入。要求有信息提示输入数字、显示计算结果和提示输入错误。

提示:用户输入字符首先判断是否是0至9之间的字符,如果是,则转换为整数并计算其立方值,然后显示结果;如果不是,则显示输入错误信息并等待用户重新输入

训练目的:掌握简单的循环结构,分支结构。

汇编语言-计算立方值
 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         promot1  BYTE "Enter a number from 0 to 9 to",cr,Lf
19                  BYTE "calculate it‘s cubic number",cr,Lf,0
20         promot2  BYTE "The number ",0
21         
22         value    BYTE 11 DUP(?)
23         warning  BYTE "The number is wrong,please enter a new number"
24                  BYTE cr,Lf
25                  BYTE "from 0 to 9",cr,Lf,0
26         answer   BYTE "The number cubic number is"
27         cubicnm  BYTE 11 DUP(?)
28                  BYTE cr,Lf,0
29 .CODE
30 _start:
31         output   promot1
32         output   promot2
33         input    value,11
34         atod     value
35         doWhiCmp:
36                  cmp eax,0
37                  jl  endWhiCmp  ;eax < 0 
38                  cmp eax,9
39                  jg  endWhiCmp  ;eax > 9
40                  
41                  jmp doRight    ;0<=eax<=9
42                  
43          
44         endWhiCmp:              ;deal the wrong number,to enter new number
45                  output warning 
46                  input  value,11
47                  atod   value
48                  jmp    doWhiCmp
49                  
50         doRight:
51                  mov    ebx,eax
52                  mul    ebx       ;eax = eax * eax
53                  mul    ebx       ;eax = eax * eax *eax  
54                  
55                  dtoa   cubicnm,eax
56                  output answer
57         
58               INVOKE  ExitProcess, 0  ; exit with return code 0
59 
60 PUBLIC _start                   ; make entry point public
61 
62 END                             ; end of source code
汇编语言-计算立方值

 

 

汇编语言-计算立方值,布布扣,bubuko.com

汇编语言-计算立方值

上一篇:Java 模板方法模式的实现


下一篇:Spring事务配置的五种方式