NO

Author Topic: Incorrect parameter assignment  (Read 1083 times)

Offline Vortex

  • Member
  • *
  • Posts: 801
    • http://www.vortex.masmcode.com
Incorrect parameter assignment
« on: February 10, 2024, 10:01:20 AM »
Trying to implement an enum macro :

Code: [Select]
include enumMacro.inc

; enum macro by mabdelouahab

; https://masm32.com/board/index.php?msg=126825

enum MACRO __vargs:VARARG

LOCAL val__

    val__=0
   
    FOR __varg,<__vargs>
   
           __varg EQU val__
       
        val__ = val__ +1
       
    ENDM
   
ENDM

.data

format  db 'test1 = %u',13,10
        db 'sample = %u',13,10
        db 'experiment = %u',0

.data?

buffer  db 64 dup(?)

.code

start:

    enum    test1,sample,experiment

    invoke  wsprintf,ADDR buffer,\
            ADDR format,test1,sample,experiment

    invoke  StdOut,ADDR buffer

    invoke  ExitProcess,0

END start

Running the executable, I receive the following results :

Code: [Select]
test1 = 3
sample = 3
experiment = 3

The correct version should be :

Code: [Select]
test1 = 0
sample = 1
experiment = 2

Poasm does not correctly assign the parameters.
Code it... That's all...

Offline Vortex

  • Member
  • *
  • Posts: 801
    • http://www.vortex.masmcode.com
Re: Incorrect parameter assignment
« Reply #1 on: February 10, 2024, 08:28:12 PM »
Same result after this attempt :

Code: [Select]
enum MACRO p1,p2,p3,p4,p5,p6,p7,p8

LOCAL val__

val__=0
   
    FOR arg,<p1,p2,p3,p4,p5,p6,p7,p8>
   
        IFNB <arg>

            arg EQU val__
                 
            val__ = val__ +1
           
        ENDIF

    ENDM
   
ENDM

Code: [Select]
test1 = 3
sample = 3
experiment = 3
« Last Edit: February 10, 2024, 08:30:43 PM by Vortex »
Code it... That's all...