News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Why is this simple Hello world MASM Program not working ? !!!

Started by RAFAAJ2000, January 13, 2013, 08:54:05 PM

Previous topic - Next topic

RAFAAJ2000

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

Vortex

Hi RAFAAJ2000,

Your code will not display a message box as it's intended to write a string named Phrase.

jj2007

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 - 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:

Vortex

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

RAFAAJ2000

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 :)

Vortex

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/

RAFAAJ2000

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 .

jj2007

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?

RAFAAJ2000

Zapped !  :P

qWord

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.
MREAL macros - when you need floating point arithmetic while assembling!

Vortex

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.

jj2007

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

hutch--

OK, we have allowed it to continue but make sure there is no illegal content or it dies forever.

RAFAAJ2000

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.

RAFAAJ2000

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.