The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: pop141 on February 26, 2008, 10:32:11 AM

Title: Help with macro
Post by: pop141 on February 26, 2008, 10:32:11 AM
Hi,

i am new to assembly language and i have a problem with this program. The program assembles but does not link for some reason. i would realy appreciate the help if someone could tell me where i am going wrong. also how can i use hex charters to display text

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

;                 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


    print MACRO Quoted_Text:VARARG
    LOCAL Txt

    .data                        ;Enter here initiated data

    Txt db "hey This works",13,10
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

   ; .data?                       ;Enter here uninitiated data

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

    .code                       ; Tell MASM where the code starts

        invoke StdOut,ADDR Txt
        ENDM

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

;start:                          ; The CODE entry point to the program

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

end                    ; Tell MASM where the program ends


Title: Re: Help with macro
Post by: evlncrn8 on February 26, 2008, 12:29:28 PM
marking an entrypoint generally helps... you commented yours out
and there should be some code in it too.... look at some of the examples in the masm32 package
Title: Re: Help with macro
Post by: ToutEnMasm on February 26, 2008, 01:45:13 PM

a macro declaration isn'nt code and isn't data,just say what to do at the compiler if it is uses in code

Quote
   print MACRO Quoted_Text:VARARG
     Local Txt                                         ;Txt is a constant being modify by the macro
                                                           ;no binaries create here
    ENDM                                               ;end of the macro

.data
chain db "hey This works",13,10             ;This create binary data in the .obj and executable
.code                                                  ;code begin here
..
start:                                                  ;entry point,first execute code
                   print                                ;create code binaries here
end start                                             ;end entry point and code
Title: Re: Help with macro
Post by: pop141 on February 26, 2008, 05:03:42 PM
Thanks guys you realy helped... i got it done now.. but for some reason i get an error after the program runs...


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

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

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

    .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




;hello.asm

include c:\MASM32\work\headings.inc

   print MACRO Quoted_Text:VARARG
     Local Txt                                         ;Txt is a constant being modify by the macro
                                                       ;no binaries create here
    ENDM                                               ;end of the macro
   
.data

Txt db "hey This works",13,10                          ;This create binary data in the .obj and executable

.code                                                  ;code begin here

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:                                                 ;entry point,first execute code

invoke StdOut,ADDR Txt                                 ;create code binaries here
                                                     
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                                                       
end start                                              ;end entry point and code


Title: Re: Help with macro
Post by: MichaelW on February 27, 2008, 12:53:34 AM
I see two problems in you code. The first is that StdOut expects to be passed the address of a null-terminated string, and your string is not null-terminated. The null is used to indicate the end of the string, and without it StdOut, or any function that works with null-terminated strings, will keep going until it finds a null, or causes an exception by accessing memory that the program does not own. A null terminator should be appended to the end of the string:

Txt db "hey This works",13,10,0

The second problem is that the program is not terminating correctly. Try adding a call to  ExitProcess (http://msdn2.microsoft.com/en-us/library/ms682658.aspx) above the end directive:

invoke ExitProcess, 0