The MASM Forum

General => The Campus => Topic started by: RuiLoureiro on March 22, 2013, 09:32:03 PM

Title: Masm question
Post by: RuiLoureiro on March 22, 2013, 09:32:03 PM
Hi
     is there a procedure to be used in console application to print
     values and strings like this:

          invoke  ThatProcedure, "pimpipmpim", str$(eax),"pumpumpum",
                      str$(ebx), 32, str$(edx), ...
          or
          invoke  ThatProcedure, str$(eax), str$(ecx), "pumpumpum",
                      str$(ebx), 32, str$(edx), ...

    Thank you !  :biggrin:

         switch/case uses registers or they are all free ?
   
Title: Re: Masm question
Post by: hutch-- on March 22, 2013, 09:33:46 PM
cat$.
Title: Re: Masm question
Post by: jj2007 on March 22, 2013, 09:51:20 PM
Quote from: RuiLoureiro on March 22, 2013, 09:32:03 PM
invoke  ThatProcedure, str$(eax), str$(ecx)

Not with eax & ecx, but this works:

include \masm32\include\masm32rt.inc
.code
print3 proc arg1, arg2, arg3
  print arg1
  print arg2
  print arg3
  ret
print3 endp

start:
   mov esi, 111
   mov edi, 222
   invoke print3, str$(esi), chr$("<>"), str$(edi)
   inkey " - ok?"
   exit
end start


Quoteswitch/case uses registers or they are all free ?

Only eax, and it will have the Switch XXX value (see macros.asm):

    switch macro _var:req, _reg:=<eax>
        mov _reg, _var

Title: Re: Masm question
Post by: RuiLoureiro on March 23, 2013, 01:55:36 AM
Hello __Hutch__  :biggrin:

        How are you ?

        cat$ ?  How do i use it ?

_Jochen,

        How are you ?  ;)
        Good help
        (but i need to learn something about how to write macros )

        If "switch macro _var:req, _reg:=<eax>"
        so _reg is EAX
        so mov _reg, _var  => mov eax, _var

        Instead of "mov eax, _var" it could be
        "push    dword ptr _var"

        Thank you !  :icon14:
Title: Re: Masm question
Post by: qWord on March 23, 2013, 02:38:27 AM
Quote from: RuiLoureiro on March 23, 2013, 01:55:36 AMbut i need to learn something about how to write macros
read chapter 9 of MASM's Programmer's guide.

Quote from: RuiLoureiro on March 23, 2013, 01:55:36 AMIf "switch macro _var:req, _reg:=<eax>"
        so _reg is EAX
        so mov _reg, _var  => mov eax, _var
"parameter:=<default token>" tells MASM to use the text inside the angle brackets if the parameter is not specified on macro call.
(":req" denotes a macro argument, which must be present on call - otherwise errors are thrown)
Title: Re: Masm question
Post by: hutch-- on March 23, 2013, 12:36:50 PM
Rui,

"cat$" is fully documented in the help file. Find it in "hlhelp.chm".
Title: Re: Masm question
Post by: RuiLoureiro on March 24, 2013, 09:19:40 AM
Hutch,
            Thanks, i found it and it helps ! ;)
Title: Re: Masm question
Post by: RuiLoureiro on March 24, 2013, 09:45:36 PM
I wanted to replace this 4 instructions by only 1
which is used in a loop and with cat$ i cannot
do it

                    print   "X Y=  "
                    print   str$(ebx),32
                    print   str$(esi)," value = "
                    print   addr _StrValue,13,10
Title: Re: Masm question
Post by: jj2007 on March 24, 2013, 10:05:29 PM
Rui,

Here is an example how to do it. The MasmBasic version is only marginally simpler, in fact cat$ is a really efficient Masm32 macro:

include \masm32\MasmBasic\MasmBasic.inc        ; download (http://masm32.com/board/index.php?topic=94.0)
.data?
buffer        db 100 dup(?)
        Init
        .Repeat
                Print Str$(esi), Tb$, Str$(ebx), CrLf$
                inc esi
                dec ebx
        .Until esi>3
        Print "Now the same with plain Masm32:", CrLf$
        mov edi, offset buffer
        .Repeat
                and byte ptr [edi], 0
                print cat$(str$(esi), chr$(9), str$(ebx), chr$(13, 10))
                inc ebx
                dec esi
        .Until Sign?
        inkey "ok"
        Exit
end start

The and byte ptr [edi], 0 serves to reset the buffer, of course.