I used a snipplet from what NaN posted once to try and make a strlen macro, and here's what i have.



$STRLENGTH MACRO Function:REQ, arg:BYTE
push ecx
xor eax,eax
doagain:
mov cl,[arg+eax]
cmp cl,0
je foundlength
inc eax
jmp doagain
foundlength:
pop ecx
EXITM <eax>
ENDM


When I try to build it, i get this error:

consoleex.asm(14) : error A2008: syntax error : BYTE
$STRLENGTH etc is the 14th line
Posted on 2001-08-23 23:41:51 by vcv
Hello,

i think that arg should be defined as :DWORD,
because arg is a 'pointer' to a String.

Let me know if this is right.
Posted on 2001-08-23 23:59:44 by marsface
Thank you, that was one issue.
But actually I forgot to put it under .code

Now that I did, I get this error:

consoleex.asm(31) : error A2008: syntax error : BYTE

line 31 being:

$LEN MACRO Function:REQ, arg:BYTE
Posted on 2001-08-24 00:10:29 by vcv
Hello,

maybe that's the problem

mov cl,

try

mov cl, byte ptr


2.
i would intend to use local labels within a
macro call.

@@:
mov cl, byte ptr
cmp cl, 0
je @F ; forward label
inc eax
jmp @B ; backward label
@@:

Hope this helps ;-)
Posted on 2001-08-24 03:13:45 by marsface
BYTE is invalid as a qualifier of a macro parameter. Valid is :REQ or :VARARG. Dont confuse "macro" with "proc". So just remove :BYTE from your code.

japheth
Posted on 2001-08-24 03:33:35 by japheth
Thanks for both of your help :)
Posted on 2001-08-24 05:05:52 by vcv
Im glad im able to inspire :grin: ...

I was about to point out a bug with your label references until marsface beat me to the punch... His solution is sound, but you dont HAVE to follow this if you dont want to, as well there my be a future macro where you need 3 jmps that cant be controlled with @F and @B.

So to provide labels in a macro you must define them as LOCAL's such the compiler will know to makeup new names for them each time its inserted into code.

$STRLENGTH MACRO Function:REQ, arg:REQ

LOCAL doagain, foundlength
push ecx
xor eax,eax
doagain:
mov cl,[arg+eax]
cmp cl,0
je foundlength
inc eax
jmp doagain
foundlength:
pop ecx
EXITM <eax>
ENDM


This will now work for multiple occourances of this macro.

Hope it helps..

:alright:
NaN

BTW: I would be interested i seeing what your brainstroming has come up with, when your satisfied and done...
Posted on 2001-08-24 13:32:18 by NaN
Ack, I hate being so new to assembly. Anyways, thanks NaN, that helps a lot.

Actually, all I'm trying to do is input 2 integers via console and print their sum.

As far as the $STRLENGTH macro goes, I'm trying to use it for a printconsole function. It runs fine now, but I think it's returning the wrong length ;(

	text	db "Enter a number to add: ",0

text2 db "Enter another number to add: ",0

I have that, and..
    invoke	WriteConsole, hOutput, addr text, $len( dword ptr [text] ), addr written, NULL
(I changed $STRLENGTH to $len).

I run it, and it prints:
Enter a number to add: Enter another number to add:

Back to work trying to fix it..
Posted on 2001-08-24 13:47:36 by vcv
hiiii

first i would like to start with
when you write mov cl, ,or mov al and etc.. you dont need to use byte ptr becuase cl is a byte .

i dont use alot in macros(dont understand in this much either) but :look at the changes i did it will save you some speed,



$STRLENGTH MACRO Function:REQ, arg:REQ
LOCAL doagain, foundlength
push ecx
mov eax,-1

doagain: inc eax
mov cl,

or cl,cl
jnz doagain
pop ecx
EXITM <eax>
ENDM

bye

eko

p.s
maybe you should check for the lenght
while ago disease_2000 published some code in here that count the length using dword it wasnt so good ,but betov published his own version then , ididnt check it but i allmost 100% sure that his version is FAST
Posted on 2001-08-24 14:23:15 by eko
i see the problem now NaN. !

Sorry for that garbage vcv
Posted on 2001-08-24 14:57:08 by marsface
Exnay on the Appologies-ay!!

I didnt say yours was wrong in any which way.. I actually use the @@:/@F/@B alot.. (In macros and not). I would most likely have done it the same, seeing it can fit the nice pattern you posted.

I just wanted to teach of other solutions, thats all :) So no, your post was NOT garbage... keep up the good work!

NaN
Posted on 2001-08-24 19:04:53 by NaN
Sorry that i got you wrong NaN
that's because my English lacks a little bit :)

I've a problem understanding this part of a Macro,
could somebody explain please.





except this... ;-)

MsgBox MACRO handl, TxtMsg, TxtTitle, styl
LOCAL Msg1
LOCAL Titl
------------------

If @InStr(1,<TxtMsg>,<ADDR>) eq 0
If @InStr(1,<TxtTitle>,<ADDR>) eq 0
.data

Posted on 2001-08-26 13:24:12 by marsface
There are built-in string macros in MASM. @InStr is one of those macros - it finds a sub-string in another string, and returns the position where is found the sub-string or zero if it fails to find it. Let us look at some examples:

temp TEXTEQU @InStr(1,<We are are the world>,<are>)
% ECHO temp ;the % because we don't want 'temp' output

Output:
04

temp TEXTEQU @InStr(5,<We are are the world>,<are>)
% ECHO temp

Output:
08

temp TEXTEQU @InStr(5,<We are are the world>,<are>)
temp TEXTEQU %temp ; look what this does!
% ECHO temp

Output:
8


Syntax: @InStr({start position},{string},{sub-string})
WARNING: the built-in @ string functions are case-sensitive!

Therefor, the macro is checking if the passed parameter has "ADDR" in it. :alright:
Posted on 2001-08-26 14:27:38 by bitRAKE
thanks a lot bitRAKE


@InStr(5,<We are are the world>,<are> )


Your words in gods ears!
Posted on 2001-08-28 12:45:11 by marsface
Last minute thought, or in this case, a quote i stumbled upon in the Masm reference today...


You should avoid using anonymous labels in macros (see ?Anonymous Labels? in Chapter 7). Although legal, they can produce unwanted results if you expand a macro near another anonymous label. For example, consider what happens in the following:
Update MACRO arg1
@@: .
.
.
loop @B
ENDM
.
.
.
jcxz @F
Update ax
@@:

Expanding Update places another anonymous label between the jump and its target. The line
jcxz @F

consequently jumps to the start of the loop rather than over the loop ? exactly the opposite of what the programmer intended.


Enjoy MaCing Macros..

NaN
Posted on 2001-08-28 21:06:24 by NaN