Thread: direct insertion of opcodes into an __asm field

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195

    direct insertion of opcodes into an __asm field

    I have some opcodes that I need to directly insert into the instruction sequence of an __asm section. The reason for this is that VC++ 6.0 doesnt seem to recognize the specific opcode in question. So what I wanted to do was directly insert the appropriate bytes as DB 0x00 statements. My question is, will the compiler leave them in the order and placement so that they translate into instructions, or will it attempt to 'optimize' them and move them around?


    example:
    Code:
    fld Val1;
    fld Val2;
    db  0xde 0xc9 ; // direct encoding of the FMULP instruction

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    It should "do what you mean".

    AFAIK, given
    statement1 ; asm ; statement2;
    any optimisation which could cause code to move between statement1 and statement2 is not made. Some compilers play safe and just leave the whole function "as is".

    If possible, you get the best results if you confine any asm to a small C 'wrapper' function, which contains only the asm code, and the bare minimum necessary to supply it with parameters and return the result. Any downgrading of optimisation, and/or side effects of code motion say would be minimised.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    DB isnt valid for visual studio. the "_emit" statement should do what you want.

    If you are worried about VS messing with your opcodes, why not create the module in MASM and link it in.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by Fordy View Post
    If you are worried about VS messing with your opcodes, why not create the module in MASM and link it in.
    What you said sounds really cool how do I do it? (heh, im not really that much of a nub). My previous assembly experience is limited to the 8086, various sundry microcontrollers, and the asm section in VS. Part of the problem is that I use VS 6.0 at work and I have 4.0 at home. 4.0 doesnt support all of the newer opcodes, so I wanted to directly code those few directly. I havent had a standalone assembler since the TRS-80. I limit my assembly to a few critical areas that can really benefit from direct coding.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    First of all downloand MASM32 (http://www.masm32.com/), and have a play.

    Your objective is to create an obj file with your procedure, then get visual studio to link it into a current project - I havent done this myself for years, but it is certainly possible.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for a little assistance with item class design...
    By Raigne in forum Game Programming
    Replies: 5
    Last Post: 10-22-2008, 08:55 AM
  2. Please critique and suggest improvements for parser
    By Queue in forum C Programming
    Replies: 14
    Last Post: 09-28-2006, 08:28 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM