ASM Newbie: Delays, waiting X seconds

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
User avatar
Posts: 52
Joined: Sun Apr 21, 2013 9:57 pm

ASM Newbie: Delays, waiting X seconds

Post by uniforix » Sun Dec 03, 2017 9:52 am

What's the best way to do say a 5 second delay? In BASIC I would reset TIME and wait for it to pass a threshold, in assembler I ended up creating a counter that counter down from 255 in another loop that counted down to 255 and called that numerous times, way overkill, sure there's likely a real easy way.

BTW I only started learning it yesterday haha :lol:

Electron Forever

User avatar
Posts: 3409
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: ASM Newbie: Delays, waiting X seconds

Post by jgharston » Sun Dec 03, 2017 5:47 pm

If you don't mind a keypress terminating the delay early:
LDX #centiseconddelay AND 255
LDY #centiseconddelay DIV 256

If it must delay the entire time, the simplest is to use *FX19 to count 1/50s VSyncs:
LDX #fiftithseconddelay AND 255
LDY #fiftithseconddelay DIV 256
DEX:BNE waitloop
DEY:BNE waitloop

This is how the BASIC V WAIT command works.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015

Post Reply