#### hutch--

• Member
• Posts: 7633
• Mnemonic Driven API Grinder
« Reply #45 on: January 20, 2019, 08:11:47 AM »
It just means that the argument is required and if the arg is omitted you get an error.
hutch at movsd dot com
http://www.masm32.com

#### jj2007

• Member
• Posts: 10664
• Assembler is fun ;-)
« Reply #46 on: January 20, 2019, 08:28:19 AM »
REQ forces an error if the argument is not present. Here is a test piece showing some macro tricks.

Code: [Select]
`include \masm32\include\masm32rt.inchi macro arg ; now add :req and see what it does  print "hi ", argendmhiwithdef macro arg:=<"folks"> ; you can use it without passing an argument but...  print "hi ", argendmtest1 macro arg ; assemble time: generates code only for the relevant branch  ifidn <arg>, <eax> print "you passed eax", 13, 10  else print "you passed &arg", 13, 10  endifendmtest2 macro arg ; runtime: generates code for both branches  .if arg==eax print "you passed eax", 13, 10  .else print "you passed &arg", 13, 10  .endifendm.codestart:  hi "TBRANSO1"  print chr\$(13, 10)  hi  print chr\$(13, 10)  hiwithdef "TBRANSO1"  print chr\$(13, 10)  hiwithdef  print chr\$(13, 10)  test1 eax  test1 something else  test2 eax  test2 ecx  inkey "ok?"  exitend start`

#### TBRANSO1

• Member
• Posts: 81
« Reply #47 on: January 20, 2019, 08:49:49 AM »
REQ forces an error if the argument is not present. Here is a test piece showing some macro tricks.

Cool examples.

I am continually amazed at what MASM can do for lowly assembly that resembles stuff that I only thought was available in OOP languages.  I've placed C in Python or Ruby and it's a bitch and time consuming to do it, working with the original C-code bases and the FFI library. I may be prematurely saying this since I am new to this, but when folks say that it's not possible to do things in assembly except some number crunching here and there, obviously aren't aware of the capabilities you guys have designed along with the assemblers.  I've always said the smartest programmers aren't the guys doing Front End JS stuff, but the compiler, assembler writers.

I have another example that I made into a MACRO, and wondering what you thought of my implementation:
from MSDN there is

Code: [Select]
`MAKEINTRESOURCEA(i) (LPSTR)((DWORD)((WORD)(i)))`
I realize that this make be absolutely unnecessary in assembly but I made this:
take the lower word of the parameter, cast it to double word, then cast it to LPSTR

Code: [Select]
`MAKEINTRESOURCE MACRO param:REQ LOCAL lpcStr .data lpcStr LPCSTR ? .code and param, 000FFh push param pop lpcStr EXITM <lpcStr>ENDM`

#### hutch--

• Member
• Posts: 7633
• Mnemonic Driven API Grinder
« Reply #48 on: January 20, 2019, 09:37:18 AM »

Looks like a C compiler.  :P
hutch at movsd dot com
http://www.masm32.com

#### jj2007

• Member
• Posts: 10664
• Assembler is fun ;-)
« Reply #49 on: January 20, 2019, 11:08:44 AM »
> and param, 000FFh

Are you sure it shouldn't be 0FFFFh?

#### TBRANSO1

• Member
• Posts: 81
« Reply #50 on: January 20, 2019, 11:57:14 AM »
> and param, 000FFh

Are you sure it shouldn't be 0FFFFh?

You're right, I caught that afterward.  I had changed it in my base code already.

I had to change it a bit, since the assembler complained.

Code: [Select]
`MAKEINTRESOURCE MACRO param:REQ LOCAL lpStr .data? lpStr LPSTR ? .code xor eax, eax mov eax, param and eax, 0FFFFh mov lpStr, eax EXITM <lpStr>ENDM`

#### TimoVJL

• Member
• Posts: 565
« Reply #51 on: January 20, 2019, 07:24:21 PM »
In C MAKEINTRESOURCE macros don't generate code, only casts WORD value to LPSTR / LPWSTR.
Code: [Select]
`#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))#define MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i))))`
Code: [Select]
`7: LPSTR lpStr = MAKEINTRESOURCEA(8001);  [00000006] C745FC411F0000         mov               dword ptr [ebp-4],1F41h8: LPWSTR lpWStr = MAKEINTRESOURCEW(8001);  [0000000D] C745F8411F0000         mov               dword ptr [ebp-8],1F41h`UNREFERENCED_PARAMETER() macro works only with optimizing compilers, as they can remove an unused parameter.
May the source be with you

• Member
• Posts: 81