News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Yet Another hello.asm Beginner

Started by bit8bug, January 20, 2013, 09:00:03 PM

Previous topic - Next topic

bit8bug

I looked at the hello.asm file in the tutorial folder , it works but I have the following questions

  • do I need all the includes kernel32, user32... ?
  • If I want to use only print what library should I use ?

  • How to link to C library if I used printf as in :

printf PROTO arg1:Ptr Byte
.data
msg1 byte "Hello World!",0Ah,0
.code
main proc
INVOKE printf, ADDR msg1
ret

Quote
When the assembler encounters the printf, it does not cause an error but
rather leaves space for the address of the instruction to be filled in later by the linker prior
to being loaded into memory for execution.

hutch--

MASM32 actually has a macro to do this and it calls the MSVCRT dll for the function.



; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    ;; __UNICODE__ equ 1

    include \masm32\include\masm32rt.inc

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    printf("this is the MASM32 default version of \qprintf\q\n\n");

    print "print macro",13,10

    printf("It handles numbers using the normal C escapes\n\n");

    printf("%X or %x or %u or %d\n\n",1234,1234,1234,-1234);

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start

Vortex

Hi bit8bug,

Welcome to the forum.

Here is a quick example for you :

.386
.model flat, stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib

printf      PROTO C :DWORD,:VARARG

.data

msg1        db 'Hello world!',0Ah,0

.code

start:

    invoke  printf,ADDR msg1

    invoke  ExitProcess,0

END start


You only need the include files matching the API functions in your source code. For example, ExitProcess is exported by kernel32.dll This means that you need kernel32.inc and kernel32.lib  You can check the include files to see the function prototypes.

bit8bug


Gunther

Hi bit8bug,

welcome to the forum and have a lot of fun.

Gunther
You have to know the facts before you can distort them.

Magnum

Good day bit8bug,

Welcome to a place where you can "chill", bang out some code and vent on occassion.

I think that masm only includes functions that you code uses even if you add includes and libraries that it won't need.

I may be wrong.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

Quote from: Magnum on January 21, 2013, 01:16:10 AM
I think that masm only includes functions that you code uses even if you add includes and libraries that it won't need.

I may be wrong.

No, Andy, you are perfectly right. One with masm32rt.inc covers 99% of all cases:

include \masm32\include\masm32rt.inc

.code
AppName   db "Masm32:", 0

start:   MsgBox 0, "Hello World", addr AppName, MB_OK
   exit

end start

dedndave

i do have to add a few, once in a while

if i want to work on the registry, i have to add AdvApi32 (inc/lib)
if i want to use TransparentBlt, i have to add MsImg32 (inc/lib)
if i want to play with multi-media stuff, i have to add WinMm (inc/lib)
if i want to do internet stuff, i have to add WinInet and/or Ws2_32 (inc/lib)
once in a while, you may want OLE stuff - Ole32 (inc/lib), maybe OleAut32 (there are other Ole's, too)
these are just some examples

if you want to create a listing, it is nice to add .XCREF and .NOLIST/.LIST to keep the list file small

if you want to play with MMX or SSE, you have to set the processor and use .MMX/.XMM
the Masm32rt.inc file sets the processor to .486
so, sometimes, you may have to bump that up to use certain instructions (CPUID, RDTSC, etc)
this has to be done prior to adding Michael's timing macros

the order is important for some of these
a long example might be...
        .XCREF
        .NOLIST
        INCLUDE    \Masm32\Include\Masm32rt.inc
        INCLUDE    \Masm32\Include\AdvApi32.inc
        INCLUDELIB \Masm32\Lib\AdvApi32.lib
        .686p
        .MMX
        .XMM
        INCLUDE    \Masm32\Macros\Timers.asm
        .LIST

Vortex

Hi bit8bug,

Dave's explanation is nice. If you try GoAsm \ GoLink, another poweful Win32 assembler \ linker set, you will see that they don't need of import libraries.

frktons

Quote from: Vortex on January 21, 2013, 05:25:29 AM
Hi bit8bug,

Dave's explanation is nice. If you try GoAsm \ GoLink, another poweful Win32 assembler \ linker set, you will see that they don't need of import libraries.

You don't put the include in the source. But probably it is done by the
assembler/compiler anyway. Is this what you mean?
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

Vortex

Hi frktons,

There is an include file set for GoAsm prepared by Donkey but normally GoAsm does not require the usage of include files. Import libraries are replaced by the names of DLLs specified in the source code or command-line :

\goasm\golink srcfile.obj Rsrc.res kernel32.dll user32.dll

Stan

3. ALWAYS make a posting as soon as you have confirmed your membership by responding to the email that the forum software sends you. This is the final most reliable method of determining a valid human being and not a spam bot.
-----------------------------------
Where can I find information about the control directives for the assembler?  I have attempted a search, but by not knowing exactly what to ask for, I don't know what gets delivered.
I need a quick/or/detailed explanation of the assembler directives.  Where is the information that would explain why I need to do items is a specific order?  What does the assemble & link, build all, build console, make all do and how critical is the order?
-----------------------------------
No spam bot could possibly generate such primitive questions.

dedndave

if you have installed the masm32 package, \Masm32\Help\Masm32.chm