I'm trying to get an example working of vararg...
and in the process of doing so, i just wanted to do something simple and see which value is being added inside the loop, and for some reason instead of outputting '2' the first time through it tries to read at address 00000002... and im not sure what to do
yeah! I know im a newb.. i'm reading through the programmers guides, and this little problem seems to have me stumped.. any input would be great :)
.586
.model flat, stdcall
option casemap:none
include kernel32.inc
include windows.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
.data
StringData2 BYTE 255 DUP(0)
Prompt BYTE "Press enter to quit", 0
addfunc PROTO C, :BYTE, :VARARG
.code
start:
invoke addfunc, 5, 2, 2, 2, 2, 2
invoke StdOut, addr Prompt
invoke StdIn, addr StringData2, LENGTHOF StringData2
invoke ExitProcess, 0
addfunc PROC C, argCount:BYTE, argVal:VARARG
local StringData:DWORD
xor eax, eax
xor esi, esi
.while(argCount > 0)
mov eax, argVal
mov StringData, eax
inc esi
inc esi
inc esi
inc esi
invoke StdOut, StringData ;I want this to print out 2
;but it tries to read at address 2
dec argCount
.endw
Ret
addfunc EndP
end start
Thanks guys.. sorry for such a stupid question.... but it was either ask or yank my hair out :)
and in the process of doing so, i just wanted to do something simple and see which value is being added inside the loop, and for some reason instead of outputting '2' the first time through it tries to read at address 00000002... and im not sure what to do
yeah! I know im a newb.. i'm reading through the programmers guides, and this little problem seems to have me stumped.. any input would be great :)
.586
.model flat, stdcall
option casemap:none
include kernel32.inc
include windows.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
.data
StringData2 BYTE 255 DUP(0)
Prompt BYTE "Press enter to quit", 0
addfunc PROTO C, :BYTE, :VARARG
.code
start:
invoke addfunc, 5, 2, 2, 2, 2, 2
invoke StdOut, addr Prompt
invoke StdIn, addr StringData2, LENGTHOF StringData2
invoke ExitProcess, 0
addfunc PROC C, argCount:BYTE, argVal:VARARG
local StringData:DWORD
xor eax, eax
xor esi, esi
.while(argCount > 0)
mov eax, argVal
mov StringData, eax
inc esi
inc esi
inc esi
inc esi
invoke StdOut, StringData ;I want this to print out 2
;but it tries to read at address 2
dec argCount
.endw
Ret
addfunc EndP
end start
Thanks guys.. sorry for such a stupid question.... but it was either ask or yank my hair out :)
Simple mistake is the source of the problem. Use 'addr' to pass the string buffer.
well, I tried that too.. believe it or not, and I just tried it again right now :)
It just makes little ascii smiley faces on the screen instead of showing the number.. kind of weird, i guess..
any thoughts?
btw.. I saw parts of the bible black anime... nice :P
It just makes little ascii smiley faces on the screen instead of showing the number.. kind of weird, i guess..
any thoughts?
btw.. I saw parts of the bible black anime... nice :P
The problem is that you are passing the dword value "2" to StdOut. This is not BASIC, nor C++ with "cout<<". The function expects an address to a string, which has a value similar to "0410F30" .
.586
.model flat, stdcall
option casemap:none
include \masm32\include\kernel32.inc
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
.data
StringData2 BYTE 255 DUP(0)
Prompt BYTE "Press enter to quit", 0
.code
addfunc PROC C argCount:BYTE, argVal:VARARG
local StringData[260]:byte
lea esi,argVal
.while argCount
push esi
invoke dwtoa,dword ptr[esi],addr StringData
invoke StdOut, addr StringData
pop esi
add esi,4
dec argCount
.endw
ret
addfunc EndP
start:
invoke addfunc, 5, 2, 2, 2, 2, 2
invoke StdOut, addr Prompt
invoke StdIn, addr StringData2, LENGTHOF StringData2
invoke ExitProcess, 0
end start
haha. you are the man :)
Yeah.. im still in the terms of thinking in c/c++ but hopefully that'll change soon. thanks man
Yeah.. im still in the terms of thinking in c/c++ but hopefully that'll change soon. thanks man