Example - 99nasty.asm - Nasty |
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.
; ----- 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. ; ---------------------------------------------- |
; ----- 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 ; ------------------------------------------------------------- |
Write all your future programs ...
INC BL ; Add one to BL
INC BL ; Make BL point to the next video RAM location
© C Neil Bauers 2003