Radheshyam Nayak
Radheshyam Nayak

Reputation: 1068

how a source code is converted into 1's and 0's?

computers do not understand anything except one's and zero's.But I want to know the details how a source code or an instruction set is converted into 1's and 0's.Is the exe file only contains 1's and 0's?

Upvotes: 5

Views: 8700

Answers (4)

Mark Cidade
Mark Cidade

Reputation: 99957

Each type of operation in a microprocessor's instruction set is specified by an opcode, which is represented as a pattern of 1s and 0s. A compiler or interpreter translates code in a source language to machine code made up of those instructions.

For example, take this code, where a variable, x, is assigned the value of 50:

x = 50;

The compiler might translate that to the following assembly language, where the AX register (for the x variable) is set with the value, 50 (in hexidecimal), using the MOV instruction:

mov ax, 0x32

If the opcode for MOV was 0xA0 and the code for the AX register was 0xB then the machine code, in binary, would look like this:

10100000 00001011 00110010

Upvotes: 9

pedromcaraujo
pedromcaraujo

Reputation: 307

When you compile your code the compiler creates the equivalent in Assembly which then goes to the processor to run. The assembler does to job of converting the Assembly to binary.

Each high level instruction (in your programming language) as Assembly instructions associated to it. These Assembly instructions can be highly optimize (hence the GCC, and other compilers, optimization flags).

You might want to read http://computer.howstuffworks.com/bytes.htm

Upvotes: -1

Luca Matteis
Luca Matteis

Reputation: 29267

Yes. A .exe is in essence a binary file format which contains 0s and 1s (it also contains other important OS information for your program to run)

A CPU comes with specification of certain basic operations like SUM, MOV etc. These are the only operations the CPU knows about. The compilers job is to interpret something like 2 + 3 and convert it into something that the CPU can interpret (SUM and flags checking for overflow etc..).

So in essence writing high level code like 2 + 3 it's just a shorter way of writing lots of assembly code (which is just a human readable version of binary).

Upvotes: 3

Chris Thompson
Chris Thompson

Reputation: 35598

You need to research Compilers

Upvotes: 4

Related Questions