Is there a way to use the contents of a variable, (containing an address),
to access the contents pointed to by the address,
without transferring the address to a register ?
mov lparr, offset arr
add lparr, 7
...
mov byte ptr [lparr], 0 ;
versus
mov esi, lparr
mov byte ptr [esi], 0 ; this works
Also what other syntax/addressing modes can be used to change the string length.
.586
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
arr db "123456789ABCDEF0" ; string of 16 chars
db 48 dup 0
lparr dd 0
.code
start:
lea eax, arr
mov lparr, eax
mov lparr, offset arr ; equivalent to preceding instructions
mov esi, 2
mov byte ptr [arr+esi*4+2], 0 ; make string 10 chars long
mov esi, 9
mov byte ptr [arr+esi], 0 ; make string 9 chars long
mov esi, 8
mov byte ptr arr[esi], 0 ; make string 8 spaces long
add lparr, 7
mov esi, lparr
mov byte ptr [esi], 0 ; make string 7 spaces long
; Following doesn't work as commented.
dec lparr
mov byte ptr [lparr], 0 ; make string 6 spaces long
invoke ExitProcess, NULL
end start
I think this does what you want. You can add to the array offset with either an immediate or a register.
.586
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\msvcrt.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\msvcrt.lib
include \masm32\macros\macros.asm
.data
arr db "123456789ABCDEF0" ; string of 16 chars
db 48 dup (0)
;; lparr dd arr
.code
start:
mov BYTE PTR [arr+14], 0
print str$(len(OFFSET arr)),13,10
mov BYTE PTR [arr+10], 0
print str$(len(OFFSET arr)),13,10
mov eax, 6
mov BYTE PTR [arr+eax], 0
print str$(len(OFFSET arr)),13,10
inkey
invoke ExitProcess, NULL
end start