i just want to implement a macro for creating an array of bytes as a local variable, but masm say that there are problems. Im using "FOR" directive

---
InsBytes macro Byte_Value
jmp Done
for Byte_Value
db Byte_Value
endm
Done:
endm
---

What could be wrong? please help...
Posted on 2003-01-02 20:29:22 by IrOn
InsBytes macro Byte_Values:VARARG

LOCAL Done, Byte_Value
jmp Done
FOR Byte_Value, <Byte_Values>
db Byte_Value
ENDM
Done:
ENDM
Posted on 2003-01-02 20:51:49 by bitRAKE
IrOn,
What is the purpose of putting data in the code section? Why not do this?



SUB EAX,3
.DATA
DB 1,2,3,4,5,6
.CODE
MOV EAX,EBX


Then a jump is unnecessary to get past the data. Ratch
Posted on 2003-01-03 00:15:18 by Ratch
Ratch is correct - it is better to put the data in another segment if it is not needed in the code segment.
InsBytes macro Byte_Values:VARARG

LOCAL Byte_Value
CONST SEGMENT
FOR Byte_Value, <Byte_Values>
db Byte_Value
ENDM
CONST ENDS
ENDM
Posted on 2003-01-03 09:41:57 by bitRAKE
Thanks BitRake and i have another problem, this time is with FORC, i have read the docs of forc but i cant figure it out. All i want ot do is to create an array of bytes locally (with local directive)in a proc and i want to assign a string to it



MyProc proc
local Str[5]:BYTE

LoadStr Str, "HELLO"
MyPro endp



How do you implement LoadStr as a macro??
Posted on 2003-01-03 11:56:16 by IrOn
I created this macro as part of vKim!'s vkdebug.
http://www.asmcommunity.net/board/index.php?topic=7955&highlight=vkdebug

FillString macro Arr, Text

local i,j
i = 0
j = 0
forc var, <&Text>
j = ('&var' shl ((i and 3)*8)) + j
if (i and 3) eq 3
mov dword ptr Arr[(i and -4)], j
j=0
endif
i = i + 1
endm

if (i and 3) eq 0
mov byte ptr Arr[i], 0
elseif (i and 3) eq 1
mov word ptr Arr[i-1], j
elseif (i and 3) eq 2
mov word ptr Arr[i-2], j
mov byte ptr Arr[i], 0
elseif (i and 3) eq 3
mov dword ptr Arr[(i-3)], j
endif
endm
You can use it like:
MyProc proc

local Str[5]:BYTE

FillString Str, "HELLO"
MyPro endp
...and it will create only two instructions. :)

I really wish we could do somthing like:
local Str[5]:"HELLO"


or

LOCAL Str[5]:BYTE "HELLO"
Posted on 2003-01-03 16:53:04 by bitRAKE
bitRAKE,
The MACRO FillString appears to output the quotes and always add a zero byte. For instance, your example | FillString tag,"Hello" |, outputs both quotes, and tacks on a zero byte for a total of eight bytes generated. Is that what you intended? I did not use it with local variables within a procedure, but that should not make any difference. Ratch
Posted on 2003-01-03 19:55:33 by Ratch
Ratch, yes that is the intended function, but my example is wrong. Forgive me - it should be:
MyProc proc

local Str[6]:BYTE

FillString Str, <HELLO>
MyPro endp
Also, to meet IrOn's task it should be adjusted to not add zero termination. Once again I provide sloppy advice from work while doing other tasks. Maybe, I try too hard to help.
Posted on 2003-01-03 22:59:28 by bitRAKE