Naresh
Naresh

Reputation: 678

How to understand the bytes in the executable and relate to load of program into memory?

The following is close to my question, still I have a missing link, that would help me understand the loading process.

How does DOS load a program into memory?

My question is "what will happen in machine step by step when I type mf.com in commandline?"

I am using windows 7 and I have installed NASM for compiling. The following is the assembly that I got in one of the website

The filename is mf.asm


org 100h

mov dx, msg mov ah, 9

int 21h ret

msg db "Hello, world !$"


I used the following command to get My mf.com file

nasm -f bin mf.asm -o mf.com

Now, I run the mf.com by typing

mf.com

I get the result Hello, World !$

I opened the mf.com binary in textpad and its shown like this.


   0: BA 08 01 B4 09 CD 21 C3  48 65 6C 6C 6F 2C 20 77  ********Hello, w
  10: 6F 72 6C 64 20 21 24                              orld !$

The ******** were the respecive characters tha was showed in the text editors.

what will happen in machine step by step when I type mf.com in commandline and hit enter? especially "BA 08 01 B4 09 CD 21 C3" how would this 8 bytes be used?

Upvotes: 1

Views: 352

Answers (2)

Jesus Ramos
Jesus Ramos

Reputation: 23266

Those are the bytes that represent the instruction's themselves, Prefix bytes (up to 4 I believe), primary opcode (1 or 2), optional MODRM and SIB bytes, displacement bytes, and finally the immediate operands (if any). The machine interprets those bytes depending on the prefix and the primary opcode of the instruction. If you really want to find out you can find tables that show you what those are in binary.

Processors don't interpret the instructions as mnemonics, the mnemonics are only their so it's easier for you to write the code. These mnemonics are changed by the compiler into something the computer can understand which is bytecode or raw binary data. The hardware takes over from that point.

Upvotes: 1

Madhur Ahuja
Madhur Ahuja

Reputation: 22709

The characters BA 08 01 B4 09 CD 21 C3 48 65 6C 6C 6F 2C 20 77 are machine code. They would be translated into assembly instructions. From your program, they are the translation of the following code:

mov dx, msg mov ah, 9

int 21h ret

So, in a nutshell those 8 bytes cause MOV and INT instructions to be executed in your processor. The MOV instructions copies the address of memory location in DX register which contains the string "Hello World !$".

Upvotes: 1

Related Questions