Hi all.
It's been long since last time I was here, and just saw this thread and I hoped perhaps I could get some advise...
I'm trying to implement exponentiation of a number in assembler language (for the 8051 processor in this case). I'm trying by using the MUL instruction, which does the multiplication of 2 numbers stored in registers A (accumulator) and B, and puts the lower 8 bits in A and the upper ones in B. So the exercise is, I have initially numbers in A and B, and we want the operation A^B leaving lower 8 bits in A and upper ones in B.
I'm trying first with a particular case: 3^10. I already have part of the overall idea, I'm making a loop that multiplies A itself B number of times, making 8 bit multiplications (obviously storing previous results in other R registers). When I reach the 6th power the upper 8 bits (register B) begins to be used. I did the following binary multiplications in calculator apart in 2 ways: taking all the 8+ bits and taking only the lower 8 bits. Compared and realized that in both cases the lower 8 bits remain the same, only the upper 8 bits changing.
So the idea of doing 8-bit multiplications seems good. My problems are, I just have no clue of how to gradually do the arrangements on the upper 8 bits, nor I know how to stop the program if the result exceeds the 16 total bits (according to MUL's instruction manual, the overflow flag sets when the product exceeds 255, not 65535, where it's actually needed!).
Can you help me by chance?
Thank you beforehand.
It's been long since last time I was here, and just saw this thread and I hoped perhaps I could get some advise...
I'm trying to implement exponentiation of a number in assembler language (for the 8051 processor in this case). I'm trying by using the MUL instruction, which does the multiplication of 2 numbers stored in registers A (accumulator) and B, and puts the lower 8 bits in A and the upper ones in B. So the exercise is, I have initially numbers in A and B, and we want the operation A^B leaving lower 8 bits in A and upper ones in B.
I'm trying first with a particular case: 3^10. I already have part of the overall idea, I'm making a loop that multiplies A itself B number of times, making 8 bit multiplications (obviously storing previous results in other R registers). When I reach the 6th power the upper 8 bits (register B) begins to be used. I did the following binary multiplications in calculator apart in 2 ways: taking all the 8+ bits and taking only the lower 8 bits. Compared and realized that in both cases the lower 8 bits remain the same, only the upper 8 bits changing.
So the idea of doing 8-bit multiplications seems good. My problems are, I just have no clue of how to gradually do the arrangements on the upper 8 bits, nor I know how to stop the program if the result exceeds the 16 total bits (according to MUL's instruction manual, the overflow flag sets when the product exceeds 255, not 65535, where it's actually needed!).
Can you help me by chance?
Thank you beforehand.
