News:

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

Tiny Memory Model confusion

Started by nmn, July 02, 2011, 03:58:43 AM

Previous topic - Next topic

dedndave

if that's the case, then you are in pretty good shape
16-bit code may be viewed as a "fun little exercise"   :P

there are a variety of sources to help you learn assembler
one i like is Randy Hyde's older version of AoA
http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html
it isn't completely up to date, but it provides a lot of the basics you will need

in the masm32 package, the examples, help, and tutorial folders have a lot of great info   :U

nmn

Thanks. I think I'm off to a good start. With a bit of messing around, I got this to compile and run:

.386
.model flat, stdcall
option casemap:none
include    \masm32\include\windows.inc
include    \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include    \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
.data
  Message db "Success.$"
  MsgTitle db "Hello MASM32!$"
.code
  start:
    push NULL
    push offset Message
    push offset MsgTitle
    push MB_OK
    call MessageBoxA
    push 0
    call ExitProcess
  end start

I don't want to drag this thread on, but is this in the right direction?

dedndave

looks good, except your parameters are reverse order   :P

in assembler, we have INC files - similar to H files in C
one that will save you some typing is \masm32\include\masm32rt.inc

also - MASM supports an internal macro called INVOKE
it will push the parms for you and make the call
it also does a little type-checking to see if the parms are dwords, at least
and that you have the correct number of parms...
        INCLUDE \masm32\include\masm32rt.inc

        .DATA

Message  db "Success.",0
MsgTitle db "Hello MASM32!",0

        .CODE

_main   PROC

        INVOKE  MessageBox,NULL,offset Message,offset MsgTitle,MB_OK
        INVOKE  ExitProcess,0

_main   ENDP

        END     _main


MessageBox is an alias for MessageBoxA
most ASCII functions have such aliases to make the code a little easier on the eye
only if you require the unicode equivalent do you need to specify MessageBoxW

nmn

Oh, that's useful. I should be paying more attention, I already saw invoke before. I'll be messing with this today, thanks for all of your help.

dedndave

oh - one more thing....

in win32, strings are often terminated with nulls rather than the old DOS '$'

nmn

Yeah, I did fix that, I just posted old code somehow.