Hello, people.
I am learning Assembly for IA-32 with MASM, using Microsoft Visual C++ Express Edition, and this difficulty came up. When I do this:
INCLUDE Irvine32.inc
QUANT = 47
.data
fibonacciVetor DWORD 1, 1, (QUANT - 2) DUP(0)
fileName BYTE "vetor.txt", 0
fileHandler DWORD 0
.code
main PROC
mov esi, 0
mov ecx, QUANT
L1: mov eax, fibonacciVetor[esi * TYPE fibonacciVetor]
add eax, fibonacciVetor[esi * TYPE fibonacciVetor + 4]
mov fibonacciVetor[esi * TYPE fibonacciVetor + 8], eax
inc esi
loop L1
mov edx, OFFSET fileName
call CreateOutputFile
mov fileHandler, eax
mov edx, OFFSET fibonacciVetor
mov ecx, QUANT * TYPE fibonacciVetor
call WriteToFile
mov eax, fileHandler
call CloseFile
exit
main ENDP
END main
This program does not run correctly, because the fileName string is erased in the middle of the process. The Irvine32.inc library can be found in Kip Irvine's website. I'm using it because the textbook my professor is using is "Assembly Language for Intel-based Computers", 5th Edition by Kip Irvine. When I change the variables declaration for this:
fileName BYTE "vetor.txt", 0
fibonacciVetor DWORD 1, 1, (QUANT - 2) DUP(0)
fileHandler DWORD 0
The program runs correctly.
Why is it that simply changing the order of the declaration has influence in how the program runs or does not, since the fileName variable should be allocated right after the end of the fibonacciVetor and should not be affected when I write to the array?
Thank you very much.