# Convert Machine code instruction (hex) into op code (binary)

• 09-19-2012
AlexTank853
Convert Machine code instruction (hex) into op code (binary)
Hi all sorry my first post was not about an problems in C, question will come relatively soon. I understand the mis categorized post and i apologize however i am stuck on this concept and thought i might see if anyone would be willing to help me understand :)

How would i convert Machine code instruction (hex) into a op code (binary)
ex. EBFFA -> op code (binary)
also how would i tell if it uses a register, and if it does which one, lastly how would i know if it includes an addressing mode (if it does which one?).

Any help would be so much appreciated, thanks for you time :)
• 09-19-2012
anduril462
Quote:

Originally Posted by AlexTank853
Hi all sorry my first post was not about an problems in C, question will come relatively soon. I understand the mis categorized post and i apologize however i am stuck on this concept and thought i might see if anyone would be willing to help me understand :)

We have a sub-forum for technical stuff that doesn't already have a specific home. Maybe a mod will move this to the Tech Board.

Quote:

How would i convert Machine code instruction (hex) into a op code (binary)
ex. EBFFA -> op code (binary)
Do you understand hex and binary conceptually? I mean, do you know that A(hex) = 10(decimal) = 1010(binary)? If you know the mapping of every hex digit to it's binary representation, then you're halfway there. You also should understand the difference between a number and it's representation. That is, if you say int x = 10;, x has the value ten. It exists in the computer in binary, due to the way hardware is, but from your point of view, it has no specific representation, it is just a value. It always has a value of 10, and you can print it out in any base (decimal, hex, octal) without changing it's value or the underlying representation in hardware.

Next, we need to understand what you mean by "hex", "binary" and convert? Where is the "hex" coming from? Where is the "binary" going? Are "hex" or "binary" actually text input/output from/to a user, and you need to convert "EBFFA" -> "11101011111111111010"? Or are you supposed to store the binary format in some number so you can write a binary file for the machine to execute? Or something else all together?

EDIT: I'm a little confused on your use of terms. "Machine code" usually refers to binary data that is the actual sequence of bits that comprise instructions for a given processor. The op-code is a part of each machine code instruction that tells the processor what to do (add, multiply, shift, compare, load, store, jump, etc).
Quote:

also how would i tell if it uses a register, and if it does which one, lastly how would i know if it includes an addressing mode (if it does which one?).
Depends on the architecture. What architecture is this for? Intel architectures are different from Motorola, ARM, etc. And no two Intel, etc. architectures are exactly the same either (though many architecture "families" are very similar, such as all x86 archs). You need to get your hands on the technical documentation for that architecture and look at all the op codes and instruction formats.
• 09-19-2012
Subsonics
A machine code instruction is an opcode, if your example ABFFA is a valid opcode if will run on the target architecture. Unless this is for educational/experimental purposes there is no need to convert it to binary as it will be stored in binary anyway, even if you are looking at a hexadecimal representation.