1
votes

So, upon many hours of research, I have come to the conclusion that I don't understand much.

  • Binary and Machine Code/Opcodes:

    Machine code is what is understood by the CPU, the machine code itself is made of pure binary correct?

    So take for example 000010 00000 00000 00000 10000 000000. This is machine code making a jump to 1024. This machine code is comprised of binary. Is that correct?

    000010 is an OPCode, a machine code instruction, made from binary, correct?

  • Assembly Language

    Assembly language provides mnemonics for OpCodes correct? So for 000010, the Assembler mnemonic is J or JMP correct?

    What does assembler assemble to? Does it produce raw machine code? What is the file extension for raw machine code? How is assembly executed?

  • Object Code/Object File

    Could someone explain what these are? Are these the output of assembly? Thanks all!

1

1 Answers

2
votes

Machine code is what is understood by the CPU, the machine code itself is made of pure binary correct?

Yes, but the opcodes vary from CPU to CPU.

An instruction of an Intel 80386+ architecture is compound with following bytes:

Instruction Prefix                0 or 1 Byte
Address-Size Prefix               0 or 1 Byte
Operand-Size Prefix               0 or 1 Byte
Segment Prefix                    0 or 1 Byte
Opcode                            1 or 2 Byte
Mod R/M                           0 or 1 Byte
SIB, Scale Index Base (386+)      0 or 1 Byte
Displacement                      0, 1, 2 or 4 Byte (4 only 386+)
Immediate                         0, 1, 2 or 4 Byte (4 only 386+)

Does it produce raw machine code?

Yes.

What is the file extension for raw machine code?

With Linux no file extension for executable is needed. But the file attribute for executable have to be set. With DOS we can use COM-files and they included only opcodes. Inside of EXE-files some more information for the OS how to start the executable.

How is assembly executed?

With the x86 architecture and after the power an self test of the PC hardware the bios is loading a boot sector from a bootdrive into the ram and start to execute the opcodes inside.

From the OS perspective the OS is loading an executable file from a known file system and start to execute the opcodes.

One part of a CPU are the CPU registers. And some of them are working as an address counter and they are pointing to a memory location where the next opcodes for executing are placed. If one of these opcodes finally is executed, then the address counter is moving forward to the next opcode...and so on.