我创建了一个dd数组,但无法输出任何内容

时间:2011-11-09 00:05:37

标签: assembly operating-system x86 bios

我想找到预定义数组中的最大数字并将其输出到屏幕。现在我知道一个事实,我找到最大数字的逻辑是正确的,但输出它就像打一场永无止境的战争!

segment .data


   matrix dd   1,62,3,44,35, \
            61,52,43,45,55, \
            17,23,37,74,65, \
            13,12,93,94,95, \
            31,21,13,14,25 \


segment .bss

holder  resb    4

counter resb    4


segment .text

global _start

_start:

    mov eax, matrix
    call big

big:
    mov esi, holder
    mov edi, counter
    mov edi, 0
    jmp switch

loop:
    inc edi
    cmp esi, [eax + edi]
    jg switch
    cmp edi, 25 
    jle loop
    mov eax, [esi]
    add eax, '0'

    mov eax, 4 ; after some advice from a few forum member i tried the [ebx + ecx *4] but no luck 
    mov ebx, 1 
    mov ecx, eax
    mov edx 
    mov eax, [ebx + ecx * 4]

    int 0x80


switch:
    mov esi, [eax + edi]
    jmp loop


exit:
    mov eax, 1
    xor ebx, ebx
    int 0x80

1 个答案:

答案 0 :(得分:0)

我知道这并没有回答你的问题,但我想你可能想知道如何以更有效的方式找到列表中最大的数字:

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