Skip to content

Reptile: The Assembler

Structure of the assembly code

Assembly code for our processor is composed of .code and .data sections. .code section will contain the variable declarations. These variables will be the operands for LDI instructions. A general declaration for a variable is:

count: 60

which means that you have a variable named count with initial value 60. The variables (except array variables) always occupy 16-bit space. All variables must start with a letter.

There are also array declarations:

my_array: .space 10

arrays are declared with the keyword .space. In the above example, we must reserve 10 consecutive 16-bit locations for the variable my_array.

.code section contains the instructions. The first instruction must always be mapped to the address 0x000 in memory. All labels of jump and jz instructions must be strings.

An example program in assembly code and its machine code translation

Assembly for

 

The machine code of the above assembly program is listed below.

 

Source code for a simple assembler

 

Questions

Your email address will not be published. Required fields are marked *