I\'m having trouble writing the code for this program. Can i see how one would w
ID: 3826332 • Letter: I
Question
I'm having trouble writing the code for this program. Can i see how one would write the code for this question in C!!! Really appreciate your help
C Language Coding
Using C language and the DE2-115 Media Computer hardware configuration write a subroutine that will return a value from an array that is selected by an input parameter. Use the stack to pass the parameter in, and to return the value of the result. Test your subroutine by writing a program that initializes the stack and calls the subroutine in a loop and passes it the value of the four slide switches SW3…SW0. Write the value that is returned from the subroutine to the HEX0 display.
Use the following byte values to create the array:
0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x67, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71
Procedures, Stacks, and Arrays in C C Language Coding 1) Using C language and the DE2-115 Media Computer hardware configuration write a subroutine that will return a value from an array that is selected by an input parameter. Use the stack to pass the parameter in, and to return the value of the result. Test your subroutine by writing a program that initializes the stack and calls the subroutine in a loop and passes it the value of the four slide switches SW3...SWO. Write the value that is returned from the subroutine to the HEX0 display Use the following byte values to create the array: 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x67, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 2) Make sure your code is well documented, and that you use semantically meaningful variable and function names. 3) What do you observe as you change the SW values? 4) Write a short paragraph that compares this process in Cand Assembly 5) Turn in this short report with the source code.Explanation / Answer
#include "msp430.h" ;
NAME main ;
PUBLIC main ;
ORG 0FFFEh
DC16 init ;
RSEG CSTACK ;
RSEG CODE ;
init: MOV #SFE(CSTACK), SP ;
main: NOP ;
MOV.W #WDTPW+WDTHOLD,&WDTCTL ;
BIS.B #0xFF,&P1DIR ;
BIS.B #0xFF,&P2DIR ;
BIS.B #0xFF,&P3DIR ;
BIS.B #0xFF,&P4DIR ;
MOV.W #arr1, R4 ;
register R4
MOV.W #arr2, R5 ;
register R4;
CLR R7 ;
MOV #8, R10 ;
lnext1: ADD @R4+, R7 ;
DEC R10
JNZ lnext1
MOV.B R7, P1OUT ;
SWPB R7
MOV.B R7, P2OUT;
CLR R7 ;
MOV #7, R10 ;
lnext2: ADD @R5+, R7 ;
DEC R10
JNZ lnext2
MOV.B R7, P3OUT ;
SWPB R7
MOV.B R7, P4OUT
JMP $
arr1 DC16 1, 2, 3,1, 2, 3 ;
arr2 DC16 1, 1, -1,-1 ;
END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.