News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

scanf macro and printf macro

Started by stevenxie, November 14, 2020, 11:53:04 PM

Previous topic - Next topic

stevenxie

;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;解群自定义宏
;**************************************
    scanf  MACRO format:REQ,args:VARARG
      rcall vc_scanf,cfm$(format),args
      EXITM <>
    ENDM 

    printf  MACRO format:REQ,args:VARARG
    rcall vc_printf,cfm$(format),args
      EXITM <>
    ENDM
;**************************************
;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

they work properly and i have added them to my MASM 64SDK main macro MACRO64.INC. Everything is fine, please all lazy people, good to create their own useful macro code.

hutch--

They look good, just make sure that the names do not clash with anything in the VC runtime library. The reason for the "vc" prefix is to avoid this problem. "vc_scanf"

stevenxie

Quote from: hutch-- on November 15, 2020, 12:34:50 AM
They look good, just make sure that the names do not clash with anything in the VC runtime library. The reason for the "vc" prefix is to avoid this problem. "vc_scanf"
very good

; *******************************************************

    include \masm32\include64\masm64rt.inc

    .data
   a dq ?
   b dq ?
   s dq ?
.code

; ******************************************************

entry_point proc
       
    printf("\t please input a and b \t")
    scanf("%ld%ld", offset a, offset b)
    mov rax,a
    add rax,b
    mov s,rax
    printf("\t a+b=%ld",s)
    printf("\n")
    waitkey

    .exit

entry_point endp

;*******************************************************

    end

it need to be noticed  that the "offset"

Vortex

Hi stevenxie,

Reading the original macros64.inc :

    rcall MACRO pname,ag1,ag2,ag3,ag4
      register_call pname,ag1,ag2,ag3,ag4
    ENDM


The rcall macro takes a maximum of 5 parameters.

Here is another version of your printf macro :

include     \masm32\include64\masm64rt.inc

printf MACRO format:REQ,args:VARARG
   invoke vc_printf,cfm$(format),args
ENDM

.code

start PROC

    printf "%s %u %u %u %u %u","This is a test",1,2,3,4,5
    invoke  ExitProcess,0

start ENDP


I get the following error message with your macro :

UpperCase.asm(11) : warning A4006:too many arguments in macro call

stevenxie

hi vortex.
it is a simple question
folowing:

.........
printf("%d %d %d  ",1,2,3)
printf("%d %d %d",5,6,7)
.........
so it have unlimit args.
:eusa_boohoo:

Vortex

Hi stevenxie,

Your macro is nice but I am afraid the case is not so simple. You are calling twice the printf macro while you can do it only with one line. In your code, you have four items limit per call. Don't misunderstand me, my aim is not to be a critique here. With some small retouches, I am sure you can write very useful macros. Thanks for your macro idea.

stevenxie


hutch--

Hi Steven, just one suggestion, like many of others I used to use simple single characters as variables but it comes back to bite you later when you don't remember what each one was. It is useful to use descriptive names as it helps you to keep track of what code is doing when you look at it again some time later.

Sad to say I have been caught enough times where I have had to carefully track what a variable does to make sense of the code again and this does matter when you write code that is designed to be reused like libraries or code block that you want to insert later.

TouEnMasm


best way is to use the original functions with the original libraries or with windows 10 a library with the inlines functions.
You can have a library with inlines functions here http://luce.yves.pagesperso-orange.fr/header.htm
dowload the sdk10.0 it is in H:\sdkrc100\crt_lib\IX86\release\crt10_32.lib
there is the same in 64
Fa is a musical note to play with CL

hutch--

The real problem with directly calling C runtime libraries is issues of namespace, it already clashes with some MASM reserve words and the process of appending a lead "vc" solves that problem. Working the 64 bit include and library in 64 bit MASM are problem free.

TouEnMasm


Real problem is to have rebuild the msvcrt librarie changing the names of various functions.
The msvcrt is just a part of the system and cannot be modified without many risks and problems.

Fa is a musical note to play with CL

hutch--

Except that it has namespace errors when used with MASM. The includes and library are very reliable and does not have the problems of trying to use a C runtime library.

Vortex

Is it possible to set internal and external names in import libraries? Maybe this would be another method to avoid naming conflicts.

TouEnMasm


I use the libraries as they are with the prototypes as they are(just translate) without any problem (UASM).
Ml64 could use also the same protototypes but is more limited than UASM.
With windows 10 , there is just the inline functions who are a problem.They need a simple library done by Visual Studio.
It is possible.
Fa is a musical note to play with CL

jj2007

Quote from: hutch-- on November 15, 2020, 08:48:36 PMit already clashes with some MASM reserve words

Can you give an example?