I’m just beginning to toy with masm. I don’t understand why this code isn’t working.
.data
MsgBoxCaption db "Iczelion Tutorial No.2",0
MsgBoxText db "Win32 Assembly is Great!",0
savedAddr DWORD ?
.code
start:
mov eax, 10
mov savedAddr, OFFSET MsgBoxText
lab:
inc MsgBoxText
MOV MsgBoxText, 'm'
cmp eax, 0
dec eax
jnz lab
invoke MessageBox, NULL, savedAddr, addr MsgBoxCaption, MB_OK
invoke ExitProcess, NULL
end start
Edit: I expect to see the first 10 characters in MsgBoxText be ‘m’s. Instead, only the first letter is an ‘m’. I assume that inc MsgBoxText increments a pointer.
At first glance it seems like this code should do nothing except change the ‘W’ of Win32 to an ‘a’ and then to a single ‘m’.
You are incrementing the word in memory at
MsgBoxText, the same word, in each loop iteration.To clobber the string using the ‘m’ characters, a better strategy would be to load the address of the string into a register, start storing ‘m’ bytes, and then increment the value in the register, as well as decrementing the counter.
Update: Ok, to answer the question in the comment, change the loop to: