Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assembly Language Programming Using TI MSP430 and IAR Workbench. In assembly (MS

ID: 1991484 • Letter: A

Question

Assembly Language Programming Using TI MSP430 and IAR Workbench.

In assembly (MSP430), how can I multiply 2 negative numbers together? I can't use the MUL function due to the MSP430. Basically I have this:

#include "msp430.h" ; #define controlled include file

PUBLIC sw_mulneg

RSEG CODE

sw_mulneg: MOV #-0x00004,R6 ; insert the number -4 into register 6

MOV #-0x00004,R7 ; insert the number -4 into register 7

I don't know where to go from here to multiply these 2 16 bit signed integers? Thanks for any help!

Explanation / Answer

The division by integer constants is considered in details in the book "Hacker's Delight" by Henry S. Warren (ISBN 9780201914658).

The first idea for implementing division is to write the inverse value of the denominator in base two.

E.g.,
1/3 = (base-2) 0.0101 0101 0101 0101 0101 0101 0101 0101 .....

So,
a/3 = (a >> 2) + (a >> 4) + (a >> 6) + ... + (a >> 30)
for 32-bit arithmetics.

By combining the terms in an obvious manner we can reduce the number of operations:

b = (a >> 2) + (a >> 4)

b += (b >> 4)

b += (b >> 8)

b += (b >> 16)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote