繁体   English   中英

Easy68K 3 数字查找最小值,最大值

[英]Easy68K 3 number find min,max

我是汇编世界的新手,我想用 Easy68k 的汇编语言找到 3 个数字的最大值和最小值,但程序不起作用,我不知道为什么,任何帮助将不胜感激。

这是代码

    ORG    $1000

l1     add.b #1,d5    * l1 to let the user enter 3 number's then find max and mincounter
       move.b #4,d0
       trap #15
       move.b d1,d2
       cmp   d6,d2
       bgt    max
       move.b  d6,d4     * d2 < d6 ,,, d4 to save the min value
       cmp  #3,d5
       bne  l1
       bra     end   


smax  move.b d2,d3       *d2 > d6 ,,, d3 for the max value
      rts             
max    bsr smax          * to go to the subrotine smax to find the max
       bne l1
end    rts       

START:
       clr.l d2
       clr.l d3
       move.b #0,d5
       move.l #0,d6
       lea msg,A1
       move.b #18,d1
       trap #15
       bsr l1

       lea msg1,a1
       move.b #10,d1
       move.b #1,d0
       trap #15 
       move.b d3,d1    * d3 to save the max in it
       move.b #3,d0
       trap #15


       lea msg3,a1
       move.b #20,d1
       move.b #0,d0
       trap #15

       lea  msg2,a1
       move.b #10,d1
       move.b #1,d0
       trap #15

       move.b d4,d1     * d4 to save the min in it
       move.b #3,d0
       trap #15


msg   dc.b   'enter 3 numbers : '
msg1  dc.b   'the max : '
msg2  dc.b   'the min : '
msg3  dc.b   '                    '
    END    START        ; last line of source

感谢您的帮助。

我会这样做:

;d0,d1,d2 hold numbers in any order
 cmp.l d1,d2
 bge.s .1
 exg   d1,d2
.1
 cmp.l d0,d1
 bge.s .2
 exg   d0,d1
.2
 cmp.l d1,d2
 bge.s .3
 exg   d1,d2
.3
;now d0 has min and d2 max of the numbers

这只是寄存器中 3 个数字的简单冒泡排序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM