CALL to label without another reference crashes

R

ReavenK

I was doing a tutorial on inline assemble tricks for C and C++ when I
came upon a little detail that I can't figure out. I was doing a test
program to test out a concept which seems like it should flat out work,
but of course doesn't in a certain circumstance.

I get this error ...

Unhandled exception at 0x004000be in Demo.exe: 0xC0000096: Privileged
instruction.

when I run:

void main()
{
goto Label2;
Label:;
_asm RET
Label2:;
_asm CALL Label
return;
}

....but if I do...

void main()
{
if(0)
_asm JMP Label
goto Label2;
Label:;
_asm RET
Label2:;
_asm CALL Label
return;
}

... Then it works like I would expect. In fact, all I have to do is
somewhere mention the label again using a JMP , even if it's never
called. I looked as the dissassembly Visual Studio 2003 outputed for
the label is completely wrong unless I mention the label
somewhere/anywhere else.

so this also works...

void main()
{
goto Label2;
Label:;
_asm RET
Label2:;
_asm CALL Label
return;
_asm JMP Label;
}

any ideas? Some compiler standard I don't know about or a bug in the
compiler?
 
J

jjf

I was doing a tutorial on inline assemble tricks for C and C++ when I
came upon a little detail that I can't figure out. I was doing a test
program to test out a concept which seems like it should flat out work,
but of course doesn't in a certain circumstance.

I get this error ...

Unhandled exception at 0x004000be in Demo.exe: 0xC0000096: Privileged
instruction.

when I run:

void main()
{
goto Label2;
Label:;
_asm RET
Label2:;
_asm CALL Label
return;
}

...

This isn't anything to do with the C language. The _asm keyword must be
an extension implemented by whatever compiler you are using. You'd be
best to ask about this in a newsgroup which discusses the compiler and
platform you are using.
 
R

Richard Heathfield

(e-mail address removed) said:
I was doing a tutorial on inline assemble tricks for C and C++

Before you write a tutorial about C, it might be a good idea to learn it.
 
P

pemo

I was doing a tutorial on inline assemble tricks for C and C++ when I
came upon a little detail that I can't figure out. I was doing a test
program to test out a concept which seems like it should flat out
work, but of course doesn't in a certain circumstance.

I get this error ...

Unhandled exception at 0x004000be in Demo.exe: 0xC0000096: Privileged
instruction.

when I run:

void main()
{
goto Label2;
Label:;
_asm RET
Label2:;
_asm CALL Label
return;
}

...but if I do...

void main()
{
if(0)
_asm JMP Label
goto Label2;
Label:;
_asm RET
Label2:;
_asm CALL Label
return;
}

.. Then it works like I would expect. In fact, all I have to do is
somewhere mention the label again using a JMP , even if it's never
called. I looked as the dissassembly Visual Studio 2003 outputed for
the label is completely wrong unless I mention the label
somewhere/anywhere else.

so this also works...

void main()
{
goto Label2;
Label:;
_asm RET
Label2:;
_asm CALL Label
return;
_asm JMP Label;
}

any ideas? Some compiler standard I don't know about or a bug in the
compiler?


The following - which is only a slight mod of your first piece of code
[which also ran fine] runs ok for me when using cl version 12.00.8804.

#include <stdio.h>

int main(void)
{
goto Label2;

Label:

puts("pre _asm RET");
_asm RET

Label2:

puts("pre _asm CALL Label");
_asm CALL Label
puts("post _asm CALL Label");

return 0;
}

I /think/ you've nul statements after your labels btw, i.e., the ';' aren't
needed.

Conclusion ... dunno.
 
F

Flash Gordon

The following - which is only a slight mod of your first piece of code
[which also ran fine] runs ok for me when using cl version 12.00.8804.

#include <stdio.h>

int main(void)
{
goto Label2;

Label:

puts("pre _asm RET");
_asm RET

<snip>

Strangely enough, neither compilers on my system. Possibly this is
because it isn't actually C but some compiler specific extension?

pemo, you have been around here long enough to know we only deal with
standard C not code that has very little to do with C.
Conclusion ... dunno.

If you don't know, why bother posting at all?
 
P

pemo

Flash said:
The following - which is only a slight mod of your first piece of
code [which also ran fine] runs ok for me when using cl version
12.00.8804. #include <stdio.h>

int main(void)
{
goto Label2;

Label:

puts("pre _asm RET");
_asm RET

<snip>

Strangely enough, neither compilers on my system. Possibly this is
because it isn't actually C but some compiler specific extension?

pemo, you have been around here long enough to know we only deal with
standard C not code that has very little to do with C.
Conclusion ... dunno.

If you don't know, why bother posting at all?

True - it's OT, and for that I apologise.

Still, I would like to find out what the OP's problem was/is due to ... I
v.rarely use assembly in any of my code [possibly once every 10 years or
so], but I guess I'm just curious.

Still nuff said - it's OT.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top