Where do you start with MASM32 in 32 bit Windows ?

Started by hutch--, January 01, 2005, 02:09:12 AM

Previous topic - Next topic

hutch--

Conceptually an assembler is a different tool to a compiler in that it has no built in runtime libraries that are normal in most compilers. Even a low level compiler like a C compiler has a minimum of runtime library built into it so it can perform the most basic functions but MASM has nothing at all. By itself it can produce assembler mnemonics and then convert them into binary code in the form of an object module.

This is by no means a disadvantage in that MASM is more than capable of using a runtime library, its just that you have the choice of which one you use to start with which makes it far more flexible than a compiler. When writing code for an operating system like Windows it is conceptually different to code from an earlier OS like MS-DOS where you had to do the most menial tasks yourself. Windows already comes with a massive range of capacities that are encapsulated in what is called the Application Programmer's Interface or commonly the API functions.

From its earlier version onwards, Windows is constructed from a massive collection of internal functions and these functions are readily available to programmers as well. In normal programming terms for 32 bit Windows, the MASM programmers has the API functions, any static libraries that are written in the correct format and the very powerful macro system that MASM has available as well as any code they write themselves.

The MASM32 Project has a static library of its own as well as a collection of macros that in conjunction with the libraries give the programmer starting on MASM a runtime library to help them to get up and going without all of the basic housekeeping needed if you started with only the bare assembler. Some of these are designed specifically to make entry level assembler programming a lot easier in that they will handle the basic data input and output at the console.

The purpose of this capacity is so the entry level programmer has similar capacities available to a compiler so that they can do the basic things easily and concentrate on learning the instructions and coding design rather than starting behind the 8 ball and having to create complicated modules and macros just to get going. This may sound strange but look at it in context, if you were learning to code in a C compiler, you don't start with compiler design and minimum runtime library constructions, you start by using the language and learning the systems and structure that make it work.

To get off the ground with MASM, you can use the MASM32 static library as your own runtime library and start learning the basic instructions and the fundamental procedure model to make your own re-usable code. here is the starting tutorial in MASM32 for simple console based applications. The code at the start before the "start" label is how you dial up your own runtime library.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

;                 Build this with the "Project" menu using
;                       "Console Assemble and Link"

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .486                                    ; create 32 bit code
    .model flat, stdcall                    ; 32 bit memory model
    option casemap :none                    ; case sensitive

    include \masm32\include\windows.inc     ; always first
    include \masm32\macros\macros.asm       ; MASM support macros

  ; -----------------------------------------------------------------
  ; include files that have MASM format prototypes for function calls
  ; -----------------------------------------------------------------
    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

  ; ------------------------------------------------
  ; Library files that have definitions for function
  ; exports and tested reliable prebuilt code.
  ; ------------------------------------------------
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

    .code                       ; Tell MASM where the code starts

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

start:                          ; The CODE entry point to the program

    print chr$("Hey, this actually works.",13,10)
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start                       ; Tell MASM where the program ends
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php