Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > CALL to label without another reference crashes

Reply
Thread Tools

CALL to label without another reference crashes

 
 
ReavenK@gmail.com
Guest
Posts: n/a
 
      05-17-2006
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?

 
Reply With Quote
 
 
 
 
jjf@bcs.org.uk
Guest
Posts: n/a
 
      05-17-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      05-17-2006
(E-Mail 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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
pemo
Guest
Posts: n/a
 
      05-17-2006
(E-Mail Removed) wrote:
> 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.

--
==============
Not a pedant
==============


 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      05-17-2006
pemo wrote:
> (E-Mail Removed) wrote:
>> 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


<snip>

> 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?
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
 
Reply With Quote
 
pemo
Guest
Posts: n/a
 
      05-17-2006
Flash Gordon wrote:
> pemo wrote:
>> (E-Mail Removed) wrote:
>>> 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

>
> <snip>
>
>> 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.


--
==============
Not a pedant
==============


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
James Gosling the Creator of EMACS and JAVA - leaves ORACLE - Butthen reports started coming in of odd failures. Systems would crashstrangely. We'd get crashes in applications. All applications. Crashes in thekernel. small Pox C Programming 2 07-22-2010 10:07 PM
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
How to get/read Hard disk label / drive label Praveen Python 1 11-05-2006 07:48 PM
<label><div></div></label> allowed? Josef K. ASP .Net 3 05-22-2005 02:13 PM
label versus asp:label Question. Thanks. Shapper ASP .Net 2 05-07-2005 05:55 AM



Advertisments