The MASM Forum

General => The Campus => Topic started by: RAFAAJ2000 on January 13, 2013, 08:54:05 PM

Title: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 13, 2013, 08:54:05 PM
Hi all,

I am completly new to MASM32 &  I am trying to learn from scratch.

I downloaded MASM32 from the Masm32 website and installed it on my computer. The installation was done sucessfully (This was confirmed by the success messages I got at the end of the intallation process)

I started the Masm32 Editor and copied into it the code below from the net . ... I only edited the 4 include lines to reflect the correct paths to the incs and libs on my computer.

Then I saved the file under the name of  MyTest.asm in the Bin folder and then I went to Project - Build All . ( I got no error messages at all ) and a new MyTest.exe was created in the Bin folder.

Now when I dblclick the MyTest.exe nothing happens . No msgbox is displayed - No errors either !!!!

Why is the exe not working ? Am I doing anything wrong ? Any help with this much appreciated.

I have Win XP SP3

.386
.model flat, stdcall
option casemap :none

include E:\masm32\include\msvcrt.inc
include E:\masm32\include\kernel32.inc

includelib E:\masm32\lib\kernel32.lib
includelib E:\masm32\lib\msvcrt.lib

.data
    Phrase db "Hello !",10
    Taille dd 8

.code
start:
    mov eax, Taille
    push eax
    push offset Phrase
    push 1
    call crt__write

    push 0
    call ExitProcess
end start
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: Vortex on January 13, 2013, 09:16:53 PM
Hi RAFAAJ2000,

Your code will not display a message box as it's intended to write a string named Phrase.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: jj2007 on January 13, 2013, 09:23:00 PM
Hi,

Vortex already wrote that your code (which is working perfectly) prints a string to the console. Therefore,
a) you need to use Console build all
b) you must run the exe from a DOS prompt because in qEditor the output window closes immediately after showing the Hello.

(you may try RichMasm  (http://www.masm32.com/board/index.php?topic=94.0)- it autodetects console and keeps the output window open)

P.S.: Use \Masm32\.... instead of E:\Masm32\... - thus your code works on the computers of members who do not have their Masm32 installation on drive E:
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: Vortex on January 13, 2013, 09:31:43 PM
Hi RAFAAJ2000,

Here is a message box example for you :

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc

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

.data

message     db 'Messagebox example',0
caption     db 'Bonjour',0

.code

start:

    invoke  MessageBox,0,ADDR message,ADDR caption,MB_OK
         
    invoke  ExitProcess,0

END start
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 13, 2013, 10:11:01 PM
Thanks everyone for answering .... I am still new to this so I still have to learn lots of Syntax and memory layout stuff Registers, Stacks ,Operators,...Pointers etc
The code I posted was mainly to check if MASM32 was installed properly on my PC.

The code from Vortex worked perfectly well.... I'll use it as a starting point for learning how to write ASM.

Can you suggest any good tutorials/websites on asm for beginners .- I have a VB background.

Again thanks for the answers and for the freindly atmosphere :)
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: Vortex on January 13, 2013, 10:35:57 PM
Iczelion's Win32 Assembly Tutorials :

http://win32assembly.programminghorizon.com/tutorials.html

Iczelion's Message box tutorial :

http://win32assembly.programminghorizon.com/tut2.html

Mad wizard's Win32asm basic tutorials :

http://www.madwizard.org/programming/tutorials/
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 13, 2013, 10:42:04 PM
Quote from: Vortex on January 13, 2013, 10:35:57 PM
Iczelion's Win32 Assembly Tutorials :

http://win32assembly.programminghorizon.com/tutorials.html

Iczelion's Message box tutorial :

http://win32assembly.programminghorizon.com/tut2.html

Mad wizard's Win32asm basic tutorials :

http://www.madwizard.org/programming/tutorials/

Thanks very much .... looks good .
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: jj2007 on January 14, 2013, 12:04:08 AM
Quote from: RAFAAJ2000 on January 13, 2013, 10:11:01 PM
Can you suggest any good tutorials/websites on asm for beginners .- I have a VB background.

There is some pretty condensed info in my signature (tips & tricks - see in particular the register preservation rules). What is your motivation to learn assembler? Call fast routines from VB?
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 14, 2013, 12:59:24 AM
Zapped !  :P
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: qWord on January 14, 2013, 01:37:59 AM
Quote from: RAFAAJ2000 on January 14, 2013, 12:59:24 AMThe main reason I want to learn assembler is to be able to safely subclass and hook VB and Office Applications/VBA without the crashings ...and to learn how to inject code in foreign processes
you maybe search for another forum that is contentual closer to your motivation.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: Vortex on January 14, 2013, 06:25:05 AM
Hi RAFAAJ2000,

Supporting Visual Basic with assembly is a nice idea but you should read the forum rules before referring to some ideas \ projects belonging to the dark side of the Force.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: jj2007 on January 14, 2013, 09:19:04 AM
Quote from: RAFAAJ2000 on January 14, 2013, 12:59:24 AM... safely subclass and hook VB and Office Applications/VBA without the crashings ...and to learn how to inject code in foreign processes ...

Hi Rafaaj2000,

As qWord and Vortex already mentioned, what you are up to looks suspicious and is a violation of the forum rules. On the other hand, you may have a valid and legal interest in calling assembly from VB. Could you elaborate what exactly you want to achieve, and why you want to inject code in a foreign process?

Thanks, JJ
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: hutch-- on January 14, 2013, 06:01:02 PM
OK, we have allowed it to continue but make sure there is no illegal content or it dies forever.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 14, 2013, 08:05:05 PM
Quote from: hutch-- on January 14, 2013, 06:01:02 PM
OK, we have allowed it to continue but make sure there is no illegal content or it dies forever.

Thanks very much hutch and sorry for the inconvinience.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 14, 2013, 08:24:03 PM
Quote from: jj2007 on January 14, 2013, 09:19:04 AM
Quote from: RAFAAJ2000 on January 14, 2013, 12:59:24 AM... safely subclass and hook VB and Office Applications/VBA without the crashings ...and to learn how to inject code in foreign processes ...

Hi Rafaaj2000,

As qWord and Vortex already mentioned, what you are up to looks suspicious and is a violation of the forum rules. On the other hand, you may have a valid and legal interest in calling assembly from VB. Could you elaborate what exactly you want to achieve, and why you want to inject code in a foreign process?

Thanks, JJ

Hi JJ,

It is not so much injecting code that i wanted as it was to be able to safely Subclass and Hook VB and VBA applications ( ie: w/o the IDE crashings)

I know that one can safely subclass in VB by using a seperate ActiveX dll file which I have done it myself but that is cumbersome and badly affects code portability ..... This is particularly true for VBA/Office applications which don't use resource files. -  Also, a dll must first be registered which can be problematic for lots of users hence the elegant idea to have a valid COM-compatible object created in memory dynamically from shellcode stored in a VB String variable..... - No malicious intentions here.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: jj2007 on January 14, 2013, 08:41:00 PM
Rafaaj,
See my reply in the other thread. I suggest to limit replies from now on to this thread, in order to avoid confusion.
Is the VB 2010 Express edition (http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express) ok for testing? The 2012 edition looks too fat for my taste.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 14, 2013, 08:51:33 PM
Thanks JJ but I use classic VB6 and VBA/Office which is very different language from VB.Net .... And yes , you are right. I'll now close the discussion in this thread to avoid confusion.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: jj2007 on January 14, 2013, 08:55:58 PM
Quote from: RAFAAJ2000 on January 14, 2013, 08:51:33 PM
VBA/Office

Be more precise, please. Is that the one that ships with WinWord? If yes, which version? Word 2003??
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 14, 2013, 08:57:56 PM
Quote from: jj2007 on January 14, 2013, 08:55:58 PM
Quote from: RAFAAJ2000 on January 14, 2013, 08:51:33 PM
VBA/Office

Be more precise, please. Is that the one that ships with WinWord? If yes, which version? Word 2003??

Office 2007 / Excel 2007
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: jj2007 on January 14, 2013, 10:28:02 PM
OK. I just tested this with WinWord 2010 - it works fine with WinWord 2003, too, so 2007 should be fine.

- Install the MasmBasic library (http://www.masm32.com/board/index.php?topic=94.0), i.e. unzip with "use folder names" to the root of your Masm32 drive
- see if \Masm32\MasmBasic\MB2VB\MasmBasicInsertStruct.bas is present
- press Alt F11 in WinWord
- right-click on Normal in the Project - Normal window
- Import file, \Masm32\MasmBasic\MB2VB\MasmBasicInsertStruct.bas
- switch to an empty document in WinWord
- type RECT
- select it
- go back to VB window
- set the cursor inside the third macro, InsertStruct
- press F5
- back to WinWord
Does it work?
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 14, 2013, 11:03:37 PM
Quote from: jj2007 on January 14, 2013, 10:28:02 PM
OK. I just tested this with WinWord 2010 - it works fine with WinWord 2003, too, so 2007 should be fine.

- Install the MasmBasic library (http://www.masm32.com/board/index.php?topic=94.0), i.e. unzip with "use folder names" to the root of your Masm32 drive
- see if \Masm32\MasmBasic\MB2VB\MasmBasicInsertStruct.bas is present
- press Alt F11 in WinWord
- right-click on Normal in the Project - Normal window
- Import file, \Masm32\MasmBasic\MB2VB\MasmBasicInsertStruct.bas
- switch to an empty document in WinWord
- type RECT
- select it
- go back to VB window
- set the cursor inside the third macro, InsertStruct
- press F5
- back to WinWord
Does it work?

Thanks for all your help and patience .  I need to log out now .... I"ll try your suggestions later and post back.

Regards.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: RAFAAJ2000 on January 15, 2013, 04:56:36 PM
Quote from: jj2007 on January 14, 2013, 10:28:02 PM
OK. I just tested this with WinWord 2010 - it works fine with WinWord 2003, too, so 2007 should be fine.

- Install the MasmBasic library (http://www.masm32.com/board/index.php?topic=94.0), i.e. unzip with "use folder names" to the root of your Masm32 drive
- see if \Masm32\MasmBasic\MB2VB\MasmBasicInsertStruct.bas is present
- press Alt F11 in WinWord
- right-click on Normal in the Project - Normal window
- Import file, \Masm32\MasmBasic\MB2VB\MasmBasicInsertStruct.bas
- switch to an empty document in WinWord
- type RECT
- select it
- go back to VB window
- set the cursor inside the third macro, InsertStruct
- press F5
- back to WinWord
Does it work?

The zip is not working - Tried to unzip it with WinRar and the Error I get is : The archive is either in unknown format or damaged
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: jj2007 on January 15, 2013, 05:21:34 PM
Quote from: RAFAAJ2000 on January 15, 2013, 04:56:36 PM
The zip is not working - Tried to unzip it with WinRar and the Error I get is : The archive is either in unknown format or damaged

Your download is not working. I just downloaded the zip, it opens and tests fine in WinZip, 7-Zip and one more archiver. The file should be 492kByte.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: Vortex on January 16, 2013, 05:47:57 AM
Hi RAFAAJ2000,

There is no any problem with the file MasmBasic02Jan2013b.zip  I downloaded it successfully.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: jj2007 on January 16, 2013, 06:44:05 AM
Thanks, Erol :biggrin:
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: Vortex on January 17, 2013, 06:18:56 AM
Maybe posting the MD5 values of ( large sized ) attachments to the forum can help members to detect incomplete \ incorrect downloads.
Title: Re: Why is this simple Hello world MASM Program not working ? !!!
Post by: Gunther on January 17, 2013, 07:44:22 AM
Jochen,

my download of the file works well, too. Unzipping wasn't a problem at all.

Gunther