Site Logo

Other Instructions

Website

Home | Previous | Next

Miscellaneous Instructions - CLI and STI control the (I) Flag

Assembler Machine Code Explanation
HALT 00 Stop the program.
00 is the machine instruction for HALT.
The program will cease to run if it encounters a HALT instruction.
Continuous running is cancelled by this command.
You can have several halt commands in one program.
There should be only one END and code after END is ignored.
NOP FF Do nothing for one clock cycle.
FF is the machine instruction for NOP.
The program will do nothing for one clock cycle.
The program then continues as normal.
NOP is used to introduce time delays to allow slow electronics to keep up with the CPU. These are also called WAIT STATES.
CLO FE Close all the peripheral windows.
FE is the machine code for CLO.
It applies to this simulator only, and is used to close peripheral windows.
This makes it easier to write demonstration programs without the screen getting too cluttered.
ORG 30 NONE Code Origin. Generate code starting from this address.
To generate code from a starting address other than zero use ORG.
This is useful to place procedures, interrupts or data tables at particular addresses in memory.
ORG is an assembler directive and no code is generated.
DB 84 84 Define a byte.
Store the byte (84) in the next free RAM location.
Use DB to create data tables containing bytes of data.
Use BD to define an Interrupt Vector.
DB "Hello" 48, 65, 6C, 6C, 6F Define a string.
Store the ASCII codes of the text in quotes in the next free RAM locations.
Use DB to store text strings.
The stored ASCII codes do not include an end-of-string marker.
Use DB 00 for this.
CLI FD Clear the I flag
If the I flag is cleared, hardware interrupts are ignored.
This is the default state for the simulator.
Resetting the CPU will also clear the I flag.
The timer that generates hardware interrupts will do nothing.
STI FC Set the I flag
If the I flag is set, the simulator will generate INT 02 at regular time intervals.
It is necessary to have an interrupt vector stored at address 02 that points to interrupt handler code stored elsewhere.
The interval between timer interrupts can be set using the slider in the Configuration Tab.
If interrupts occur faster than the processor can handle them, a simulated system crash will follow.
Adjust the CPU clock speed and the timer interval to prevent this – or cause it if you want to see what happens.

It is possible to program the simulator using pure machine codes. Here is a simple example.

; ===== NORMAL CODE =====
	MOV AL,0
	INC AL
	END
; ===== NORMAL CODE =====

Here is the same program in pure machine code apart from the required END keyword. This should run exactly as the program above.

; ===== PURE MACHINE CODE =====
	DB D0 ; MOV
	DB 00 ; AL
	DB 00 ; 0
	DB A4 ; INC
	DB 00 ; AL
	END
; ===== PURE MACHINE CODE =====

This is an interesting exercise but rather defeats the whole point of using an assembler. If you have a dog, why bark yourself? Manually calculating jump distances might be a useful learning exercise, especially for negative jumps.

Home | Previous | Next

© C Neil Bauers 2003