We are now going to create a simple busy loop that we can use to house our main ‘hello world’ logic. It is quite simple, but as in everything in life there is more than one way. We are going to aim for a continuous loop with a way of breaking out and returning control to the user by using a command called BNE or ‘branch if not equal’ along with some kind of check. BNE is coupled with a check and label to branch to. The check must equal 0 to stay in the loop, if not then we break or branch out.
;SOME KIND OF CHECK
In most Amiga demo’s they left mouse button is pressed to exit the demo (which will exit the busy loop). We will emulate this in our code. The register $bfe001 holds the status of the left mouse button (if it is down or not) by checking if bit 6 of the hardware register at address $bfe001 (which is a fixed value so always available) is set. The value you get when you read that register contains the information at bit number 6. When bit 6 is set, the left mouse button is pressed, otherwise not (0)
btst #6,$bfe001 ; test for left mouse button press
That’s it! Let’s combine our hello world logic so we repeat the word until the left button is pressed.
‘Hello World’ Busy Loop
Below is the full listing of our ‘hello world’ program along with a busy loop which will constantly ouput the text until the left mouse button has been pressed.
ExecBase = 4
OpenLib = -552
OpenLibVersion = 34
CloseLib = -414
PutString = -948
NoLibError: CLR.L D0
DosName: DC.B "dos.library",0
DisplayString: DC.B "Hello World",10,0
Lets compile and copy to our virtual Amiga in UAE!
C:\Users\spare\Desktop\vbcc\test>vasmm68k_mot -kick1hunks -Fhunkexe -o "C:\Users\Public\Documents\Amiga Files\WinUAE\Harddrives\Programs\asm\helloworldBusyLoop2" -nosym "HelloWorldBusyLoop.asm"
And jump over to UAE, one up a new shell window, cd to Programs:asm and then type in the name of our program. And, it works! The world ‘Hello World’ repeated and clicking the left mouse button quits the program.