4
I have to create a program with the Assembly language K & S Model 2 that multiplies one number by another, the problem is that this language does not provide a multiplication operation. So I thought of doing multiplications with additions, for example:
3 x 5 = 5 + 5 + 5 (3 vezes o 5) = 15
This language also does not provide a direct way to make a cycle (or loop), nor a record comparison statement, for example to see if they are equal, ie if it has the same number.
This Assembly language provides only operators of bitwise which I’m not very familiar with. I know that doing AND bit by bit is like doing a multiplication of numbers but converted into binaries, for example:
3 & 2
First we have to convert to binary:
11 (3)
& 10 (2)
====
10 (2)
I honestly don’t see how I can do a multiplication using this operation, if only I could make a loop anyway...
What types of conditional deviation does this language have? Is it possible for example to say, "deviate if such a record is zero"? Most likely the solution to your problem will be there, not the operators bitwise.
– mgibsonbr
Yes! As I said in the answer, I don’t know exactly how these commands work. I assume that "ALU RESULT" refers to the "result of the last arithmetic and logic operation performed", and wrote the pseudo-code based on this premise. It would even be possible to adapt the algorithm to a language without conditional deviation, provided that the unconditional deviation allowed to use a memory or register value as the point of arrival, but I see that in your case this is not how the
BRANCH
works (it asks for an address hardcoded). So the output is to useBNEG
orBZERO
same (in my code,BNEG
)– mgibsonbr
You can use the 4th series multiplication algorithm to make the account more efficiently than just making a lot of sums.
– hugomg
https://pt.wikipedia.org/wiki/Multiplica%C3%A7%C3%A3o_por_duplica%C3%A7%C3%A3o
– hugomg
@hugomg Cool this algorithm, but I don’t remember seeing you at school no. Although my 4th grade is a lot further away than yours... : P
– mgibsonbr
This algorithm is the base 2 version of the school’s algorithm (which uses base 10)
– hugomg
Aaaaah, now everything makes sense! : I actually thought [subconsciously] about suggesting a variation of it at first, but how this architecture does not support shift left it was going to be a little bit more complicated... I preferred to keep the answer really, after all "first make it work, then make it fast" :P
– mgibsonbr