Mind blowing journey
Published: 2023-05-13 10:49:06

## Warning. You must have a linux distribution to follow this post

**TOC:**

Pseudocode
Executable (Binary machine code)
Scripts - Bash script (text file) -
Assembler -Netwide Assembler (NASM) -
programming language - C language - 
programming language - C++ language -
programming language - Java language -
programming language - Python -


### Pseudocode

Pseudocode is a plain language description of the steps in an algorithm. It is intended for human reading.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1r5m2ph8np2650lf91o9.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enb21axiz0bpn4oe5o3y.png)

```
Algorithm Sum
Var
	Sum = 0
Begin
	Read a, b
	Sum = a + b
	Write Sum
End
```

### Executable (Binary machine code)

Machine code instructions for a physical CPU.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pi0gr4d29z0ww2qw20xn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fc1jcy7ebvjre28mawx.png)

**EXE** is a common filename extension denoting an executable file for Microsoft Windows


**ELF**: The Executable and Linkable Format is a common standard file format for executable files, object code, shared libraries…. 

If you run the command **file** you will get information about the executable. Try the following:

`file /usr/bin/ls` (Please, pause and try it!)

“ls” is a command but it is also executable program  (ELF)

To display file headers of an elf file:


`readelf -h /usr/bin/ls` (Please, pause and try it!)

**Magic numbers** is the name given to constant sequences of bytes (usually) at the beginning of files, used to mark those files as being of a particular file format. They serve a similar purpose to file extensions.
	
How to see the executable inside?

`hexdump -C /usr/bin/ls | less` (Please, pause and try it!)

You could see what system calls are made using the command “strace”

`strace /usr/bin/ls | more` (Please, pause and try it!)


### Scripts - Bash script (text file)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4ichtgvi67w2xvvp7oa.png)

Follow the next steps:

1)`nano hello.sh`

2) Add the following code:

`#!/bin/bash
echo "Hello World"`

3) Set the script executable permission by running **chmod** command:

`chmod +x hello.sh`

4) Run or execute the script using following syntax:

`./hello.sh`

You can also do step 2 and 3 as follows: bash ./hello.sh

### Assembler -Netwide Assembler (NASM) -

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ru2ydtaxsmwsoxmxgq2w.png)

Let’s install NASM:

`sudo apt update
sudo apt install nasm`


The Netwide Assembler (NASM) is an assembler for the Intel x86 architecture. It can be used to write 16-bit, 32-bit and 64-bit (x86-64) programs.

List of available records:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a32h4xte5po6t4apa6zg.png)

We are going to use the following system calls:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49lrdqzulzqj52bvl78x.png)

1. nano hello.asm:

```
global    _start


          section   .text


_start:   mov  rax, 1      ; system call for write
          mov  rdi, 1      ; file handle 1 is stdout
          mov  rsi, message ; address of string to output
          mov  rdx, 13                 ; number of bytes
          syscall   ;invoke operating system to do the write
          mov  rax, 60                 ; system call for exit
          xor  rdi, rdi                ; exit code 0
          syscall        ; invoke operating system to exit


          section   .data
message:  db        "Hello, World", 10     
 ; note the newline at the end

```
Execute the following command:
 
`nasm -felf64 hello.asm && ld hello.o && ./a.out`

From the txt file called hello.asm an object file “hello.o” is created and then “ld” command creates an executable file “a.out” (ld, command to link object files)

To display file headers elf file:

`readelf -h ./a.out`

### Programming language - C language - 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aymhq3avec4kqkspliq9.png)

Let’s install compiler gcc:

```
sudo apt install build-essential
sudo apt install gcc 
gcc --version
```
gcc, 15 million lines of code in 2019 (it is one of the biggest free program)

Let's create a C program:

1. nano hello.c:

```
#include <stdio.h>

int main (void)
{
  printf ("Hello, world!\n");
  return 0;
}
```
2. `gcc -Wall hello.c -o hello2`

3. `./hello2`

### Programming language - C++ language -


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vdsb3vl1l5fu005lhns3.png)

Let's create a C program:

1) To install cpp compiler

```
sudo apt install g++
g++ --version
```

2) nano hello_cpp.cpp:

```
#include <iostream>

int main(int argc, char** argv) {
  std::cout << "Hello, world!" << std::endl;
  return 0; 
}

```

3) `g++ -Wall -pedantic -o hello2 hello_cpp.cpp`

4)` ./hello2`

### Programming language - Java language -


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/funy0kv53khs0y4ec3du.png)

Let's create a Java program:

1) Install jdk and jre:

```
sudo apt install default-jdk
sudo apt install default-jre

```
2) nano hello.java:

```
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!"); 
    }
}
```

3) `javac hello.java`

This creates a file called hello.class (it is in bytecode, which is code that can be executed by the Java VM).

4) `file HelloWorld.class ` (this command is optional, it is only for didactic purposes)
HelloWorld.class: compiled Java class data, version 55.0

5) `hexdump -C HelloWorld.class` (this command is optional, it is only for didactic purposes)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6srfnzt3fguau0vkg3b.png)

6) `java HelloWorld`
Output:
Hello, World!

## Programming language - Python -


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khyn1peoaqf8ksebj4ip.png)

Don't have python installed? Use the following script:

[](https://github.com/grafeno30/myscripts/blob/master/install_python3.sh)

Let's create a python program:

1) nano hello.py:
`print("Hello world!")`
2)`python3 hello.py`
Output:
Hello world!

Sources:

[](https://en.wikipedia.org/)

[](https://www.geeksforgeeks.org/readelf-command-in-linux-with-examples/)

[](https://www.linux.org/threads/how-to-read-a-executable-file-in-linux.7976/)