“Hello, World!” in Assembly (NASM)

Prerequisites

The Netwide Assembler (NASM) will need to be installed on the host. NASM is an assembler and disassembler for the Intel x86 architecture.

sudo apt-get install nasm

Getting started

Once NASM has been installed, create a new file with the below code and save as ‘hello-world.nasm’:

global _start

section .text

_start:

mov rax, 1
mov rdi, 1
mov rsi, hello_world
mov rdx, length
syscall

section .data

hello_world: db 'Hello, World!', 0xa
length: equ $-hello_world

For the example above, the ‘global _start’ is the global directive in NASM for declaring the entry point in the object code. The next line ‘section .text’ contains the actual machine instructions and declares the entry point of your program with ‘_start:’. The next line of code takes the integer value of 1 for the source address, and moves (mov) this in to the CPU general purpose register RAX (64-bit accumulator) as the destination address stored in memory. It is worth noting that the integer value of 1 here, is the argument used for the write syscall function. We can check this by grepping for the write syscall:

$ cat /usr/include/x86_64-linux-gnu/asm/unistd_64.h | grep write

This will show the write syscall functions (API syscalls from user mode in to kernel mode):

#define __NR_write 1
#define __NR_pwrite64 18
#define __NR_writev 20
#define __NR_pwritev 296
#define __NR_process_vm_writev 311
#define __NR_pwritev2 328

The remaining lines of code continue with moving the data between the source and destination addresses in memory to the general purpose registers, before calling ‘syscall’. Under ‘section .data’, this contains anything that you want to be automatically initialized by the system before it calls the entry point of your program.

For the next step after creating the file, is to assemble and link the object code for the ‘Hello World.nasm’ assembly file. To assemble, use the following command:

nasm -felf64 "hello-world.nasm" -o "hello-world.o"

To link the object code, use the following command:

ld "hello-world.o" -o "hello-world"

Finally, to execute the assembled and linked object code, run the following command:

./"hello-world"

Create Executable Python Script with PyInstaller

PyInstaller for Python can be used to create a standalone executable from a Python script.

To create the executable, Python must be installed on the local host. Python can be obtained from here. Currently as of 2018, there is Python versions 2 and 3 available to download.

Before proceeding with the environment setup, test that the pip libraries have been installed with your Python installation with the following command in the Python interpreter:

pip

This will show the command results for the pip command. For any errors with running the pip command, pip may need to be downloaded and installed manually.

Next step is to install PyInstaller. This is done by using the following command within the Python interpreter:

pip install pyinstaller

For PyInstaller on Windows environments, PyWin32 might be required and can be found here

To test Python is running in your environment, test your Python script with the following command:

python your_script.py

Once PyInstaller has been installed, within your Python script directory, the following command can be used with your Python script to create the standalone executable:

pyinstaller --onefile .py

For any other issues with installing or running pip, PyInstaller or Python scripts, you may need to set up your PATH environment variables within your operating system.

Programming Languages

Python
Paradigm: Object-oriented, imperative, functional, procedural, reflective
Typing discipline: Duck, dynamic, strong

Ruby
Paradigm: Multi-paradigm: Object-oriented, imperative, functional, reflective
Typing discipline: Duck, dynamic, strong

C
Paradigm: Imperative (procedural), structured
Typing discipline: Static, weak, manifest, nominal

C++
Paradigm: Multi-paradigm: procedural, functional, object-oriented, generic
Typing discipline: Static, nominative, partially inferred

C#
Paradigm: Structured, imperative, object-oriented, event-driven, task-driven, functional, generic, reflective, concurrent
Typing discipline: Static, dynamic, strong, safe, nominative, partially inferred

Perl
Paradigm: Multi-paradigm, functional, imperative, object-oriented (class-based), reflective, procedural, event-driven, generic
Typing discipline: Dynamic

Java
Paradigm: Multi-paradigm: object-oriented (class-based), structured, imperative, generic, reflective, concurrent
Typing discipline: Static, strong, safe, nominative, manifest

PHP
Paradigm: Imperative, functional, object-oriented, procedural, reflective
Typing discipline: Dynamic, weak

Installing Tk on Windows for Python

ActiveTcl is a precompiled distribution of the open source Tcl language. Tcl includes the Tk extension libraries for Python.

  • Install the “ActiveTcl” distribution from ActiveState – Link
  • Download the Community Edition of ActiveTcl for Windows
  • Run and complete the installer for the Community Edition of ActiveTcl for Windows
  • After the installer completes, assuming the default directory was used for installation, verify ActiveTcl has installed correctly by opening a Command Prompt window and typing C:\ActiveTcl\bin
  • An on-screen Tcl window will be displayed. This can be closed and confirms successful installation of ActiveTcl.