|
Post by quentinpsausages on Feb 22, 2024 21:49:17 GMT
Hello!
Does anyone know of a way to get MPAGD to do digit sums for given variables?
For example, if A = 123, automatically calculate 1 + 2 + 3 = 6?
Thanks!
|
|
mas
Processing Plant
Posts: 27
Member is Online
|
Post by mas on Feb 23, 2024 12:52:45 GMT
I think there isn't an easy way. Standard variables will hold 0-255 (so A-Z, OPT, RND,etc).
If you want to say A = 123; sum those numbers you'll have to do something like.
LET A = 123 ; initial setting of A ; we will use B to calc hundreds, C for tens, D for units
LET B = A LET C = A LET D = A
PRINT "A = " DISPLAY TRIPLEDIGITS A
DIVIDE B BY 100 REPEAT B SUBTRACT 100 FROM C SUBTRACT 100 FROM D ENDREPEAT DIVIDE C BY 10 REPEAT C SUBTRACT 10 FROM D ENDREPEAT
PRINT " WHICH BECOMES " DISPLAY DOUBLEDIGITS B PRINT " + " DISPLAY DOUBLEDIGITS C PRINT " + " DISPLAY DOUBLEDIGITS D PRINT " = "
ADD D TO C ADD C TO B
DISPLAY DOUBLEDIGITS B
;(code from top of my head) ;(may not be 100% correct)
is that what you're after? I'd be tempted to do a little assembler math and call it as a user routine (but that would be for someone else to do)
(A quick test outputs: A = 123 WHICH BECOMES 01 + 02 + 03 = 06 )
|
|
|
Post by quentinpsausages on Feb 27, 2024 22:35:04 GMT
Thanks so much, that's really helpful!
|
|