CALL to label without another reference crashes

Discussion in 'C Programming' started by ReavenK@gmail.com, May 17, 2006.

  1. Guest

    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?
    , May 17, 2006
    #1
    1. Advertising

  2. Guest

    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.
    , May 17, 2006
    #2
    1. Advertising

  3. 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)
    Richard Heathfield, May 17, 2006
    #3
  4. pemo Guest

    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
    ==============
    pemo, May 17, 2006
    #4
  5. Flash Gordon Guest

    pemo wrote:
    > 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
    Flash Gordon, May 17, 2006
    #5
  6. pemo Guest

    Flash Gordon wrote:
    > pemo wrote:
    >> 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
    ==============
    pemo, May 17, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shapper
    Replies:
    2
    Views:
    722
    Scott Mitchell [MVP]
    May 7, 2005
  2. Josef K.

    <label><div></div></label> allowed?

    Josef K., May 20, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    13,305
    Josef K.
    May 22, 2005
  3. Praveen
    Replies:
    1
    Views:
    945
    Rob Williscroft
    Nov 5, 2006
  4. Tom Reilly
    Replies:
    0
    Views:
    77
    Tom Reilly
    Aug 20, 2007
  5. Knut Krueger
    Replies:
    8
    Views:
    253
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page