Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

baskuenen

Forward References in MSVC

This topic is 6926 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey programmers, I''ve a little problem with forward references in Microsoft Visual C. I''m using some inline assembly with labels. I want to use these labels in a C array. Here''s a practical example: (the reduced code) const int jmptbl[3] = { jmp0, jmp1, jmp2 }; __asm { ... mov ecx, width jmp jmptbl[ecx*4] jmp2: mov 2[edi],ah jmp1: mov 1[edi],ah jmp0: mov [edi],ah } After compilation you get the folowing errors: jmp2: undeclared identifier jmp1: undeclared identifier jmp0: undeclared identifier Using labels before declaring the label gives an error. With TASM this was resolved using: "Allow multiple passes to resolve forward references" THE QUESTION IS: - Does MSVC have a compiler setting? (incremental linking isn''t it!) - Is there a pragma for this? - How can I solve this? Any answer is respected. Maybe it can give a lead to the answer... Bas.

Share this post


Link to post
Share on other sites
Advertisement
I think you can''t use labels which are inside the assembly part in the other parts of you program.

Visit our homepage: www.rarebyte.de.st

GA

Share this post


Link to post
Share on other sites
That''s the first I thought,

But you can use goto to jump to inline assembly labels!

The bigger problem is refering to vars/labels that have not been declared yet.

(I''ve tried implementing the array in inline assembly...???...can''t implement label refs in asm...!!!...???) (used: dd jmp0,jmp1,jmp2)

Thanx for response,
Bas.

Share this post


Link to post
Share on other sites
MSVC GURU'S?

multiple passes to resolve forward references
Microsoft Visual C compiler


If these words say any thing to you...PLEASE HELP,
Point me in any direction! Any reply respected!
Can't continue right now...

Edited by - BasKuenen on 5/7/00 6:05:41 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m not sure if this will work, but it should solve the problem of forward declarations.


#define JUMP(index) goto jmp##index

....

const int jmptb[3] = {0, 1, 2}

....

JUMP(width<<2)

jmp2:
__asm {
mov 2[edi],ah
}
jmp1:
__asm {
mov 1[edi],ah
}
jmp0:
__asm {
mov [edi],ah
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
oops.... the JUMP(width<<2) should have a semicolon after it

Share this post


Link to post
Share on other sites
quote:
Original post by baskuenen


multiple passes to resolve forward references
Microsoft Visual C compiler




I think that one of the cornerstones of C/C++ is that it is a one-pass process, in so far as you have to declare all identifiers before using them. Whereas in many assembers, they do one pass to collect all the symbols, and then a second pass to set up everything that relies on those symbols. I am not sure you can force this in C.

It looks like you''re just simulating a switch statement, more or less. Why not write a very simple switch in C, and then disassemble it to see how it works?

Share this post


Link to post
Share on other sites
It''s a hard question, almost nobody has an answer for.
So first of all, thanx for your response!


Anonymous,
Without the jump table this will not work, but thanks anyway.


Kylotan,
I tried the switch statement and disassebled it. It looks like this:

; switch(width) {
; case 2: pScreen[2] = value >> 8; value += delta;
; case 1: pScreen[1] = value >> 8; value += delta;
; case 0: pScreen[0] = value >> 8; value += delta;
; }

jmp DWORD PTR $L31469[edi*4]
$L30904:
mov edx, ecx
sar edx, 8
mov BYTE PTR [esi+2], dl
add ecx, eax
$L30905:
mov edx, ecx
sar edx, 8
mov BYTE PTR [esi+1], dl
add ecx, eax
$L30906:
sar ecx, 8
mov BYTE PTR [esi], cl
$L30583:
...
ret


$L31469:
DD $L30906
DD $L30905
DD $L30904


You can see the extra instructions. Every step can be reduced to:
mov BYTE PTR [esi+x], ch
add ecx, eax


So...from this answer, a new question is born...
Is there a C(++) command to use these high byte registers?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!