section .bss
digit0: resb 2
digit1: resb 1
answer1 : resb 1
answer2 : resb 1
answer : resw 1
array: resb 50
element: resb 1
num: resb 1
temp: resb 1
largest: resb 1
smallest: resb 1
count: resb 1
section .data
msg1: db "Enter the number of elements : "
size1: equ $-msg1
newline: db 0Ah
msg2 : db "enter a number:"
size2 : equ $-msg2
len2: equ $ - newline
section .text
global _start
_start:
mov byte[count], 0
;Printing the message to enter the number
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, size1
int 80h
mov eax,3
mov ebx,0
mov ecx,digit1
mov edx,1
int 80h
mov eax,3
mov ebx,0
mov ecx,digit0
mov edx,1
int 80h
mov eax,3
mov ebx,0
mov ecx,temp
mov edx,1
int 80h
sub byte[digit1], 30h
sub byte[digit0], 30h
mov al, byte [digit1]
mov bl, 10
mul bl
add al, byte[digit0]
add byte[num], al
mov al, byte[num]
mov byte[temp], al
mov ebp, array
reading:
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, size2
int 80h
mov eax,3
mov ebx,0
mov ecx,digit1
mov edx,1
int 80h
mov eax,3
mov ebx,0
mov ecx,digit0
mov edx,2
int 80h
sub byte[digit1], 30h
sub byte[digit0], 30h
mov al, byte [digit1]
mov bl, 10
mul bl
add al,byte[digit0]
mov byte[ebp], al
add ebp, 1
dec byte[temp]
cmp byte[temp], 0
jg reading
mov ebp, array
mov al,byte[ebp]
mov byte[largest],al
mov byte[smallest],al
add ebp, 1
searching:
mov al, byte[largest]
cmp al, byte[ebp]
jnb if
mov al, byte[smallest]
cmp al, byte[ebp]
jna else
add byte[count], 1
add ebp, 1
mov al, byte[count]
cmp al, byte[num]
jb searching
mov al,byte[largest]
mov bl, 10
div bl
add ah, 30h
add al, 30h
mov byte[answer1], ah
mov byte[answer2], al
mov eax, 4
mov ebx, 1
mov ecx, answer2
mov edx, 1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, answer1
mov edx, 1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, len2
int 80h
mov eax, 1
mov ebx, 0
int 80h
if:
mov al, byte[ebp]
mov byte[largest],al
add byte[count], 1
add ebp, 1
jmp searching
else:
mov al, byte[ebp]
mov byte[smallest], al
add byte[count], 1
add ebp, 1
jmp searching
答案 0 :(得分:0)
mov al,byte[largest]
mov bl, 10
div bl ;PROBLEM IS HERE
add ah, 30h
add al, 30h
在这部分中,您忘记在执行div bl
之前清除AH寄存器。请记住,字节除法使用AX。
movzx ax,byte[largest]
mov bl,10
div bl
add ah,30h
add al,30h