News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Access violation writing location 0xFFFFFFFA.

Started by Xycron, December 29, 2012, 06:35:01 PM

Previous topic - Next topic

Xycron

QuoteUnhandled exception at 0x008B101A in Project1.exe: 0xC0000005: Access violation writing location 0xFFFFFFFA.

I'm trying to declare a variable and I get this error. I'm not sure what I'm doing wrong here, as when I look it up, it appears this is how to declare them. I have tried to make the program as simple as possible. Here is the example:
Quote
.486
.MODEL FLAT
.code
main PROC
   m dword 0
main ENDP

END main

What am i doing wrong on m dword 0?

Xycron

I believe i figured this out, it has to be declared in .data? or is there a way of declaring in .code?

Thanks.

MichaelW

Your code is trying to execute m as an instruction. If a piece of data must be in the code segment then it must be outside the execution path. One common way of doing this is to add a jump instruction that jumps over the data.

    jmp @F
    m dword 0
  @@:

Well Microsoft, here's another nice mess you've gotten us into.

Farabi

If you want to make m as a variable, use local m:dword
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

jj2007

As Farabi wrote, local variables are one way to do it:

.486
.MODEL FLAT
.data?
MyGlobalNonInitializedVar DWORD ?
.data
MyGlobalVar DWORD 123

.code
main PROC
LOCAL m:DWORD
  ret
main ENDP
END main

Note that
- global variables in .data? are zeroed at program start
- global variables in .data carry the value you assigned
- local variables may contain garbage (they are just stack space), and need to be explicitly set to zero if needed

There are many good simple examples in \Masm32\examples, too.

Xycron

Thanks! i dont have a reason to do it one way or the other yet, but it's nice to know it's an option going forward as I get past the very basics in the future.

dedndave

main PROC
   m dword 0
main ENDP

END main


the END directive tells the assembler where to begin execution
in this case, that is the beginning of the proc named "main"

you can put data in the code section, but it is generally prefered to use the data or data? section
main PROC
   invoke ExitProcess,0
main ENDP
   m dword 0
END main

   m dword 0

main PROC
   invoke ExitProcess,0
main ENDP

END main


data you place in the code section cannot be written to without taking extra steps
the default attribute of the code section is READ_EXECUTE
meaning you can read data or execute code in that section, but not write