8086汇编语言程序:从数字输入数组中查找比单个输入数字更大的数字的程序



我不知道我是否清楚,但我需要一个程序来获取我输入的数字,一个输入数字,它需要从给定的数字数组中找到所有大于数字#2的数字。

.model small
.stack 100
.data
sir db 80 dup('$')
m1 db 'Introduceti sirul:$'
m2 db 13,10,'Introduceti un caracter:$'
m2 db 13,10,'Cel mai mare caracter este: $'
max db 0,'$'
.code
mov ax,@data
mov ds,ax
mov ah,9h
mov dx,offset m1
int 21h
mov bx,0
mov cx,80
mov ah,3fh
mov dx,offset sir
int 21h
mov ah,9h
mov dx,offset m2
int 21h
mov ah,1
int 21h
mov si,offset sir
mov ah,[si]
next: mov al,[si]
cmp al,13 
jz sfarsit
cmp al,ah 
jle nu
mov ah,al
nu: inc si
jmp next
sfarsit:
mov bl,ah 
mov ah,9
mov dx,offset m2
int 21h
mov dl,bl
mov ah,2
int 21h
mov ah,4ch
int 21h
end 

目前,您的程序只是在 sir 的输入数组中找到最大的数字,也就是 ASCII(字符代码)。您根本不使用单独的输入!首先存储此输入:

    mov     ah, 01h    ; DOS.InputCharacter
    int     21h
    mov     char, al

然后在数组中查找更大的内容。每个较大的项目都会立即显示。

    mov     si, offset sir
next:
    mov     dl, [si]
    cmp     dl, 13 
    je      sfarsit
    cmp     dl, char
    jbe     nu         ; Ignore if not bigger
    mov     ah, 02h    ; DOS.DisplayCharacter
    int     21h
nu:
    inc     si
    jmp     next
sfarsit:

请注意,数组元素实际上是字符,您应该将它们视为无符号数量。因此,不要使用用于有符号比较的jle,而是使用用于无符号比较的jbe

您将不得不重新考虑何时输出第三条消息。

您是否看到您的第 2 条和第 3 条消息都标记为 m2?汇编程序将拒绝此操作。

相关内容

最新更新