News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Why my program crash?

Started by zhiling0229, March 01, 2007, 07:35:40 AM

Previous topic - Next topic

zhiling0229

Hi,

I was able to compile my program and build the whole asm file. However once i try to run it, it crash immediately. I was wondering why? Can you please point towards my error in my code or something that i should add?

      .386                      ; set processor type
      .model flat, stdcall      ; memory model & calling convention
      option casemap :none      ; case sensitive

      ; --------------------------------
      ; Include any needed INCLUDE files
      ; or procedure prototypes.
      ; --------------------------------
       include \masm32\include\windows.inc
       include \masm32\include\gdi32.inc
       include \masm32\include\user32.inc


      ; ---------------------------------------------------------
      ; Write the prototype for the procedure name below ensuring
      ; that the parameter count & size match and put it in your
      ; library include file.
      ; ---------------------------------------------------------

      ; YourModule PROTO :DWORD,:DWORD etc.....

    .code

      main PROC

   mov   eax,10000h      ; EAX = 10000h
   add   eax,40000h      ; EAX = 50000h
   sub   eax,20000h      ; EAX = 30000h

    main ENDP
    END main

zooba

You need to put a ret instruction or invoke ExitProcess, 0 at the end of your Main procedure. At the moment, the CPU runs your three instructions and then attempts to run whatever comes after (probably nothing).

Cheers,

Zooba :U

dsouza123

#2
Here is an example, with the invoke ExitProcess, 0 at the end.


  .386                   ; set processor type, another option is .686
  .model flat, stdcall   ; memory model & calling convention
  option casemap :none   ; case sensitive

  ; ----------------------------------------------
  ; Include any needed INCLUDE and LIBRARY files
  ; and procedure prototypes.
  ; ----------------------------------------------
  include \masm32\include\windows.inc
  include \masm32\include\user32.inc
  include \masm32\include\kernel32.inc

  includelib \masm32\lib\user32.lib
  includelib \masm32\lib\kernel32.lib

Main PROTO

  ; ---------------------------------------------------
  ; Include any needed global constants and variables
  ; both initialized and uninitialized
  ; ---------------------------------------------------
.const
    con_init equ 255
.data
    var_init dd 0
   
.data?
    var_unin dd ?


.code
start:

  invoke Main
  invoke ExitProcess,0

Main PROC
  mov   eax,10000h      ; EAX = 10000h
  add   eax,40000h      ; EAX = 50000h
  sub   eax,20000h      ; EAX = 30000h
  ret
Main ENDP

end start

[attachment deleted by admin]

Tedd

dsouza: you might want to change that - neither of the last two lines will even be executed. The entry-point is at "start" which then goes on to execute the function, and return (to the os.)


.code
start:

invoke Main
invoke ExitProcess,0


Main PROC
  mov   eax,10000h      ; EAX = 10000h
  add   eax,40000h      ; EAX = 50000h
  sub   eax,20000h      ; EAX = 30000h
  ret
Main ENDP

end start
No snowflake in an avalanche feels responsible.

dsouza123

Thanks Tedd, 

Good catch, I updated the original post and replaced the attachment with the corrected code.