Amiga Asm: Busy Loop

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.

loop:
;DO STUFF
;SOME KIND OF CHECK
bne loop
rts

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)

loop:
btst #6,$bfe001 ; test for left mouse button press
bne loop
rts

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
MOVE.L #OpenLibVersion,D0
LEA DosName,A1
MOVE.L ExecBase,A6
JSR OpenLib(A6)
TST.L D0
BEQ.B NoLibError
MOVE.L D0,A6
loop:
MOVE.L #DisplayString,D1
JSR PutString(A6)
BTST #6,$bfe001
BNE loop
MOVE.L A6,A1
MOVE.L ExecBase,A6
JSR CloseLib(A6)
NoLibError: CLR.L D0
RTS
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.

Be the first to comment

Leave a Reply

Your email address will not be published.


*