The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: korte on June 22, 2009, 07:22:55 PM

Title: Define data table
Post by: korte on June 22, 2009, 07:22:55 PM

How to define macro?


table macro data_address,data (data is vararg)
  cnt=0
  mov [data_address+cnt],data
endm





    table data_address,1,2,3,4,5,6,7,8,
Title: Re: Define data table
Post by: Jimg on June 22, 2009, 07:50:05 PM
table macro tbladdr,bvals:vararg
    local cnt
    cnt=0
    for dat,<bvals>
        mov byte ptr [tbladdr+cnt],dat
        cnt=cnt+1
    endm       
endm

.data?
mytable db 10 dup (?)
.code

table mytable,1,2,3,4,5,6,7,8


note:  this is only for bytes, modify as desired for other sized values, eg.


table macro tbladdr,dvals:vararg
    local cnt
    cnt=0
    for dat,<dvals>
        mov dword ptr [tbladdr+cnt],dat
        cnt=cnt+4
    endm       
endm

.data?
mytable db 40 dup (?)
.code

table mytable,1111,2222,3333,4444,5555,6666,7777,8888


however, I don't see why you would want to do this when you could just do


.data
mytable dd 1111,2222,3333,4444,5555,6666,7777,8888
.code

and not have to worry about exceeding the space set aside for the table and other things.