Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.acorn.programmer > #5982
| From | Jean-Michel <jmc.bruck@orange.fr> |
|---|---|
| Newsgroups | comp.sys.acorn.programmer |
| Subject | Re: Subtracting times |
| Date | 2020-02-18 19:11 +0100 |
| Organization | Jean-Michel |
| Message-ID | <0a59594458.jmb@jmc.bruck.orange.fr> (permalink) |
| References | <37f8364458.Alan.Adams@ArmX6.adamshome.org.uk> |
In message <37f8364458.Alan.Adams@ArmX6.adamshome.org.uk>
Alan Adams <alan@adamshome.org.uk> wrote:
> My head is hurting.
> I need a BASIC routine to subtract one 5-byte time from another and return
> a correctly signed result.
> Complications arise at the point where the low word goes from &7fffffff to
> &80000000, and where the high byte increases.
> BASIC doesn't allow access to the carry or borrow from arithmetic
> operations.
> I've developed the following which *seems* to work correctly. However I'm
> not sure about all the edge cases.
> This is part of a timing system, Next February the high byte of times will
> change from &57 to &58, and I would like this code to survive working
> across this boundary. I need to reliably detect negative results, which
> can occur if a spurious finish time pulse arrives before a start time.
> Subtract stamp2 from stamp1 and store the result in resultbuf.
> ( Although the result is 5 bytes. the elapsed time will always be
> contained in the low 4 bytes. This will only overflow after 1 year, 5
> months and 2 hours 27 minutes. The system doesn't meed to run for that
> long. )
> PROCsubstamp(resultbuf%,stamp1%,stamp2%)
> LOCAL I%,J%,K%,L%,borrow%
> borrow%=0
> FOR I%=0 TO3
> J%=stamp1%?I%
> K%=stamp2%?I%
> L%=J%-K%-borrow%
> resultbuf%?I%=L%AND&FF
> IF L% < 0 THEN borrow%=1 ELSE borrow%=0
> NEXT
> I%=4
> J%=stamp1%?I%
> K%=stamp2%?I%
> L%=J%-K%-borrow%
> IF L% < 0 THEN
> resultbuf%!0 = -(resultbuf%!0)
> ENDIF
> resultbuf%?I%=L%AND&FF
> ENDPROC
from Steve Drain (ROOL Forum 18/12/2016)
I wrote a library to support some of this this, as have others. It is a
candidate for Basalt, someday. ;-)
Look at http://kappa.me.uk/Libraries/lbLongs032.zip
Jean-Michel
--
Jean-Michel
Back to comp.sys.acorn.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-18 11:55 +0000
Re: Subtracting times Jean-Michel <jmc.bruck@orange.fr> - 2020-02-18 19:11 +0100
Re: Subtracting times Steve Drain <steve@kappa.me.uk> - 2020-02-21 03:28 -0800
Re: Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-21 12:45 +0000
Re: Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-21 15:17 +0000
Re: Subtracting times Steve Drain <steve@kappa.me.uk> - 2020-02-22 10:37 +0000
Re: Subtracting times Steve Drain <steve@kappa.me.uk> - 2020-02-25 16:05 +0000
Re: Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-25 16:35 +0000
Re: Subtracting times Steve Drain <steve@kappa.me.uk> - 2020-02-27 17:10 +0000
Re: Subtracting times Steve Drain <steve@kappa.me.uk> - 2020-02-27 10:06 -0800
Re: Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-28 11:21 +0000
Re: Subtracting times jeffrey.a.doggett@gmail.com - 2020-04-22 12:00 -0700
Re: Subtracting times Martin <News03@avisoft.f9.co.uk> - 2020-04-23 00:07 +0100
Re: Subtracting times jeffrey.a.doggett@gmail.com - 2020-04-23 03:13 -0700
Re: Subtracting times Martin <News03@avisoft.f9.co.uk> - 2020-04-23 18:01 +0100
Re: Subtracting times "John Williams (News)" <UCEbin@tiscali.co.uk> - 2020-04-23 18:06 +0100
Re: Subtracting times jeffrey.a.doggett@gmail.com - 2020-04-23 11:18 -0700
Re: Subtracting times Martin <News03@avisoft.f9.co.uk> - 2020-04-23 21:23 +0100
Re: Subtracting times David Higton <dave@davehigton.me.uk> - 2020-04-24 15:24 +0100
Re: Subtracting times David Higton <dave@davehigton.me.uk> - 2020-04-23 20:57 +0100
Re: Subtracting times jgh@mdfs.net - 2020-02-23 17:39 -0800
Re: Subtracting times Steve Drain <steve@kappa.me.uk> - 2020-02-24 10:23 +0000
Re: Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-24 11:12 +0000
Re: Subtracting times Martin <News03@avisoft.f9.co.uk> - 2020-02-24 13:05 +0000
Re: Subtracting times Matthew Phillips <spam2011m@yahoo.co.uk> - 2020-02-19 08:35 +0000
Re: Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-19 10:03 +0000
Re: Subtracting times Sebastian Barthel <naitsabes@freenet.de> - 2020-02-19 13:04 +0000
Re: Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-19 16:41 +0000
Re: Subtracting times jgh@mdfs.net - 2020-02-19 12:01 -0800
Re: Subtracting times Matthew Phillips <spam2011m@yahoo.co.uk> - 2020-02-23 20:46 +0000
Re: Subtracting times Martin <News03@avisoft.f9.co.uk> - 2020-02-19 23:54 +0000
Re: Subtracting times Alan Adams <alan@adamshome.org.uk> - 2020-02-20 11:18 +0000
csiph-web