Skip to content

Hello, world!

Let’s dive right in and start off with the very original, and super unique, “Hello, world!” program.

What’s going on here though?

Now that you’ve seen a little bit of assembly, let’s break down the individual parts of this program.

Breaking it down

First, let’s start with line 1:

lea r0, hello_start

We can dissect this line into 3 parts.

The first word here is the operation.

lea

The left hand side (LHS) is the first operand.

r0

And lastly, the right hand side is the second operand.

hello_start

But what does this mean?

Every machine is capable of executing instructions. These instructions manipulate the different components of the machine in simple and basic ways.

Each instruction is composed of the operation and operands, with the operation specifying what to do and the operands specifying what to do it with.

This instruction in particular is known as the Load Effective Address instruction.

When the CPU encounters this, what actually happens is a memory address (not the value at an address) is loaded into a register.

In this case, the memory address of a label - we will talk about what labels are later - is loaded into register 0.

What about the next line?
lea r1, hello_end

Similar to the first line, this performs a Load Effective Address instruction to load the memory address of hello_end into register 1.

Labels

A label is a symbolic location that is defined with label_name: (e.g. fish:)

At compile/assemble time, labels are resolved to real memory addresses, and when an instruction references the address of a label (such as with label_name), it is replaced with the address of the label.

Here, we are defining hello_start and hello_end, and the ASCII string in between them essentially says “Put a string in memory here”.

hello_start references the first character of the string, and hello_end references the end of the string block.

But what are .asciiz and .word?

.asciiz and .word are assembler directives that tell the assembler to simply load the memory address(es) where the directive appears with the ASCII values of a string or with a numeric literal.

.word will accept a numeric value, whilst .asciiz accepts a full string.

What is a “word”?

Computer architecture has a concept known as a “word”, and “word”s are fixed size units of data for processing.

In BELLE, and other architecures, words are 16 bits in length. Thus, when you declare a .word, it simply assigns 16 bits of memory with the given data inside of it.

Here,

.word 10

Means to load a numeric 10 into the memory address it resides at. This is also the newline character

The next line

int 8

In many languages, int is used to declare integers. However, in many assembly languages, int actually means interrupt.

What are interrupts?

An interrupt in assembly essentially “pauses” the program (or “interrupts” it), to perform some task, and then return to the program execution.

Many CPU architectures and instruction sets have regions of memory that contain code to be executed upon an interrupt call.

For BELLE, the interrupts are not implemented as blocks of code on the machine’s memory, and instead are part of the software.

What is the ‘8’?

Each interrupt call is assigned a given interrupt code. In many other ISAs, the interrupt code is held in some register when the interrupt is called.

But, in the BELLE-ISA, interrupts are generated with their respective code in the instruction to avoid having to read a register.

In this case, interrupt 8 is the code to “Print all values from the memory address in r0 to the memory address in r1 as ASCII characters.

Concluding

Lastly, the program has a

hlt

To tell the CPU to stop execution.

So, there you have it! Your very first “Hello, world!” program for the Big Endian, Low Level Emulator. Try to change some text or some instructions and see what happens. The interactive box is fully interactive, so all parts of the assembler and emulator work just fine in every instance that you’ll see it.

Now, let’s have a look at moving data on the next tutorial.