0
votes

So I have a procedure here that should print an array initialized with "~". Since I want a 12x12 game board I use modular division on 144 by 12 and print a new line when the remainder is 0. I definitely have a problem somewhere though, my first hint is that it just crashes the second it goes to print the board.

displayBoard PROC
lea esi, dArray
mov eax, 144

.while eax > 0
    xor edx, edx
    mov ecx, 12
    div ecx
    .if edx == 0
        print 0DH, 0AH
    .endif
    print esi
    sub eax, 1
.endw

mov eax, input()

displayBoard ENDP

1

1 Answers

0
votes

The problem is that the div instruction sets both edx and eax - it does this:

eax := edx:eax DIV ecx
edx := edx:eax MOD ecx

So it overwrites the eax register and breaks your loop.


Additionally, eax is a temporary register and the call to print will overwrite it as well. See the ABI document or calling convention for your target platform to see which registers are and which are not preserved across function calls.


Finally, I don't know what print does, but using it both with immediate CR/LF values 0DH, 0AH and esi, a pointer to some array, seems fishy.