News:

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

Main Menu

What am I doing wrong in the creation and use of this macro?

Started by Rav, June 28, 2022, 05:44:10 AM

Previous topic - Next topic

jj2007

Quote from: Rav on June 28, 2022, 10:37:56 AMOnce again:  I DID post complete code.  I DID test the code I posted.  There IS NO OTHER CODE.  The only error I got during assembly of the code that I posted was "syntax error: SUBSTR".  There were NO OTHER ERRORs.  And getting that ONE error was WHY I made my original post.  Why you got a bunch of errors that I did NOT get is unknown to me.  I did not get those errors.

OK, mystery solved - my apologies: you did not get those errors because you are using a very recent version of ML.exe which, apparently, does no longer need the usual .686p at the start of the file. That makes your code incompatible with the setups of most but not all members here. The Masm32 SDK comes with ML version 6.14; all MASM versions up to version 9.0 need the .*86, same for the Watcom gang.

My advice: add a .686p on top of all your sources. Visual Crap may not need it, but you can spare yourself such negative experiences.

And keep in mind that you cannot change a macro argument, as explained earlier. It will choke.

Technically speaking, you can change a proc argument, though:

MyTest proc zStringPtr:DWORD
  mov zStringPtr, 123


However, you should never do that, it's considered bad and risky coding.

Rav

Quote from: jj2007 on June 28, 2022, 11:10:02 AM
Quote from: Rav on June 28, 2022, 10:37:56 AMOnce again:  I DID post complete code.  I DID test the code I posted.  There IS NO OTHER CODE.  The only error I got during assembly of the code that I posted was "syntax error: SUBSTR".  There were NO OTHER ERRORs.  And getting that ONE error was WHY I made my original post.  Why you got a bunch of errors that I did NOT get is unknown to me.  I did not get those errors.

OK, mystery solved - my apologies: you did not get those errors because you are using a very recent version of ML.exe which, apparently, does no longer need the usual .686p at the start of the file. That makes your code incompatible with the setups of most but not all members here. The Masm32 SDK comes with ML version 6.14; all MASM versions up to version 9.0 need the .*86, same for the Watcom gang.

My advice: add a .686p on top of all your sources. Visual Crap may not need it, but you can spare yourself such negative experiences.

And keep in mind that you cannot change a macro argument, as explained earlier. It will choke.

Technically speaking, you can change a proc argument, though:

MyTest proc zStringPtr:DWORD
  mov zStringPtr, 123


However, you should never do that, it's considered bad and risky coding.

Thanks for saying that -- I appreciate it.  And thanks for the additional info.

NoCforMe

Quote from: jj2007 on June 28, 2022, 11:10:02 AM
Technically speaking, you can change a proc argument, though:

MyTest proc zStringPtr:DWORD
  mov zStringPtr, 123


However, you should never do that, it's considered bad and risky coding.

Just to address this small issue, was reading about this the other day and the writer said that procedure arguments are basically the same as local variables; they're all on the stack, it's just that arguments get set by the caller. So no harm, no foul if you change an argument--just so long as you're sure you're never going to need it again, 'cause you can't get it back once you've overwritten it. Amiright?
Assembly language programming should be fun. That's why I do it.

hutch--

Rav,

Macros have their uses if you are used to writing them but stripping leading blanks or tabs from text is best done with a tiny loop where you start at the beginning of the string and scan through the start of the string until the next character is neither a space (ascii 32) or a tab (ascii 9). Code of this type is both tiny and fast.

    mov ecx, pstr                       ; load the string
    sub ecx, 1                          ; set up for loop

  @@:
    add ecx, 1
    cmp BYTE PTR [ecx], 32              ; test for space
    jne @F
    cmp BYTE PTR [ecx], 9               ; test for tab
    jne @B

  @@:

hutch--

Here is the complete example.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    sptrim PROTO sptr:DWORD,buffr:DWORD


    .data
      MyString db "        12345678",0      ; the string
      pstr dd MyString                      ; its pointer
      buffer db "                         " ; buffer
      pbuf dd buffer                        ; its pointer

    .code

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

    call main
    inkey
    exit

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

main proc

    LOCAL pout :DWORD

    print pstr,13,10

    invoke sptrim,pstr,pbuf
    mov pout, eax

    print pout, 13, 10

    ret

main endp

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

sptrim proc sptr:DWORD,buffr:DWORD

    mov ecx, sptr                       ; load the string
    sub ecx, 1                          ; set up for loop

  @@:
    add ecx, 1
    cmp BYTE PTR [ecx], 32              ; test for space
    jne @F
    cmp BYTE PTR [ecx], 9               ; test for tab
    jne @B

  @@:
    mov edx, buffr
    sub ecx, 1
    sub edx, 1

  @@:
    add ecx, 1
    add edx, 1
    mov al, BYTE PTR [ecx]
    mov BYTE PTR [edx], al
    test al, al
    jnz @B

    mov eax, buffr

    ret 8

sptrim endp

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

end start