Difference between revisions of "Assembler & Disassembler"

From Arcade Tester AR81
Jump to: navigation, search
Line 221: Line 221:
{| class="wikitable"
{| class="wikitable"
Line 255: Line 255:
{| class="wikitable"
{| class="wikitable"
|File Name
|File Name
Line 271: Line 271:
{| class="wikitable"
{| class="wikitable"
|File Name
|File Name

Revision as of 17:27, 29 October 2017

Assembler & Disassembler

The AR81 test software from revision 1.80 has the ability to assemble and disassemble code written in the processor selected. The software can only handle Z80 code at present but more processors will be added in later revisions.

To use these features, the Z80 Emulator hardware is required however the functions can still be used though an area of RAM is required on the test PCB to store any code. The Disassembler will work on any code including ROMS and requires no RAM.


The disassembler is accessed by typing DIS (upper or lower case) into the next line of the Main Test Window. The command must be followed by the amount of bytes to process in a 16bit format.


DIS 00FF - This will disassemble code from the Start address set in the ADDR box and process FF bytes or 255. Note upper and lower case is acceptable.

All the disassembly code will be displayed in the Main Test Window and will be highlighted in various colours as detailed below.

Function Colour
ADDRESS of code line Purple
ADDRESS of code line Green (Label in use)
OP CODE Yellow
OP CODE with LABEL Orange
HEX DATA of opcode Red included in brackets
MEMORY ACCESS Red (Addresses out of the range)

When a block of code is disassembled, the resultant information will also be placed into a .ASM file. This file can be set by using the FILENAME box with no extensions inserted.

The PATH where the file will be placed can be set using the PATH command. If no path is set, the default is /home/pi/Desktop/ROMS.

Each time the disassembler is run, the last address will be the start address for the next run. To disassembly the same code again, the address needs to be set using the WRITE ADDR button or the low level AOS command *A0000. This will set the address to 0000h.

LABELS can also be used to highlight important points within the code such as a start of a subroutine etc. These can be set using the DATA ENTRY MODE detailed in another section.

Note that when using the EMULATOR and when it is in the EMULATOR MODE, the disassembler cannot be used. This is due to the address bus being set to and input and no addresses can be written to memory.


To operate the assembler, there are two methods which will be described in the following information.

Direct Entry Method

The DATA ENTRY MODE allows code to be entered directly into memory at any location set by the ADDR BOX.

Each time a line of code has successfully been loaded, the address will be incremented by the number of bytes used so the next line will be entered at the next address position. This allows programs to be entered directly into memory but bear in mind if the address set is not RAM, the code will be lost and not stored. The EMULATOR hardware contains suitable memory for this purpose.

To enter a line of code, the following should be entered into the next line of the MAIN TEST WINDOW.


>JP &0000 - This will load the memory with the Z80 opcode JP and the jump address will be 0000h

It is important to start all lines using the '>' as this indicates the data entry mode.

Make sure the opcode is entered exactly as the Z80 Zilog manual indicates else the code will be ignored. Every time a line of code is entered, a syntax will be run on the line and if it is correct, the resultant hex data will be entered into memory.

All numbers entered within the opcodes must be prefixed using the '&' symbol. This tells the assembler that a numeric value is entered in hex. So for example FF should be entered as &FF etc.

Upper and lower case is acceptable and can be mixed. The DISASSEMBLER will only display upper case however.

When using the Direct Entry Method, other commands can be used. These are detailed in a later section.

Labels can also be used though these are detailed in the Data Entry Section.

Program Entry Mode

Using the Direct Entry Mode is perfectly acceptable for entering lines of code however if the program is larger and has a reasonable number of lines, a better method is to use the Program Entry Mode.

This mode allows programs to be written using any text editor and then load them into the memory automatically. It will result in the program in memory without the slow laborious line by line method.

When this method is used, the TXT file created can also contain other lines to set addresses and define labels. Effectively the program can be loaded multiple times to a location set in the TXT file. Any errors in the program will be displayed and once the changes have been made and saved, the program can get re-loaded.

An example of a program written for this method is shown below.


$org &0000




: LD BC,&0800

: LD(HL),&45


: #go

: JP <go>


$org &0000

The program above is only an example and is not intended to produce any useful results.

The first lines of the program are STATIC LABEL definitions and can be in upper or lower case. These must be prefixed by '#' and have nothing else on the lines. Any text after the # will be set as the label name. Note spaces cannot be used. The line starts with the address to be set. So the first line 8800 #VIDEO_RAM will set the label VIDEO_RAM to address 8800h. Each time the assembler sees VIDEO_RAM it will insert address 8800 into the program. The Disassembler will also display the labels if set.

Static labels can be placed at any lines within the program as long as the rules are followed above. If duplicate labels are used, duplicates will be stored and the results unpredictable.

After the labels, a command to set the address the code will be loaded at is inserted.


$org &0000 - Sets the address to 0000h.

This will set the ADDR BOX to the address specified and the code that follows will be loaded at that point. This command can be used throughout the program to change addresses where sections of code has to be loaded. Note at the end of the program, the same line appears. This will return the start address to 0000h after the program is loaded.

Any code to be entered must be contained in two lines. One at the start of the code and the other at the end. This is important as it indicates to the assembler there is a block of code starting.

The lines that contain a block of code are as follows:


. code


They must be exactly as shown and in LOWER case only.

Multiple sections of code can be contained in the one program using this method.

After this, the lines of code can be entered. Each line must start with a ':' symbol to indicate a line of code. If this symbol is omitted, the line will be ignored. This allows lines to be commented out easily by simply deleting the ':'

Enter the code as before using the correct syntax. Upper and Lower case is allowed and all numbers must be prefixed by '&'

Note that any Labels used must be entered in brackets for example <START>.

Also labels can be defined within the lines of code such as #go

This will tell the assembler that 'go' is a label but the address must be set to the point in the program it is at when the line is read. This is useful if the address cannot be easily worked out at the time, such as loops etc. These labels are called FLOATING labels as their values can change depending where the program is loaded in memory.

It is worth noting that any ASM file generated by the disassembler can also be loaded into the assembler if renamed to a TXT file. The additional information included will be ignored.

Loading a Program

To load a program using the above method, the LOAD command is used in the MAIN TEXT WINDOW.

There are four variations of the command that can be used, two are for this.

LOAD /W Load a BIN file using waits. Useful if loading into slower memory devices.
Code Description
LOAD /a Load a TXT program into the assembler without showing lines of code. Useful if larger program is used.
LOAD /A Same as above but all lines of code will be shown.
LOAD Will load a BIN file only. * See note below*

Upper and lower case can be used but the switch must be in the case as above.

Note the path where the program is to be found has to be set using the PATH command as detailed before.


When loading a BIN file, there are a couple of points worth mentioning.

  • 1) The file must be called anyname.BIN with the extension in CAPITALS only.
  • 2) If the BYTES window is set to 0000, the entire file will be loaded at the start address set. If the BYTES window contains any other value, then only that amount of bytes will be loaded unless the file is shorter and then the full file will load.
  • 3) When using the '/A' or '/a' switch to load a TXT assembly file, no start address of bytes are required as the assembler will set these as required and also they will be set within the TXT file.


To set labels, they can be either defined in a program file as detailed above or manually set using the DATA ENTRY MODE.


Code Description
>#Program_Start Sets the label 'Program_Start' to the current tester address.
>$CLR ALL Clears all set labels from the tester
>$LIST Lists all set Labels. If none then nothing will be returned.
>$GOTO Program_Start Set start address.

All the above commands are typed into the next line of the MAIN TEST WINDOW.

Saving a Program

Once the program is entered, it can be saved as a BIN file with the associated labels stored in a LBL file. The filename is set by the FILENAME BOX and the number of bytes set by the BYTES box. The start address of the program must also be set in the ADDR box.

For example to save FF bytes in a BIN file called Test_Program, enter Test_Program into the FILENAME box followed by 00FF into the BYTES box.

Then enter SAVE into the MAIN TEST WINDOW and press enter.

The following files will be created using the PATH that is currently set.

File Name Description
Test_Program.BIN Binary file.
Test_Program.LBL Label file

Other files generated by the assembler and disassembler are as follows.

File Name Description
Test_Program.ASM Assembly output file.
Test_Program.HEX HEX output from the Block Read function
Test_Program.TXT Original program to load.