News:

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

A first assembly program...

Started by IRONmask, May 30, 2008, 07:07:25 PM

Previous topic - Next topic

IRONmask

Hi there...

             I am completely new to assembly language programming...I am using Visual Studio 2008 Professional and just a while ago learnt to invoke the Microsoft Macro Assembler using Visual Studio 2008 Command Prompt ( it is ML )...

             I have searched for hours by google for a sample helloworld asm program that I can paste to notepad and compile...But I didn't find any correct source that would compile...

             Can anyone here give me the correct source code for a helloworld program to be compiled by the above method???

hutch--

IRONmask,

Probably the easiest way is to download the masm32 project from the masm32 subforum, it has a mounain of example code and substantial library and macro suport so it should be able to get you up and going.

RE: using VS, get the swing of MASM first then you should be able to test with the version of ML.EXE that comes with VS to make sure they do the same things. There are from memory minor diferences but the vast majority of earlier 32 bit code will build with it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

IRONmask

What is the link to masmsubforum and where can I get those source codes???

hutch--

As per the link at the top of the page, www.masm32.com .

In the learning stage the old version of ML will do fine to learn how to make object modules for VS, EXE and DLL files for small specialised targets. The later version you have has support for SSE2 and 3 from memory so once you get up to pace and can successfully compare the tho versions, you should have no problems converting to the later VS version.

A few of our members have posted how to make a masm module/project in VS but I don't personally have the experience ere as I program in the editor that comes with masm32.

Don't be afriad to ask questions in here once you get a setup working as there is a lot of expertise floating around in this forum who help learners where they can.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

- Goto http://www.masm32.com/masmdl.htm
- install the whole package
- look for x:\masm32\qeditor.exe (where x is your installation drive)
- open qeditor
- open in qeditor x:\masm32\examples\exampl10\masm1k\masm1k.asm
- go to Project/BuildAll (not: Console build all)
- once the DosBox has finished, press space and then F5
- select masm1k.exe and press OK

Highly recommended: http://win32assembly.online.fr/tutorials.html

Don't get scared too easily if you see GPF's on your puter. You'll get used to it. I am used to BASIC, started Masm32 a few months ago and have now around 100kBytes of source code.

IRONmask

Thanx jj2007...but can you still give me the source code for a helloworld program which I can write in notepad and use Microsoft Macro Assembler to assemble it???

PBrennick

This is a Windows version of your request using a Message Box.


    .386
    .model  flat, stdcall
    option  casemap:none

    include \GeneSys\include\windows.inc
    include \GeneSys\include\kernel32.inc
    include \GeneSys\include\user32.inc

includelib  \GeneSys\lib\kernel32.lib
includelib  \GeneSys\lib\user32.lib

.data
HelloWorld db  "HelloWorld", 0

.code

start:

    call    WinMain
    invoke  ExitProcess, eax

WinMain proc
;---------------------------------------
invoke  MessageBox, NULL, addr HelloWorld, addr HelloWorld, MB_OK
ret
;---------------------------------------
WinMain endp

    end     start


Paul
The GeneSys Project is available from:
The Repository or My crappy website

GregL

#7
IRONmask,

Here is a "Hello World" console program. You will need the include and library files from the MASM32 package.


.386
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE

INCLUDE \masm32\include\windows.inc
INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib

.DATA

   szHello      BYTE  "Hello World from MASM",13,10,0
   hStdOut      DWORD 0
   dwNumToWrite DWORD 0
   dwNumWritten DWORD 0
   
.CODE

 start:

   INVOKE GetStdHandle, STD_OUTPUT_HANDLE
   mov hStdOut, eax    
   INVOKE lstrlen, ADDR szHello
   mov dwNumToWrite, eax          
   INVOKE WriteFile, hStdOut, ADDR szHello, dwNumToWrite, ADDR dwNumWritten, NULL
   INVOKE ExitProcess, 0

END start


If you insist on not using MASM32, you will need to write your own PROTOs for the Windows API functions and will need to use the .lib files from the Windows SDK.

If you want to use Visual Studio 2008, create an empty Win32 project and add the .asm file to the project. Visual Studio 2008 has Custom Build Rules for MASM. It's still the same situation with the include and library files.

I would recommend you use MASM32 (or GeneSys), it makes things a lot easier.


hutch--

IRONmask,

Quote
Thanx jj2007...but can you still give me the source code for a helloworld program which I can write in notepad and use Microsoft Macro Assembler to assemble it???

You are asking for something that cannot be done, MASM requires at least libraries and preferrably API prototypes so you can use its "invoke" notation. MASM as an assembler comes with NO RUNTIME LIBRARY AT ALL which is norma for an assembler. With the MASM32 project you get a reliable runtime lirary that will get you up to pace quickly whwere if you have to try and learn assembler by having to write your own, the volume of work and the difficult learning curve will defeat you.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: IRONmask on May 31, 2008, 08:24:33 PM
Thanx jj2007...but can you still give me the source code for a helloworld program which I can write in notepad and use Microsoft Macro Assembler to assemble it???

As you have read already, I hope, you MUST install the whole Masm32 package (step 2 of my list above).
Once you are done, save these two pieces to some folder:

A)  save as HelloWorld.asm:
include \masm32\include\masm32rt.inc

.data
AppName  db "Hello World!", 0
MyText db "This is a simple text, change it if you like", 0

.code

start:   invoke MessageBox, NULL, addr MyText, addr AppName, MB_OK
  exit
end start


B) Save as HelloWorld.bat:
\masm32\bin\ml /c /coff HelloWorld.asm
\masm32\bin\Link /SUBSYSTEM:WINDOWS /OPT:NOREF HelloWorld.obj
HelloWorld.exe


So, once you saved these files, go to this folder and double-click on HelloWorld.bat
Alternatively, you can right-click on HelloWorld.bat, and then click on "Open" on top of the list.

If all that fails, try unzipping the attached archive, and double-click on HelloWorld.bat

[attachment deleted by admin]

IRONmask

thanks a lot guys...I think I will use the MASM32 package....