Hi,guys!
Here`s two ways to output "12345",that`s all of the string from inside a proc.
How do i output "345",that`s part of the string from inside of the proc? Have tried all kinds of combinations but cant work it out.
lpCL BYTE "12345",0
-----------
MsgBox "%s", addr lpCL+2 ;will output "345",need to do the same from inside of the proc
invoke f,addr lpCL
------------
f PROC dCL:DWORD
MsgBox "%s", dCL ; way 1 to output "12345"
----
mov eax,dCL
MsgBox "%s", eax ; way 2 to output "12345"
---
;how do i get "345"?
ret
f endp
---------------
Thanx.
In the masm32 macro section, search for and examine the 'InString' macro (or just use it). :U
'nuff said,
Paul
you have to deference it first:
mov eax, dCL ; move the address of the address into eax
mov eax, [eax] ; move the pointer into eax
MsgBox "%s", eax
Though it's not very good programming practice, technically you can reference the global variable with no problem from inside the function as well (MsgBox "%s", lpCL+2). Also, be warned, invoke often doesn't play well with arguments in eax, so you might need to a different register
-r
Here are some options.
include \masm32\include\masm32rt.inc
f1 PROTO: DWORD
f2 PROTO: DWORD
.data
lpCL BYTE "12345",0
.code
start:
MsgBox 0, addr lpCL+2, "Outside", MB_OK
invoke f1, addr lpCL
invoke f2, addr lpCL+2 ; addr is the same as...
invoke f1, offset lpCL
invoke f2, offset lpCL+2 ; ... offset for GLOBAL variables
exit
f1 proc dCL:DWORD
mov eax, dCL
add eax, 2
MsgBox 0, eax, "Inside f1", MB_OK
; MsgBox 0, dCL+2, "Inside f2", MB_OK ; would assemble but crashes
ret
f1 endp
f2 proc dCL:DWORD
MsgBox 0, dCL, "Inside f2", MB_OK
ret
f2 endp
end start
Thanx a lot,guys.
This pointer/(de)referencing stuff is pretty confusing for a newbie.
i`m sure u`ve been there :)
Zap,
Dereferencing is a complicated term for a simple task. In Motorola nomenclature we used to refer to that as indirect referencing which is a lot more descriptive of what is actually happening. An Indirect Reference is a reference to a reference.
Paul
:dazzled:
My bad everyone; as was pointed out (pun intended), my code is erroneous and the extra deferencing is not required in this case. Sorry to muddy the waters further
-r