[英]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.