Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please answer the fill in the blanks. Thank You MSP430 Assembly Programming Intermediate- Multiplication In this lab, you will be designing an assembly program running
please answer the fill in the blanks. Thank You
MSP430 Assembly Programming Intermediate- Multiplication In this lab, you will be designing an assembly program running on MSP430 hardware using the IAR Kickstart IDE tool, a free tool for IAR for programming MSP430. Your program will perform multiplication via add, shift, and jump instruction. You will learn basic arithmetic operations, and flow of control in a program such as decision and loop structures. This lab worksheet along with your assembly program design and simulation will be inspected by the instructor in the lab for grading. Note that you will be using your own MSP430 for this lab. Most of the materials are hosted at http://cse.spsu.edu/clo/gLab In MSP430, there is no instruction to perform multiplication directly. Instead, to perform multiplication, we wl need to create an assembly program. In the class, we have studied a multiplication algorithm using "shift-add" approach. In this lab, you wil implement the shift-add algorithm to perform multiplication. Let's take a look at an example again, and observe how an assembly program for multiplication may be implemented. Table 1 illustrates an example of binary multiplication. Observe that the rows with an arrow ( are identical to the multiplicand, and the rest are all zeros. Also, the non-zero rows are from the one's digits of the multiplier. When adding up the partial products (all equal to the multiplicand), they only shift left a number of positions according where the multiplier digit is Table 1 An Example of Binary Multiplication Table 1 An Example of Binary Multiplication 10 Multiplicand x 00Multiplier 1 0 1 +0000 0 1 1 0Product With the above observation, a multiplier is designed based on an adder and two shifters. The adder is used to add partial products, whereas the shifters are used to shift the multiplicand left at a time after a corresponding bit in the multiplier is checked, and shift right the multiplier. Figure 1 illustrates the flowchart of the multiplication algorithm. In this algorithm, there are three registers, one for the multiplicand, one for the multiplier, and one for the product. The registers for the multiplicand and multiplier are shift registers. The multiplicand register will shift left whereas the multiplier register will shift right in each iteration. If the size of the multiplier is n bits, the size of the multiplier register needs only n bits. However, the registers for the product and the multiplicand will have to have 2n bits, simply because the shift left operation for the multiplicand register and the potential space need for the product. Begin Is LSB of multiplier1? Yes Add multiplicand to product No No Shift left multiplicand, and shift right multiplier Done? Yes End Figure 1 The Flowchart of a Hardware Binary Multiplication Algorithm To implement the multiplication algorithm, we need to understand add instruction, shift instructions, and conditional jump instructions. The instructions needed to the implementation are listed as follows: RRC dst RLC dst CLRC JC label JNC labeljump if carry bit it not set ADD src, dst put the sum of src and dst in dst The rotation instructions involve the carry bit. We can think the carry bit is sitting in-between MSB : rotate right 1 bit via carry ; rotate left 1 bit via carry : clear carry bit jump if carry bit is set and LSB of the destination, which is a register. Graphically, the RRC can be viewed as follows: B13 B2 B14 B1 B15 BO carry Figure 2 The RRC Operation on a 16-Bit Register The carry bit goes to bit 15, the bit 15 goes to the bit 14, the bit 1 goes to the bit 0, and the bit 0 goes to the carry, and the like. Because of the participation of the carry bit, the carry bit should be cleared, if necessary, before the RRC operation to implement a regular shift operation. To clear the carry, the instruction CLRC is used. The left rotation is symmetric to the right rotation. The two decision blocks in Figure 1 may be implemented using the conditional jump instructions (JC and JNC). To check if the LSB of a register is one can be done by right shifting the register, and conditional jump on the carry using JC or JNC accordingly AutarR4 sars ml.res mlbpepmodact 1. Fill in the assembly code to right shift the multiplier one bit. Assume that R4 stores muliplicand, KS stores multiplier, and Kb stores the proauct. 1. Fill in the assembly code to right shift the multiplier one bit. : clear the carry bit check : right rotate the multiplier 2. Fill in the assembly code to implement "if the LSB of the multiplier is one, add the multiplicand to the product." Assume the LSB of the multiplier is stored in the carry bit. The if a and endif a are labels. Should you have more decision structures, you would use labels ended by_b,_c, etc Check i skip if the carry is not set if a: ; add multiplicand to product endif a: . Fill in the assembly code to left shift the multiplicand one bit. check : clear the carry bit : left rotate the multiplicand 4. The decision block in Figure 1 requires to check when the computation is done. If we perform multiplication on two one-byte operands, the product wll require two bytes. So to fit to the MSP430 registers, we assume the multiplicand and multiplier contain one-byte data. Based on the algorithm, the shift-add operation should repeat 8 times, one for each bit in the multiplier. This essentially requires a counting mechanism. In this lab, however, we will use another register R7 to do the counting. Here is the idea. We first set R7 to the binary "10000000" and right shift one bit at each iteration. Then all we need to do is check when the "l reaches to the LSB. At that time, the loop should be terminated. Fill in the partial code follows. check , set R7 to the binary 10000000 loop begins here loop: : loop body : set R7 to the binary 10000000 loop: : loop begins here : loop body i right rotate the counter R7 ; loop if the LSB of R7 ; is still o 5. Wrap i up by creating a project called "multiplication" under your workspace in IAR. Design an assembly program to compute 3 X 39h, where 3 is the multiplicand, and 39h is the multiplier Add your code in-between MOV.W and JMP in the template generated from the wizard. Make sure your initialize the R4, R5, R6, and R7 upfront. Put a statement in the loop to toggle the LED on your MSP430 hardware. That way you are sure your program is running on the hardware when you step over the code. You may want to refer to the previous lab for this purpose checkStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started