CODE
The Hidden Language of Computer Hardware and Software
2nd Edition

Chapter 27. Coding: Assembly Language

Chapter 27 is about writing computer programs, an activity variously known as software engineering, programming, or coding.

Two types of coding are described in this chapter: Assembly language programming based on the the Intel 8080 processor on this page, and on another page, high-level programming using JavaScript.

8080 Assembly Language Programming

This is an emulation of an Intel 8080 microprocessor written in JavaScript. It has four main components:

These components are described further down this page.

Editor - Untitled

Do you want to save changes to

Open / Save As

"" already exists.
Do you want to replace it?

 

Memory

CPU

PC = 0000h
SP = 0000h
A00h00hFlags
B00h00hC
D00h00hE
H00h00hL
Flags

Console

The following sections describe the various components of this emulator.

Editor

The Editor is a stripped down version of a multiline editor application such as the Windows Notepad or the macOS TextEdit. It is here that you can create assembly language programs that are compatible with the Intel 8080 Assembly Language. This language is case insensitive: You can type your programs in uppercase or lowercase or a mix.

The File menu has options to clear the contents of the Editor to begin a new file, open an existing file, and save a file. These menu options invoke familiar dialog boxes.

This simulated file system uses a feature available through JavaScript known as localStorage. The files that you store are private to this particular webpage and to the particular browser you're using. In other words, if you save files while running this page on one browser, you won't be able to see them when using another browser. You can transfer these files between browsers, or save these files elsewhere by copying them from the Editor to the clipboard.

In addition to opening and saving entire files, you can save a snippet of a file by selecting a block of text and choosing Save selection from the menu. You can insert a snippet into your existing file and choosing Insert file from the menu. This features are intended to save and retrieve handy subroutines.

WARNING: Although this editor uses typical message box warnings to help you avoid writing over an existing file, or erasing a file before it's been saved, it does NOT warn you about losing your edits if you refresh or close the webpage.

Several files are pre-stored for you. These include all the assembly language programs in the book, as well as a couple others. These files are described in the File Open dialog box. They are read-only files. You can modify them in the Editor but you cannot save them unless you choose the Save As option to specify a different filename.

The allowable syntax for your programs is generally that described by the Intel 8080 Assembly Language Programming Manual published in 1975 and available on the Internet Archive with some stipulations and exceptions:

Notice that hexadecimal numbers that begin with a letter must be preceded with a zero. Otherwise, the assembler could mistake them for labels.

Amoung the available programs is one called Test Suite, which is copyright 1980 and intended to test emulated 8080 processors. This program assembles on runs on the emulator here and was particularly useful for testing it.

If the program contains an ORG statement that causes the assembled program to begin execution at the address 100h, then five CP/M calls are supported through the CALL 5 interface:

The Test CP/M Console Calls program included among the files demonstrates all these function calls.

A CP/M program can terminate in several ways: By a CALL 5 with register C set to zero; by JMP or CALL to address 0000h; or by a RST 0. When a CP/M program begins execution, the address 0000h has been pushed on the stack, so it can also terminate with a RET instruction.

Memory

After you've opened or typed in a progam you can press the Assemble button. Any errors in your code are displayed in red under that button.

If the file is successfull assembled, the addresses and machine code are displayed in the Memory box. For convenience, the corresponding instructions are displayed at the right.

This display is helpful when executing the code: Lines of code in the Memory display are highlighted as they are being executed.

CPU

This table displays the state of the CPU, which consists of the Program Counter (PC), the Stack Pointer (SP), the registers A, B, C, D, E, H, L, and the flags.

Four buttons are available:

* The original Intel 8080 ran at 2 Mhz. The various instructions (including fetching the instruction from memory) required a minimum of 4 clock cycles and as many as 11. The instuctions executed at a rate of approximately 200,000 to 500,000 a second.

Console

The Console displays output from your programs and allows you to type input to your programs. It should receive input focus when a CP/M call has been made to receive keyboard input, but if not, simply click it and then type. It can be cleared with the Clear button.