DEV Community

ANISHA SWAIN | The UI Girl
ANISHA SWAIN | The UI Girl

Posted on • Originally published at theuigirl.hashnode.dev on

How the computer understands programming languages…

THE BASIC GUIDE

They say that computer science is no more about computers then astronomy is about telescope.

A re you one of them who feels programming languages have made our life awful and you have no clue how to understand them like computer does? Then you are at the right place. Grab a cup of coffee and enjoy learning about basics of programming languages with each sip.

They say that computer science is no more about computers then astronomy is about telescope. True that we cant explore the higher aspects of it without venturing into the elemental ones.

Note: All the answers are designed to explain the basics in the most basic and simple way possible..

What is a programming language?

A programming language is a formal language for us. It helps us to communicate with the computer and ask it for our desired output. Programming languages consist of a set to instructions that we give just like sentences or statements we say to another human being which communicating.

What are cryptic languages?

You see, cryptic means having a meaning that is mysterious or not discovered. So in case of programming languages, low-level code are often cryptic and not human-readable. For example assembly language and machine language which is kind of mysterious because you wont understand anything just by reading it (unless you are already familiar with it).

For example:

in Java, the addition of two numbers:

int a = 12;

int b = 17;

int c = 342;

int d = a + b + c;

System.out.println(Addition result = + d);

but in assembly: (for 8086)

data segment

a db 09h

b db 02h

c dw ?

data ends

code segment

assume cs:code,ds:data

start:

mov ax,data

mov ds,ax

mov al,a

mov bl,b

add al,bl

mov c,ax

int 3

code ends

end start

One can interpret the meaning of the code just by looking at it in case of Java but it is difficult in case of assembly. So we can say that it is more cryptic.

But, what does a computer understand?

The only language that the computer can process or execute is called machine language. It consists of only 0s and 1s in binary, that a computer can understand. In short, the computer only understands binary code, i.e 0s and 1s.

And, what do we give to a computer?

What we give to our computer is a programming language which is more in a human-readable format. This type of languages consists of English keywords and convenient to remember. These are called Hight-Level Languages. For example, C, C++, Java, Python, JavaScript etc.

If a computer only understands binary code, then how it understands HLL(High-Level Languages)?

Simple, it converts High-Level Languages to its understandable format(machine/object code).

What is object code?

When you have a Java program and you run in, you give that program to the compiler(a program that converts the code you gave into a machine-code, binary (1s and 0s) code that can be executed directly by the CPU) and the compiler will produce the output in assembly code, which is still human-readable, but the machine cant read). Now, that assembly code will go into the assembler and assembler is going to produce you some code. That is known as Object Code(which is a portion of machine code*)*. Now, Machine code is binary (1s and 0s) code that can be executed directly by the CPU, in other words, now your computer understands what you are saying it.

See the process here:

Note: When you compile (or, run) a program, usually then you are not going to use both compiler and assembler. The compiler is actually compiler+assembler+loader+linker which converts your readable code to machine-readable code.

How can the user give machine code to computer?

Well yes, you can give direct machine code to computers, but your code will be just 0s and 1s. And by computers, I mean microprocessors(It is an Electronic device which acts like CPU), not the usual laptops or desktops you are familiar with. Mostly microprocessors take data input in assembly though.

For example, see the Microprocessor Trainer Kit (8085) below:

What is assembly level language?

An assembly language is a low-level programming language designed for a specific type of processor.

What is the difference between assembly level language and machine language?

Machine language is a language that deals with only binaries(0s or 1s). It is directly executed by the computer as it is in a machine-readable format. Assembly language is a low - level programming language that requires a software program called an assembler to convert it into machine code(0s and 1s format).

What are machine-dependent languages and machine-independent languages?

Machine dependent language is a language which only a particular type of machine can understand. If we change the machine and run the same code, then the new machine might not interpret the code or produce a different output. For example, machine code or Embedded System programs(programs used for washing machine or traffic control system etc.). Machine Dependent languages are used in scenarios where portability is useless.

But, Machine independent language is the one which can run on any machine and gives the same output no matter what is the operating system. For example in Java, because of JVM( Java Virtual Machine), it recognizes Java compiled code and then makes it suitable to run on any OS it is running on. So the JVM makes the Java code Machine Independent.

A true machine-independent language would produce exactly the same output no matter which computer or Operating System it was run on.

What is the basic structure of Assembly Language?

Assembly language is just another programming language that again has its own syntax for writing down instructions. A good tutorial for understanding Assembly might be TutorialsPoint or this.

But, every assembly language instruction contains an opcode and an operand. The opcode is the action that is executed by the CPU and the operand is the data or memory location used to execute that instruction.

For example,

MOV A, 2H ; // MOV in the action/mnemonics and A, 2H is the operand

What are the mnemonics and opcodes?

We program a microprocessor in assembly language. Now lets see first how to write a simple assembly language in the 8085 microprocessor.

Some stuff to consider before that is,

  • A microprocessor executes instructions given by the user in a language understood by the microprocessor.
  • Microprocessor understands the language of 0s and 1s only, which is called Machine Language. (Same as usual computers)
  • For e.g. 01001111Is a valid machine language instruction of 8085
  • It uses English keywords to represent an action, which is called Mnemonics. For example, MOV: Transfer of Data, ADD: Add two values, SUB: subtract two values

Now, Assembly language program to add two numbers

MVI A, 2H ; Copy value 2H in A

MVI B, 4H ; Copy value 4H in B

ADD B ; A = A+B

Here in the code MVI is the mnemonics which represents the action Move Immediate.

Now, the Opcode stands for Operational Code which says us how the instructions(or mnemonics) get stored in computer memory(every mnemonics reserve some space memory in byte form). It is a number understood by your machine that says your computer which operation to perform. Now the problem is very absurd to remember the opcode for every instruction so we use mnemonics instead.

In other words, each opcode has a human-understandable nickname, which is mnemonics. For Example:

Instruction: MOV B,A

Mnemonics- MOV

Opcode- 0xb8

Operand- B, A

Hex Code- 47H

Binary code- 0100 0111

What do you mean by software architecture of the computer?

Software architecture refers to the fundamental structures of a software system and the discipline of creating such structures and systems. It deals with the software components of the system and defines the inter-relation between them.

What do you mean by hardware architecture of the computer?

Hardware architecture refers to figuring out the hardware components which needs to be fit in the system and deals with their relationship with each other.

As per Wikipedia:

In engineering, hardware architecture refers to the identification of a systems physical components and their interrelationships. This description often called a hardware design model* , allows hardware designers to understand how their components fit into a system architecture and provide to software component designers important information needed for software development and integration. Clear definition of a hardware architecture allows the various traditional engineering disciplines (e.g., electrical and mechanical engineering) to work more effectively together to develop and manufacture new machines, devices and components.*

Special Note: Thanks Durga prasasd Kusuma and Ankit Nayak for helping me out with the reviews.

Top comments (0)