News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Printing out array

Started by MCpiroman, September 30, 2017, 10:04:53 PM

Previous topic - Next topic

MCpiroman

Given code:

    .486                                   
    .model flat, stdcall                   
    option casemap :none                   

    include \masm32\include\windows.inc     
    include \masm32\macros\macros.asm       
    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
PrintBoard PROTO :DWORD

.data

initBoard  dw 0,0,0, 7,0,0, 0,0,0
            dw 1,0,0, 0,0,0, 0,0,0     
            dw 0,0,0, 4,3,0, 2,0,0             
            dw 0,0,0, 0,0,0, 0,0,6     
            dw 0,0,0, 5,0,9, 0,0,0     
            dw 0,0,0, 0,0,0, 4,1,8
            dw 0,0,0, 0,8,1, 0,0,0
            dw 0,0,2, 0,0,0, 0,5,0
            dw 0,4,0, 0,0,0, 3,0,0
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .code 
                     
start:
    call FindSolutions
    exit

FindSolutions proc

    invoke PrintBoard, initBoard
   
    ret                         
FindSolutions endp

PrintBoard proc iBoard:DWORD

    push ebx
    push ecx

    lea ebx, iBoard
    xor edi, edi
    @@:
        mov edi, [ebx+ecx]
        print str$(edi)
        inc ecx
        cmp ecx, 80
        jne @B

    pop ecx
    pop ebx
   
PrintBoard endp

end start


prints the first number (0) and then crashes. Although if I remove 'print' segment it works fine (at least doesn't crash). Also, when in PrintBoard I add
LOCAL someVar :DWORD
(so it looks:)

..some code

    PrintBoard proc iBoard:DWORD
    LOCAL someVar :DWORD
    push ebx

..some code

it crashes too, even without print instruction.
Any ideas, how to fix this?

jj2007

Maybe a ret before the endp would help?

aw27

There are many errors in your program other than the absence of ret.
ecx becomes corrupted in the loop, you pass a parameter by value and expect to get the original address from it on the called function, initBoard is an array of words but you want to print an array of bytes. Well, may be you should scrap everything and start over.   ::)

mabdelouahab

Quote
FindSolutions proc
    invoke PrintBoard,addr initBoard
    ret                         
FindSolutions endp

PrintBoard proc iBoard:DWORD
    push esi
    push edi   
    mov esi, iBoard
    xor edi, edi
    @@:
        movsx ecx,word ptr  [esi+edi]
        print str$(ecx)
        add edi,2
        cmp edi, 80*2
        jne @B

    pop edi
    pop esi
    ret
PrintBoard endp