base:multiplication_with_a_constant
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
base:multiplication_with_a_constant [2020-04-09 21:30] – Added credits ftc | base:multiplication_with_a_constant [2021-02-10 01:24] (current) – fix a typo strobe | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Multiplication with a constant ====== | ====== Multiplication with a constant ====== | ||
- | |||
- | By TWW | ||
Multiplication by a specific constant can be a lot simpler and faster than a general-purpose routine to multiply two given numbers together. | Multiplication by a specific constant can be a lot simpler and faster than a general-purpose routine to multiply two given numbers together. | ||
Line 20: | Line 18: | ||
---- | ---- | ||
- | EDIT: The above is based on 8*A + 2*A. This routine would not allow any higher number than A = 25 as it would overflow (8 * 26) + (2 * 26) = 208 + 52 = 262 (However 25 fits perfectly f.ex. when you'd want to calculate a character line based on Y). | + | By TWW: |
+ | |||
+ | Optimization of the above posted by unknown: The above is based on 8*A + 2*A. This routine would not allow any higher number than A = 25 as it would overflow (8 * 26) + (2 * 26) = 208 + 52 = 262 (However 25 fits perfectly f.ex. when you'd want to calculate a character line based on Y). | ||
With this in mind, you can do 2*A + 8*A which saves you the asl $2. Also as long as A cannot be higher than 25, the upper 4 bits (high nybble) will always be #%0000. This means that the asl instructions will never set carry and the clc can be dropped. | With this in mind, you can do 2*A + 8*A which saves you the asl $2. Also as long as A cannot be higher than 25, the upper 4 bits (high nybble) will always be #%0000. This means that the asl instructions will never set carry and the clc can be dropped. | ||
- | This gives the following code to multiply A with 10 (assuming A is less than 25): | + | This gives the following code to multiply A with 10 (assuming A is less than 26): |
< | < |
base/multiplication_with_a_constant.1586460629.txt.gz · Last modified: 2020-04-09 21:30 by ftc