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

design and write an MSP430 assembly language subtoutine 4. (25 points) Write a s

ID: 3749093 • Letter: D

Question

design and write an MSP430 assembly language subtoutine 4. (25 points) Write a subroutine Design and write an MSP430 assembly language subroutine i2a_s(char *a, int myl) that converts a 16-bit integer, myl, into a character array with elements corresponding to the hexadecimal representation of the integer. For example, an integer my13,486-0x34AE is converted into an array with 4 elements as follows a[0E', a[1]='A", a[2]=4', a[33'. The main program that calls the subroutine is shown below Ascii('A')-0x41, ascii('O')-0x30 RESET: StopWDT: mov .w # STACK END,SP ; Initialize stack pointer ; mov . w #WDTPHIWDTHOLD,&NDTCTL Stopwatchdog timer ; Main code here sub.w #4, SP mov.w SP, R14 mov.W myI, R4 push.w R14 call #i2a_s add.w #2, SP jmp $ ; allocate space for ascii chars ; R14 points to the allocated area ; integer is passed through R4 ; push the starting address on the stack call subroutine free space on the stack lend: myr: word 8x34AE Stack Pointer definition global-STACK-END .sect stack Interrupt Vectors .sect ".reset" MSP430 RESET Vector short RESET 12a s

Explanation / Answer

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

NAME main ; module name

PUBLIC main ; make the main label vissible

; outside this module

ORG 0FFFEh

DC16 init ; set reset vector to 'init' label

RSEG CSTACK ; pre-declaration of segment

RSEG CODE ; place program in 'CODE' segment

init: MOV #SFE(CSTACK), SP ; set up stack

main: NOP ; main program

MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer

BIS.B #0xFF,&P1DIR ; configure P1.x as output

BIS.B #0xFF,&P2DIR ; configure P2.x as output

BIS.B #0xFF,&P3DIR ; configure P3.x as output

BIS.B #0xFF,&P4DIR ; configure P4.x as output

MOV.W #arr1, R4 ; load the starting address of the array1 into the

register R4

MOV.W #arr2, R5 ; load the starting address of the array1 into the

register R4

; Sum arr1 and display

CLR R7 ; Holds the sum

MOV #8, R10 ; number of elements in arr1

lnext1: ADD @R4+, R7 ; get next element

DEC R10

JNZ lnext1

MOV.B R7, P1OUT ; display sum of arr1

SWPB R7

MOV.B R7, P2OUT

; Sum arr2 and display

CLR R7 ; Holds the sum

MOV #7, R10 ; number of elements in arr2

lnext2: ADD @R5+, R7 ; get next element

DEC R10

JNZ lnext2

MOV.B R7, P3OUT ; display sum of arr1

SWPB R7

MOV.B R7, P4OUT

JMP $

arr1 DC16 1, 2, 3, 4, 1, 2, 3, 4 ; the first array

arr2 DC16 1, 1, 1, 1, -1, -1, -1 ; the second array

EN