Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using the MSP430 micro chip and code composer studio to come up with a program that follows the paper...i attempted it but still cant find

using the MSP430 micro chip and code composer studio to come up with a program that follows the paper...i attempted it but still cant find a solution

image text in transcribed

image text in transcribed

mov.w #5, R4 ;set up the initial a value in R4 clr.w R5 clr.w R6 clr.w R7 clr.w R8 Xcalc mov.w R4, R5 ;copy the a value into R5call #ABSOL ;computer the absolute value of a in R5Summation mov.w R5, R6 ;starting the upper limit with value a of the summation in R6call #FACTO ;get the factorial value of R6 and save in R6; finish Xcalcby dobling the value and adding it to accumulator R8,;repeat the loop with a-1, a-2 (in R5) till lower value a=0;save the Xcalc results in R5Fcalc mov.w R5, R7 ;start F calculation ;finish Fcalc by adding the constant 50 and dividing by 4 (hint shift twice to the right with carry=0) loop jmp loop ;loop in place;Absolute subroutine take a value form R5 and converts it to its absolute value ABSOL: tst R5jn twoscomplrettwoscompl inv R5inc R5ABSOLend ret; Factorial subroutine takes number n form R6 and compute/save n! in R6;You need to replace the NOP with your actual n! calculation as given in class;You must push/pop all registersFACTO:;write the factorial subroutine;you start with value n in R6, then multiply with n-1, n-2, ..1;use the MULT subroutine to multiply R5 to R6 registersFACTOend ret;The multiplier subroutine based on shift and add;It takes R5 as the multiplier and R6 as the multiplicand;to avoid multiplication overflow, both R5 and R6 should be limited to one byte and thus ANDed with 0X00FF.;but due to factorial calculation, we will not mask R6 to let it grow beyond 255MULT:push.w R5;push.w R7;push.w R8;mov.w #8, R8 ;8 bit multiplication, so we loop 8 timesclr.w R7 ;additive accumulator should start with zeroand.w #0x00FF, R5 ;clear upper 8 bits of multiplier;and.w #0x00FF, R6 ;clear upper 8 bits of multiplicandnextbit rrc.w R5 ;shift multiplier bits one at a time to the carry jnc twice ;if no carry skip the addaddmore add.w R6, R7 ;add a copy of the multiplicand to the accumulatortwice add.w R6, R6 ;multiplicand times 2, (shifted 1 bit left)dec.w R8 ;dec loop counterjnz nextbit ;jump to check next bit of the multipliermov.w R7, R6 ;save the result in R6pop.w R8;pop.w R7;pop.w R5;MULTend ret

120] 3) Implement the following arithmetic function using subroutines and develop the code to be as efficient as possible. The only input to the function is variable (a) that is initialized in register R4 at the beginning of the program to 5 and maintained thereafter. The X calculation result is stored in R5. The final answer, F, is stored in R7 X +50 where = i-0 12] 3.a) Write an MSP430 assembly language program that implements the above function using subroutines for Multiplication and Factorial. The overall program structure should be as follows. Please note that the multiply subroutine is included in the skeleton code. Please review how it works: #--STACK-END , SP #NDTPWHDTHOLD,&NDTCTL ;Initialize stack pointer ;Stop WDT RESET mov.w StopWDT LAB2 CLEAR mov.w #5, R4 ;Load "a" into R4 mov.w clr R5 clr R6 clr R7 clear the entire register ;clear the entire register ;clear the entire register ithe X calculation part of your program :taking value of R4 as an input and returning result X in R5 XCALC . ;the final part of your program ;taking inputs from R5 and returning result F in R7 FCALC MainLoop jmp Mainloop Infinite Loop MULT : Included in the skeleton code 12] for Main Program- [1] XCALC, [1] FCALC [10] for Factorial Subroutine

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions