Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Converting Instructions to OpCode?

AidmanAidman Posts: 15Member
Hi, all :)

Where can I find a tool/program that converts/encodes single assembly instructions (including 32 bit operands) to opcode (machine/byte code)? I know I can simple compile an assembly source code, but the compiler will then include other data which I am not interested in.

Thanks in advance

Aidman over and out

«1

Comments

  • Josh CodeJosh Code Posts: 675Member
    : Hi, all :)
    :
    : Where can I find a tool/program that converts/encodes single assembly instructions (including 32 bit operands) to opcode (machine/byte code)? I know I can simple compile an assembly source code, but the compiler will then include other data which I am not interested in.
    :
    : Thanks in advance
    :
    : Aidman over and out

    The assembler shouldn't include other data in the program unless you use includes in your source code. If you assemble com programs(pure machine code) with MicroASM(http://www.emu8086.com/asm/), MyAssembler(software section on www.bmts.com/~gdonald), FASM(http://fasm.sourceforge.net/fasm.html)... no other data is added to the program file, just purely your code.

    EXE files use other data in the header section. The format is more complicated and requires that extra data other than just machine code be included in the file.
  • AidmanAidman Posts: 15Member
    : The assembler shouldn't include other data in the program unless you use includes in your source code. If you assemble com programs(pure machine code) with MicroASM(http://www.emu8086.com/asm/), MyAssembler(software section on www.bmts.com/~gdonald), FASM(http://fasm.sourceforge.net/fasm.html)... no other data is added to the program file, just purely your code.
    :
    : EXE files use other data in the header section. The format is more complicated and requires that extra data other than just machine code be included in the file.
    :

    I tested all of the assemblers above but only one, the FASM, accepted instructions with 32 bit registers. But for some strange reason it changed them to 16 bit when compiled to .com files.
    Could I have missed somthing or doing somthing wrong?

    Aidman over and out
  • Josh CodeJosh Code Posts: 675Member
    : : The assembler shouldn't include other data in the program unless you use includes in your source code. If you assemble com programs(pure machine code) with MicroASM(http://www.emu8086.com/asm/), MyAssembler(software section on www.bmts.com/~gdonald), FASM(http://fasm.sourceforge.net/fasm.html)... no other data is added to the program file, just purely your code.
    : :
    : : EXE files use other data in the header section. The format is more complicated and requires that extra data other than just machine code be included in the file.
    : :
    :
    : I tested all of the assemblers above but only one, the FASM, accepted instructions with 32 bit registers. But for some strange reason it changed them to 16 bit when compiled to .com files.
    : Could I have missed somthing or doing somthing wrong?
    :
    : Aidman over and out
    :

    The thing is, some 32-bit instructions use the exact same machine code as 16-bit instructions. It just executes as a 32-bit instruction if the processor is in a 32-bit mode.

    for example,
    [code]
    [b]mov[/b] ecx,ebx ; 32-bit instruction, machine code = db 8Bh, CAh
    [b]mov[/b] cx,bx ; 16-bit instruction, machine code = db 8Bh, CAh
    [/code]

    As far as I know, com programs can only run in 16-bit mode. I'm not sure but I think with 32-bit exe files, there is a prefix used before every 16-bit instructions to indicate that the instruction is to be executed in 16-bit mode.
  • angelusMortisangelusMortis Posts: 141Member
    you mean 66h. if its a 32-bit instruction then 66h must precede the opcode.
  • AidmanAidman Posts: 15Member
    [b][red]This message was edited by Aidman at 2003-7-6 10:42:42[/red][/b][hr]
    But isn't there a program or tool that simply converts an assembly ascii 32 bit instruction (like: "move eax, ebx") to its binary opcode/machinecode (hex: 8B C3)? If not, where can I find the necessary documentations on how to convert 32 bit instructions?

    Aidman over and out
  • Josh CodeJosh Code Posts: 675Member
    : [b][red]This message was edited by Aidman at 2003-7-6 10:42:42[/red][/b][hr]
    : But isn't there a program or tool that simply converts an assembly ascii 32 bit instruction (like: "move eax, ebx") to its binary opcode/machinecode (hex: 8B C3)? If not, where can I find the necessary documentations on how to convert 32 bit instructions?
    :
    : Aidman over and out
    :

    Why do you want to do this?
    There aren't any tools for it that I know of. It would be easy to make, though. The reason why there aren't toold to output machine code in hexidecimal text is not many people would use it. I don't know why anyone would.

    There are several open source assemblers. They would have procedures built in to do things like that. How would you use a tool like this and why?
  • BitdogBitdog Posts: 528Member
    Isn't there a program or tool that simply converts an assembly ascii 32 bit instruction (like: "move eax, ebx") to its binary opcode/machinecode (hex: 8B C3)? If not, where can I find the necessary documentations on how to convert 32 bit instructions?
    Aidman over and out

    [green]
    The Nasm assembler I uses to makes 32 bit code.
    Make an asm file and assemble to a .com file
    The header allows 32 bit or 16 bit code. 16 bit is default.
    The header looks like this: (following is one line of code)

    BITS 32
    ORG 100h

    MOV EAX,0xFFFFFFFF


    ;that is all that is required to assemble to .com
    JUST THE MACHINE LANGUAGE of the line of code you wrote.

    I have made such a creature, and it's in
    C:
    asmstuffcodeinfo
    C:
    asmstuffmachcode
    directorys in my
    http://bitdog.home.att.net/files/nasmenv.zip
    it's free, & ready to go to work.
    (Plenty of flaws included also.)

    I hope that helps somehow.
    Bitdog
    [/green]

  • AidmanAidman Posts: 15Member
    [b][red]This message was edited by Aidman at 2003-7-6 19:49:57[/red][/b][hr]
    Thanks Bitdog, that worked.

    The reason I need a tool (that converts instructions to their opcode) is becouse I want to load the bytecodes (from a series of instruction) into a variable array in my experimental C++ program, where it is supose to execute those codes. And I also don't want any inline assembly, becouse I want the bytecodes to be variable, so they can be loaded during runtime. But I have heard this type of executation (mixing code and data) is risky, why is that?

    Aidman over and out


  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : [b][red]This message was edited by Aidman at 2003-7-6 19:49:57[/red][/b][hr]
    : Thanks Bitdog, that worked.
    :
    : The reason I need a tool (that converts instructions to their opcode) is becouse I want to load the bytecodes (from a series of instruction) into a variable array in my experimental C++ program, where it is supose to execute those codes. And I also don't want any inline assembly, becouse I want the bytecodes to be variable, so they can be loaded during runtime. But I have heard this type of executation (mixing code and data) is risky, why is that?
    :
    : Aidman over and out
    :
    :
    :
    [blue]I think any debugger can do what you want - at least I use sometimes Turbo Debugger 5.5 from Borland (it is a free download) - this one can do it easily. Open any EXE file in that tool and start typing something while focus in CPU panel - you will see how the instruction you typed changes that CPU panel and the code immediately disassembled.

    Mixing code and data is only risky if you have bugs in your code.[/blue]
  • BitdogBitdog Posts: 528Member
    --(Previous Message)--
    : Thanks Bitdog, that worked.
    :
    : The reason I need a tool (that converts instructions to their opcode) is becouse I want to load the bytecodes (from a series of instruction) into a variable array in my experimental C++ program, where it is supose to execute those codes. And I also don't want any inline assembly, becouse I want the bytecodes to be variable, so they can be loaded during runtime. But I have heard this type of executation (mixing code and data) is risky, why is that?
    :
    : Aidman over and out

    [green]
    Well, I'm no expert and all,
    BUT, what I found is:
    Some insterted machine code like bytes from a com file
    are not risky, and some are because they vary.
    Code that: MOV AX,BX ; is variable because BX is unknown
    but some things are constant, like: a cold boot or a warm boot
    code assembled and insterted as NAME DB ???????
    I have a warm & cold boot code insertion as a %define NAME DB ???????
    in one of those directories.
    The code in warm/cold boot is always the same and does NOT rely on
    the surounding code to be this or that so it works every time.

    Another way to do what you want is macro's in assembly,
    they are just a group of instructions,
    you're grouping your instructions in an .asm to .com
    and using the assembled code as NAME DB (code bytes here)
    They are both about the same actually ?
    Well I'm rambling now, so good luck at yer project.

    Bitdog
    [/green]

«1
Sign In or Register to comment.