如何在 emu8086 中显示我的代码中的最小值?

how to display the smallest value in my code in emu8086?

我做了一个显示最大的代码,但后来我的老师让我们再做一个输入 3 个数字并显示最小值的代码。

代码如下:

org 100h

    jmp start

    msg1 db 10,13,"Enter first number: $"
    msg2 db 10,13,"Enter second number: $"
    msg3 db 10,13,"Enter third Number: $"

    num1 db ?
    num2 db ?
    num3 db ?

start:

    lea dx, msg1
    mov ah, 9
    int 21h
    mov ah, 1
    int 21h
    mov num1, al 
    lea dx, msg2
    mov ah, 9
    int 21h
    mov ah, 1 
    int 21h
    mov num2, al
    lea dx, msg3
    mov ah, 9
    int 21h
    mov ah, 1
    int 21h
    mov num3, al

    mov bl, num1
    cmp bl, num2
    jng number2 

    cmp bl, num3
    jng number3

    mov ah, 2
    mov dl, num1
    int 21h
    jmp escape 

number2:

    mov bl, num2
    cmp bl, num3
    jng number3

    mov ah, 2
    mov dl, num2
    jmp escape

number3:

    mov ah, 2
    mov dl, num3
    int 21h

escape:
    ret

sample output:

1st no. i enter 3

2nd no, i enter 2

3rd no, i enter 1

and the largest is 3 but the output will be 13 because i don't know how to put space on my code :D...

请帮忙!!! XD 这也是我第一次发布这个...很抱歉我的语法错误。

mov ah, 2
mov dl, num2
jmp escape

在这部分中,您的程序忘记了使用 int 21h 实际调用 DOS。

i don't know how to put space on my code

只需在同一行的输出之间需要一些 space 的地方使用以下内容:

mov ah, 2
mov dl, " "
int 21h

或使用以下方法将项目放在不同的行上:

mov ah, 2
mov dl, 10
int 21h
mov dl, 13
int 21h

更好的解决方案是在输出数字之前显示一条合适的消息:

msg4 db 10,13,"Smallest value: $"
...
lea dx, msg4
mov ah, 9
int 21h

my teacher ask us to make another one that input 3 numbers and display the smallest value.

只需将所有这些 jng(跳转不大于)指令更改为 jnl(跳转不小于)指令。


这是您的代码的稍微好一点的版本,使用 jnl:

 mov bl, num1
 cmp bl, num2
 jnl number2 
 cmp bl, num3
 jnl number3
 mov dl, num1
 jmp Print
number2:
 mov bl, num2
 cmp bl, num3
 jnl number3
 mov dl, num2
 jmp Print
number3:
 mov dl, num3
Print:
 mov ah, 2    
 int 21h
 ret

祝你周一好运!