2011-11-09 2 views
0

미리 정의 된 배열에서 가장 큰 숫자를 찾아서 화면에 출력하고 싶습니다. 지금 나는 가장 큰 숫자를 찾는 나의 논리가 맞다는 사실을 알고 있지만 결코 끝내지 않는 전쟁과 싸우는 것과 같다.dd 배열을 만들었지 만 아무 것도 출력 할 수 없습니다.

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 
+0

케어 당신이 사용하고있는 플랫폼과 운영체제에 관한 것이 있습니까? 인쇄 출력은 상상할 수있는 플랫폼 별 특징 중 하나입니다. –

+0

@KerrekSB SB 와우 그 재미있는 내가 보편적 인 언어, 내가 리눅스와 어셈블리에 대한 nasm 컴파일러를 사용하여 알았는데 알았어 –

+0

어떻게 보편 수 있을까? 어셈블러 (예 : 부트 로더)에 "알몸"머신 코드를 작성하거나, 호스트 된 프로그램을 작성할 수 있습니다. 호스트 된 환경에서는 모든 세부 사항이 OS에 종속됩니다. 적절한 시스템 호출을하고 싶습니다. 어쨌든 여기서 "Linux"는 중요한 정보입니다. 건배. –

답변

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 
관련 문제