Hi, I want to convert the following C Code to MASM.
Do I have to declare the variable as a global one, or can I do it on another way?
void test() {
static int i;
i += 2;
}
Depends on whether you need a global or local variable...
.data?
varI dd ? ; varI will be zero at progstart
.data
varI dd 123 ; varI will be 123 at progstart
MyProc
LOCAL varI:DWORD
mov varI, 0 ; varI will be undefined whenever you enter this proc, so you better put a value :wink
Yes, it will need to be global.
MASM doesn't have the same scoping rules as C, so you may want to include the name of the function in the variable name to make clear where it belongs.
Cheers,
Zooba :U
The closest you can get is..
test proc
.data
i DWORD 0
.code
add DWORD PTR [i],2
ret
test endp
So I'd just go for a 'global' - with a slightly more meaningful name than 'i' :wink
You could also use the GLOBAL macro.
test PROC
GLOBAL i DWORD 0
add i, 2
ret
test ENDP