The idea is to be able to multiply a value with a constant number without making macros for every case
This is my first idea (but it doesn't work):
reg is either A or HL, sup is the support register (make sup=reg before using) and times the constant you want your value multiplied with
Code: Select all
.deflong MULT(reg, sup, times)
i = times
.while i != 1
.if i % 2 = 1
i = i - 1
add reg, sup
.else
i = i / 2
add reg, reg
.endif
.endwhile
.enddeflong
I was thinking of using a combination of .org directives and a logaritm to calculate the amount of additions... There must be an easier way! ^^
Now I think of it...
Code: Select all
j=i
n=0
.while j!=1
n=n+1
.if j%2=1
j=j-1
.else
j=j/2
.endif
.endwhile
Any ideas?
And yes, it's meant for Brass (obviously ^^).
EDIT:
WHOAAAA hold on... I missed something...
there is no .while, though it shouldn't be that hard to synthesize it with a .repeat/.loop
But the concept stays, is there a way to create an elegant macro to multiply a value with a constant?