User Tools

Site Tools


base:multiplication_with_a_constant
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


Next revision
base:multiplication_with_a_constant [2015-04-17 04:33] – external edit 127.0.0.1
Line 1: Line 1:
 +====== Multiplication with a constant ======
 +Multiplication by a specific constant can be a lot simpler and faster than a general-purpose routine to multiply two given numbers together.
 +
 +For multiplying by a power of two, you can use ASL multiple times on a number.
 +
 +For multiplying by other things, you can use two copies of the number, ASL both copies different amounts, and then add the results together. For example, here's some code for multiplying the accumulator by ten:
 +<code>
 +  sta $2 ; Can be any other memory location that's free for use
 +  asl    ; Shifting something left three times multiplies it by eight
 +  asl    ; 
 +  asl    ; 
 +  asl $2 ; Shifting something left one time multiplies it by two
 +  clc    ; Clear carry
 +  adc $2 ; Add the two results together
 +</code>
 +
 +You may also use a table, which is even faster, but would take up more space.
 +<code>
 +  tax          ; Copy the accumulator into X so we can use it as an index
 +  lda Table, x ; 
 +</code>
  
base/multiplication_with_a_constant.txt · Last modified: 2021-02-10 01:24 by strobe