Site Logo

Example - 99nasty.asm - Nasty

Website

Home | Previous | Next

This example shows how you can create totally unreadable code.

Try not to do this.

This program actually works. Copy it and paste it into the simulator and try it!

Click the List-File tab to see the code laid out better and to see the addresses where the code is stored.

To get back to the editor window click the Source-Code tab.

Example - 99nasty.asm

; ----- Here is how NOT to write a program -----
_: Mov BL,C0 Mov AL,3C Q: Mov [BL],AL CMP AL,7B
JZ Z INC AL INC BL JMP Q Z: MOV CL,40 MOV AL,20
MOV BL,C0 Y: MOV [BL],AL INC BL DEC CL JNZ Y JMP
_ END ; Look at the list file. It comes out OK!
; Press Escape to stop the program running.
; ----------------------------------------------

 

Here it is tidied up

; ----- A Program to display ASCII characters -----------------
; ----- Here it is tidied up. This version is annotated. ------
; ----- This makes it possible to understand. -----------------
; ----- The labels have been given more readable names too. ---

Start: 
	Mov BL,C0	; Make BL point to video RAM
	Mov AL,3C	; 3C is the ASCII code of the 'less than' symbol
Here: 
	Mov [BL],AL	; Copy the ASCII code in AL to the RAM location that BL is pointing to.
	CMP AL,7B	; Compare AL with '{'
	JZ Clear	; If AL contained '{' jump to Clear:
	INC AL		; Put the next ASCII code into AL
	INC BL		; Make BL point to the next video RAM location
	JMP Here	; Jump back to Here
Clear:
	MOV CL,40	; We are going to repeat 40 (hex) times
	MOV AL,20	; The ASCII code of the space character
	MOV BL,C0 	; The address of the start of video RAM
Loop: 
	MOV [BL],AL	; Copy the ASCII space in AL to the video RAM that BL is pointing to.
	INC BL		; Make BL point to the next video RAM location
	DEC CL		; CL is counting down towards zero
	JNZ Loop	; If CL is not zero jump back to Loop
	JMP Start	; CL was zero so jump back to the Start and do it all again.
	
	END
; -------------------------------------------------------------

 

Your Task

Write all your future programs ...

Bad Comment - just repeats the code

        INC BL ; Add one to BL

Useful Comment - explains why the step is needed

        INC BL ; Make BL point to the next video RAM location

Home | Previous | Next

© C Neil Bauers 2003