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

4. (25 points) Write a subroutine Design and write an MSP430 assembly language s

ID: 3749199 • Letter: 4

Question

4. (25 points) Write a subroutine Design and write an MSP430 assembly language subroutine 12a_s(char *a, int myl) that converts a 16-bit integer, myi, into a character array with eiements corresponding to the hexadecimal representation of the integer. For example, an integer my 13,486-0x34AE is converted into an array with 4 elements as follows: alol-E', a[1] 'A', a[2]'4', a[3]s3. The main program that calls the subroutine is shown below. Ascli('A')-0x41, ascll('O')-0x30. RESET: stopWDT: mov Initialize stack pointer Stop watchdog timer mov.w STACK END,SP DTPWWDTHOLD, &HDTCTL ; Main code here Sub. #4. SP mov.w SP, R14 mov.w myl, R4 push.w R14 call #12a s add .w #2, SP : allocate soace for ascii c ; 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: .word x34AE ; Stack Pointer definition .sect .stack Interrupt Vectors .sect".reset" .short RESET MSP430 RESET Vector

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote