Re: Uniform spacing of labels in MASM32
- From: "Nicolo Parenti" <spamtrap@xxxxxxxxxx>
- Date: Wed, 21 Dec 2005 06:59:32 -0500
Chris Martens wrote:
> I'm a recently graduated computer engineer who's been messing around
> with assembly for more than 2 years now. (Mostly TASM for basic
> hardware drivers and inline asm in MS VC++6.0, the source of
> manyheadaches).
>
> I've been working on a hobby project involving an interpreter engine
> that uses compiled binaries to allow me to script new functionality in
> without having to recompile.
>
> The way I thought of doing this was allocating each binary instruction
> (16 bits wide) a 64 byte chunk of code to implement what it had to do.
> I've done this before writing text blitters for DirectX (yes, I'm a
> bit of an oddball), but I thought that using masm32 to compile the
> function in assembly would give me greater control than inline
> assembly in MS VC++ 6.0 like the way I used to do things.
>
> Here's what I mean - I've got it to work before, but that has been
> thru trial and error and the clever placement of NOP's to space each
> command implementation apart. I'm thinking there has to be an easier
> way.
You probably shouldn't worry about spacing them out, but rather collect their addresses, whatever they end up as, into a table and jump through that. You can align the addresses using ALIGN 4 (for example) before each one, so that the jump targets are on dword boundaries.
JumpTable dd Command1, Command2, etc
mov ebx, offset Instruction
sub ebx, 2
jmp JumpTable[ebx*4] ; or call/retf
align 4
Command1:
some code
some code
align 4
Command2:
more code
more code
Alternatively, if you must space them out, try the .ORG directive. I don't actually know if this works in prot mode segments because I haven't needed it since the DOS days, but it goes like this:
Command1: some code
some code
.org ExecStart+40H
Command2:
more code
more code
====================
>
> [MASM32 CODE]
>
> mov ebx, offset Instruction
> sub ebx, 2 ; Each instruction is two bytes wide (WORD)
>
> LoopStart:
> add ebx, 2
> xor edx, edx
> mov dx, WORD PTR [ebx]
> sal edx, 6
> add edx, offset ExecStart
> jmp edx
>
> ExecStart:
> ; Instruction 0x0000 code
> jmp LoopStart
>
> ExecStart + 40h:
> ; Instruction 0x0001 code
> jmp LoopStart
>
> [END MASM32 CODE]
>
> ...and so on. But, as you might have been able to tell, the assembler
> goes nuts on the ExecStart+40h line. Here's the error message:
>
> C:\masm32\projects\FeatureEngine\execfeature.asm(154) : error A2008:
> syntax error : +
>
.
- Follow-Ups:
- Re: Uniform spacing of labels in MASM32
- From: Chris Martens
- Re: Uniform spacing of labels in MASM32
- References:
- Uniform spacing of labels in MASM32
- From: Chris Martens
- Uniform spacing of labels in MASM32
- Prev by Date: Having trouble posting?
- Next by Date: Re: varargs in C (AMD64 architecture)
- Previous by thread: Uniform spacing of labels in MASM32
- Next by thread: Re: Uniform spacing of labels in MASM32
- Index(es):