Question: Skeleton code: ;------------------------------------------------------------------------------- ; MSP430 Assembler Code Template for use with TI Code Composer Studio ; ; ;------------------------------------------------------------------------------- .cdecls C,LIST,msp430.h ; Include device header file

 Skeleton code: ;------------------------------------------------------------------------------- ; MSP430 Assembler Code Template for use with
Skeleton code:
;-------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;
;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file
;-------------------------------------------------------------------------------
.text ; Assemble into program memory
.retain ; Override ELF conditional linking
; and retain current section
.retainrefs ; Additionally retain any sections
; that have references to current
; section
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; your lab3 code is here between double dashed lines
; below is the
Lab3 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 R5
call #ABSOL ;computer the absolute value of a in R5
Summation mov.w R5, R6 ;starting the upper limit with value a of the summation in R6
call #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 R5
Fcalc 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 R5
jn twoscompl
ret
twoscompl inv R5
inc R5
ABSOLend 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 registers
FACTO:
;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 registers
FACTOend 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 255
MULT:
push.w R5;
push.w R7;
push.w R8;
mov.w #8, R8 ;8 bit multiplication, so we loop 8 times
clr.w R7 ;additive accumulator should start with zero
and.w #0x00FF, R5 ;clear upper 8 bits of multiplier
;and.w #0x00FF, R6 ;clear upper 8 bits of multiplicand
nextbit rrc.w R5 ;shift multiplier bits one at a time to the carry
jnc twice ;if no carry skip the add
addmore add.w R6, R7 ;add a copy of the multiplicand to the accumulator
twice add.w R6, R6 ;multiplicand times 2, (shifted 1 bit left)
dec.w R8 ;dec loop counter
jnz nextbit ;jump to check next bit of the multiplier
mov.w R7, R6 ;save the result in R6
pop.w R8;
pop.w R7;
pop.w R5;
MULTend ret
;end of you code between double dashed lines
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET

20] 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 R5The final answer, F, is stored in R7. F-C.tw) X +50 4 wherex-(2(i !)) [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: Initialize stack pointer ;Stop WDT RESET mov.w # STACK END,SP StopWDT LAB2 CLEAR mov .wFHDTPHHDTHOLD,&kDTCTL mov.w #5, R4 ; Load "a" into R4 clr RS clr R6 cir R7 jclear the entire register clear the entire register clear the entire register :the X calculation part of your program ;taking value of R4 as an input and returning result X in R5 XCALC.... FCALC.... MainLoop jmp Mainloop Infinite Loop ithe final part of your prograrm itaking inputs from R5 and returning result F in R7 Included in the skeleton code MULT 12] for Main Program -[1] XCALC, [1] FCALC [10] for Factorial Subroutine

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!