Microprocessor Simulator 0 Help



Download 1.18 Mb.
Page35/82
Date18.03.2021
Size1.18 Mb.
#56105
1   ...   31   32   33   34   35   36   37   38   ...   82
sms32v50 (3)
sms32v50 (3), sms32v50 (6)

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

; -------------------------------------------------------------


 


Download 1.18 Mb.

Share with your friends:
1   ...   31   32   33   34   35   36   37   38   ...   82




The database is protected by copyright ©ininet.org 2024
send message

    Main page