680x0:Simple calculations

From Amiga Coding
Revision as of 23:06, 31 October 2007 by Spellcoder (talk | contribs) (New page: Simple calculations: <code><pre> move.l #5,d0 ; d0 = $00000005 add.l #1,d0 ; d0 = d0 + 1 (d0 is now $00000006) sub.l #2,d0 ; d0 = d0 - 2 (d0 is now $00000004) rts </pre></co...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Simple calculations:

move.l	#5,d0		; d0 = $00000005
add.l	#1,d0		; d0 = d0 + 1       (d0 is now $00000006)
sub.l	#2,d0		; d0 = d0 - 2       (d0 is now $00000004)
rts


Harder calculations:

move.l	#5,d0		; d0 = $00000005
mulu.w	#4,d0		; d0 = d0 * 4
rts


The standard mulu (MULtiply Unsigned) only works with words so can only handle numbers up to 65535. There is an command for 68020+ processors and there are routines to multiply using longwords but whe'll ignore them for now ;)

divu uses the lower word for the quotient (the result) and the upper word for the remainder.

mulu doesn't use the upper word.