Dr. T's Assembly Guide

Introduction

Dr. T's Toy Assembler is an emulator for a minimalist (14 instruction) language for teaching the basics of ASM programming.

Features of the Language

Instruction Set

Data Movement Instructions

Arithmetic Instructions

Control Flow Instructions

Input/Output Instructions

Using Labels

Labels are STRING identifiers used to mark specific locations in your code. They are useful for making your code more readable and for facilitating jumps to different sections of the program.

Defining Labels

To define a label, simply write the label name followed by a colon (:) at the desired location in your code. Labels are usually placed before a section of code to which you might want to jump.

start:
LOAD r1, #10 ; Load immediate value 10 into r1
ADD r1, r2 ; Add the value of r2 to r1
JNZ end ; Jump to the label 'end' if Zero Flag is not set
INC r1 ; This line will be skipped if ZF is set
end:
OUT r1 ; Output the value of r1

Using Labels with Jumps

Labels can be used with jump instructions (JMP, JZ, JNZ) to create more complex control flows. You can use labels to jump to different parts of your code, enabling loops and conditional execution.

LOOP_START:
LOAD r1, #5 ; Load immediate value 5 into r1
DEC r1 ; Decrement r1
JNZ LOOP_START ; Jump back to 'LOOP_START' if ZF is not set (r1 != 0)
OUT r1 ; Output the final value of r1 after loop ends

Flags Explained

Flags are special bits that store information about the state of the CPU or the results of operations. They are typically used to make decisions during program execution. In this language, the primary flag used is the Zero Flag (ZF).

Zero Flag (ZF)