• 汇编语言-求毕达哥拉斯三角形的边


    1. 题目:给定一条最长边,求所有可能的毕达哥拉斯三角形。

    2. 实验要求:一个毕达哥拉斯三角形的三条边是由三个正整数A、B和C组成,从而A2+B2=C2。例如,数字3、4、5,由于9+16=25,而形成一个毕达哥拉斯三角形。写一段完整的汇编程序,实现输入一个值给C,然后显示值为C时,所有可能的毕达哥拉斯三角形。例如,如果输入5作为C的值,那么输出可以是:

    A              B              C

    3                    4                   5

    4                    3                   5

    3. 提示:由于C边的值已经给定,建立一个双重循环,外循环将A初值设1,每次循环加1,直到等于C-1;内循环将B值设为1,每次循环加1,直到等于C-1。在内循环中如果A2+B2=C2成立,则当前的A、B、C是一个毕达哥拉斯三角形的边,并显示,如果不成立,继续循环。

     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      promot BYTE "Please Enter a number as the max slide ",0
    19      value  BYTE 40 DUP(?)
    20      nc     DWORD ?
    21      na     DWORD ?
    22      nb     DWORD ?
    23      n      DWORD ?
    24      
    25      answer  BYTE "         A         B         C ",0
    26      crLf    BYTE cr,Lf,0
    27      
    28 
    29 .CODE                           ; start of main program code
    30 _start:
    31         mov    ebx,0
    32         mov    ecx,0
    33         
    34         output promot
    35         input  value,40
    36         atod   value
    37         
    38         mov nc,eax
    39         mov n, eax
    40         
    41         mul nc
    42         mov nc,eax ;C*C
    43         output answer
    44         output crLf
    45         doFirstWhile:
    46              inc ebx
    47              mov ecx,0
    48              cmp ebx,n
    49              jge endFirstWhile  ;大于等于n则转移
    50              
    51              mov eax,ebx
    52              mul ebx
    53              mov na,eax       ;A*A
    54              doSecondWhile:
    55                 inc ecx
    56                 cmp ecx,n       
    57                 jge endSecondWhile ;大于等于n则转移
    58                 ;执行比较
    59         
    60                 mov eax,ecx
    61                 mul ecx         ;B*B
    62                 mov nb,eax
    63                 mov edx,nb
    64                
    65                 add edx,na        ;A*A+B*B
    66                 
    67                 cmp edx,nc
    68                 jne  stanIf        ;不等于则转移
    69                
    70                 ;output answer
    71                 dtoa value,ebx
    72                 output value
    73                 
    74                 dtoa value,ecx
    75                 output value
    76                 
    77                 dtoa value,n 
    78                 output value
    79                 output crLf
    80                 
    81                 jmp doSecondWhile
    82              stanIf:
    83                 jmp doSecondWhile
    84              endSecondWhile:
    85                 jmp doFirstWhile
    86                 
    87         endFirstWhile:
    88        
    89        INVOKE  ExitProcess, 0  ; exit with return code 0
    90 
    91 PUBLIC _start                   ; make entry point public
    92 
    93 END                             ; end of source code
  • 相关阅读:
    Vue.js中学习使用Vuex详解
    vuex存储和本地存储(localstorage、sessionstorage)的区别
    Java 编译与反编译
    Vue导航守卫beforeRouteEnter,beforeRouteUpdate,beforeRouteLeave详解
    Vue生命周期简介和钩子函数
    微信开发----被动回复用户消息
    C#4.0 System.Dynamic
    Mvc5 控制器,视图简单说明
    JQuery 禁用后退按钮
    防止用户多次点击
  • 原文地址:https://www.cnblogs.com/Forever-Kenlen-Ja/p/3734439.html
Copyright © 2020-2023  润新知