Я создал массив dd, но ничего не могу вывести - PullRequest
0 голосов
/ 09 ноября 2011

Я бы хотел найти наибольшее число в предопределенном массиве и вывести его на экран.Теперь я точно знаю, что моя логика найти наибольшее число верна, но вывести его - все равно что вести войну, которая никогда не заканчивается

1 Ответ

0 голосов
/ 09 ноября 2011

Я знаю, что это не отвечает на ваш вопрос, но я подумал, что вы, возможно, захотите узнать, как найти наибольшее число в списке более эффективным способом:

mov     esi, matrix       ; esi now points to the beginning of the matrix
xor     ebx, ebx          ; ebx will mold the max
xor     ecx, ecx          ; ecx is the counter

loop:
  cmp   ecx, 25           ; Make sure the end of the matrix has not been reached
  jge   end_loop          ; If the end has been reached, jump out of the loop

  mov   eax, [esi+ecx*4]  ; Read the next DWORD from the matrix
  cmp   ebx, eax          ; Compare it to ebx (the current max)
  jle   skip              ; If it's not greater than the current max, skip it
  mov   ebx, eax          ; Otherwise, update ebx with the new max

  skip:
  add   ecx, 1            ; incriment the counter
jmp     loop              ; Loop to the end of the matrix

end_loop:

; ebx now contains the max value in the 25 number matrix
...