[Coco] Performing a modulo operation

Robson França robsonsfranca at gmail.com
Wed Feb 13 20:54:34 EST 2013


Well, there are many ways to do it. If the divisor is a number like 2^n,
such as 8 (2^3) or 16 (2^4), this could be easily accomplished by an AND
operation:

M = N AND D

or in 6809 Assembly:

LDA N
ANDA D
STA M

For other divisors, the method described by Luis and William are OK. If the
dividend and the divisor are below 127, 6809 Assembly could be used:

           ldb  n
rm1:
          subb d
          cmpb d
          bge rm1
          rts

If you need this operation in BASIC, use the following:

10 GOSUB 1000: DEFUSR0=10496
20 POKE 10498, N: POKE 10499,D
30 M=USR0(0)
40 PRINT M
50 END

1000 DATA 32,02,00,01,246,41,02
1010 DATA 240,41,03,241,41,03,44,248
1020 DATA 79,126,180,244
1030 FOR I=10496 TO 10514
1040 READ B: POKE I,B
1050 NEXT I
1100 RETURN



2013/2/13 Luis Antoniosi (CoCoDemus) <retrocanada76 at gmail.com>

> 7-INT(7/3)*3
>
>
>
> On Wed, Feb 13, 2013 at 3:07 PM, Alan Bryan <icemanind9 at gmail.com> wrote:
>
> > Is there a way, preferably in CoCo BASIC or in 6809 assembly language to
> > perform a Modulo Operation?
> >
> > For example: 7 modulo 3 should be 1 (since 3 goes into 7 two times with a
> > remainder of 1)
> >
> > Thanks
> >
> > --
> > Coco mailing list
> > Coco at maltedmedia.com
> > http://five.pairlist.net/mailman/listinfo/coco
> >
>
>
>
> --
> Long live the CoCo
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>



More information about the Coco mailing list