Modify the main program and the subroutine so that the input and output to the s
ID: 655360 • Letter: M
Question
Modify the main program and the subroutine so that the input and output to the subroutine are handled on the stack and not through the core registers.
The code is running on Launach pad MSP-EXP430G2551
;-------------------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;-----------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file
;----------------------------------------------------------------------------------------
.data
Result: .space2
;--------------------------------------------------------------------------------------
.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
;-------------------------------------------------------------------------------------------
; Main loop here
mov.w #28, R10 ; prepare input for TwosComp
call #TwosComp ; call subroutine TwosComp
mov.w R11, &Result ; move result from TwosComp to variable Result
; call subroutine TwosComp
Loop: jmp Loop
;----------------------------------------------------------------------------------------
; Subroutine: TwosComp
; ; Input: R10, R10 modified
; Ouput: R11 : 2's comliment of R10
; ;-------------------------------------------------------------------------------------------
TwosComp:
sub.w #4, SP ; reserve space on the stack for 0(SP) and 2(SP)
; 0(SP) -> index for the for loop
; 2(SP) -> variable with the moving bit to be used with bit.w, bis.w and bic.w
mov.w #1, 2(SP)
;------------------- start for loop --------------------------------
mov.w #0, 0(SP)
for_cond_label:
cmp.w #16, 0(SP)
jge for_break
;------------ start if-else ------------------------------
bit.w 2(SP), R10
jc if_label
bis.w 2(SP), R10
jmp if_break
bic.w 2(SP), R10
if_label:
if_break:
rla.w 2(SP)
inc.w 0(SP)
jmp for_cond_label
;----------------- end if-else----------------------------------
for_break:
mov.w R10, R11
inc.w R11
;---------------------- end for loop ---------------------------
add.w #4, SP ; release space on the stack
ret
;---------------------------------------------------------------------------------
; Stack Pointer definition
;--------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-----------------------------------------------------------------------------------
; Interrupt Vectors
;--------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
Explanation / Answer
The code is running on Launch pad MSP-EXP430G2551
;-------------------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;-----------------------------------------------------------------------------------
.cdscl C,TITLE,"msp430.h" ; Include the device in the header file
;----------------------------------------------------------------------------------------
.term
Result: .space4
;--------------------------------------------------------------------------------------
.term ; Assemble into memory
.retain ; Override ELF linking
; and then retain the current section in it
.retain ;Now to retain any sections
; that have some references from the current
; section
;-------------------------------------------------------------------------------------
RESET mov.v #__STACK_END,SP ; Initialize stackpointer
StopWDR mov.v #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog
;-------------------------------------------------------------------------------------------
; Main loop start here
mov.v #56, R13 ; prepare the input for the TwoComp
call #TwoComp ; call subroutine TwoComp
mov.v R59, &Result
; Now to move the result from TwoComp to the variable Result
; call subroutine TwoComp
Loop: jmp
;----------------------------------------------------------------------------------------
; Subroutine: TwoComp
; ; Input: 45, R12 modif
; Ouput: R65 : 2's comliment of R12
; ;-------------------------------------------------------------------------------------------
TwoComp:
sub.v #6, SP ; reserve space on the stack for 3(SP) and 4(SP)
; 3(SP) -> index for the for loop
; 4(SP) -> having the variable with the moving bit to be used with bit.v, bit.v and bit.v
mov.v #4, 45(SP)
;------------------- start the for loop here --------------------------------
mov.v #3,10(SP)
for_cond_label:
cmp.v #32,6(SP)
for_break
;------------ Now start the if-else loop ------------------------------
bit.v 4(SP), R17
if_label
bit.v 3(SP), R11
jmp if_break
bit.v 5(SP), R12
if_label:
if_break:
rla.v 6(SP)
inc.v 4(SP)
jmp for_cond_label
;----------------- end of if-else condition----------------------------------
for_break:
mov.wvR15, R13
inc.v R41
;---------------------- end of the for loop ---------------------------
add.v #9, SP ; release the space on the stack
;---------------------------------------------------------------------------------
; Stack Pointer definition
;--------------------------------------------------------------------------------
.global __STACK_END
.set .stack
;-----------------------------------------------------------------------------------
; Interrupt the Vectors
;--------------------------------------------------------------------------------
.set ".reset" ; MSP430 RESET Vector
.short RESET
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.