0

So I have 3 numbers and I have to find the smallest one. Here is what I got:

.data
a: .long 4
b: .long 3
c: .long 2
min: .space 4
tc: .asciz "c is min\n"
tb: .asciz "b is min\n"
ta: .asciz "c is min\n"

.text

.global main

main:

mov a, %eax

cmp b, %eax

jle etc

cmp %eax, c

jle eta

etc:
mov b, %ebx
mov c, %ecx
cmp %ecx, %ebx
jle etminc
mov %ebx, min
mov $4, %eax
mov $1, %ebx
mov $tb, %ecx
mov $9, %edx

int $0x80

eta:
mov %eax, min
mov $4, %eax
mov $1, %ebx
mov $ta, %ecx
mov $9, %edx
int $0x80


etminc:
mov %ecx, min
mov $4, %eax
mov $1, %ebx
mov $tc, %ecx
mov $9, %edx
int $0x80


mov $1, %eax
mov $0, %ebx
int $0x80

The terminal showed:

c is min
c is min

for a=4, b=3 and c=2

And :


b is min
c is min
c is min

for a=1, b=3 and c=2

I tried to compare them one by one and show the "a/b/c is min" for the correct chase, but I don't know where I am wrong.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

0 Answers0