Difference between revisions of "680x0:Simple calculations"
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...) |
Spellcoder (talk | contribs) (changes so syntax highlighting is used) |
||
Line 1: | Line 1: | ||
Simple calculations: | Simple calculations: | ||
− | <code | + | <code lang="m68k"> |
move.l #5,d0 ; d0 = $00000005 | move.l #5,d0 ; d0 = $00000005 | ||
add.l #1,d0 ; d0 = d0 + 1 (d0 is now $00000006) | add.l #1,d0 ; d0 = d0 + 1 (d0 is now $00000006) | ||
sub.l #2,d0 ; d0 = d0 - 2 (d0 is now $00000004) | sub.l #2,d0 ; d0 = d0 - 2 (d0 is now $00000004) | ||
rts | rts | ||
− | + | </code> | |
Harder calculations: | Harder calculations: | ||
− | <code | + | <code lang="m68k"> |
move.l #5,d0 ; d0 = $00000005 | move.l #5,d0 ; d0 = $00000005 | ||
mulu.w #4,d0 ; d0 = d0 * 4 | mulu.w #4,d0 ; d0 = d0 * 4 | ||
rts | rts | ||
− | + | </code> | |
Revision as of 23:38, 24 March 2008
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.