Easy68K 3 число найти мин, не более - PullRequest
0 голосов
/ 07 ноября 2019

Я новичок в мире ассемблера, и я хочу найти max и min из 3 чисел на языке ассемблера, используя Easy68k, но программа не работает, и я не могу понять, почему, любая помощь будет признательна.

Вот код

    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

Спасибо за помощь.

1 Ответ

1 голос
/ 08 ноября 2019

Я бы сделал это так:

;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 числам в регистрах.

...