I'm new to the assembly world, and I want to find the max and min of 3 numbers with the assembly language using Easy68k but the program does not work and I can't find out why, any help would be appreciated.
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
Thanks for helping.
I'd do it like this:
;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
It is just a simple bubble sort for 3 numbers in registers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.