homework7

docx

School

North Park University *

*We aren’t endorsed by this school

Course

266

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

3

Uploaded by GrandLapwing1439

Report
ECE 266 – Introduction to Embedded Systems Spring 2024 Homework #7 Due: Wednesday, Mar. 6 Notes: a) Complete the assignment electronically and submit a PDF file on BlackBoard. You also need to submit an assembly program file. b) The submission will be graded by evaluating your effort level, not correctness. You are expected to show your best effort, and you may get the credit even if your answers are not all correct. Specially, for each problem, you should 1) show that you have a correct understanding of the problem; 2) use a reasonable approach to solve the problem; and 3) if required, show a complete procedure of solving in addition to the answer. c) It is suggested that you complete this week’s readings before you start on the homework. d) If you discuss this homework assignment with any of your classmates, claim so and state the name(s) of discussion participant(s). The discussion should be about the knowledge and skills related to the questions, not the solutions. Solution sharing is strictly prohibited . e) Late homework is NOT accepted. You may request an extension or exemption for a valid excuse (emergency, travel, etc.). Send the request by email to the instructor. f) The number in brackets for each exercise is an indication of the time (in minutes) needed to complete the exercise. Discussed with (if any): __________________ Readings: Textbook, Chapter 5, “Load and Store” Questions 1 and 2: You must test your solution code in the CCS/LaunchPad platform. Do the following before you start on questions 1 and 2. i. Download the attached file homework7_main.c , homework7.h , and homework7_asmfunc.asm into a folder named “Homework7”. ii. In CCS, create a CCS project named “Homework7” with external reference to this folder. Double check that the above files have been added automatically to the project. iii. Put your solution codes in homework7_asmfunc.asm , which is a template. iv. Start the terminal program putty or the CCS built-in terminal. v. Build the project and run the program. The test output will be shown on the terminal window. Note: Even if the test output looks all correct, your codes may still contain bugs. If so, partial credit will be given. Submit 1) homework6.pdf, 2) your revised homework6_asmfunc.asm, and 3) a screenshot of CCS showing the testing output. You don’t have to put the assembly code in this file.
1. [25] Write four assembly functions that copy an int array of four elements. They have to use pre- index, pre-index with update, post-index, and register offset in most (not necessarily all) load/store instructions, respectively. The following are their function porotypes. Note that the arrays are of fixed size, so you don’t have to use any loop. Hint : Review the examples in the related lecture slides. // Copy functions: Copy from array X[] to array Y[], each of four elements void copy4ByPreIndex( int Y[], int X[]); void copy4ByPreIndexUpdate( int Y[], int X[]); void copy4ByPostIndex( int Y[], int X[]); void copy4ByRegOffset( int Y[], int X[]); 2. [10] Write an assembly instruction that swaps the i -th element of array X[] and array Y[]. Note that the array elements are short type. // swap() function: Swap X[i] and Y[i] void swap2( short X[], short Y[], int i); The following is the correct test output: *** Test copyArray functions *** By pre-index: X1[] = {10, 20, 30, 40}, Y1[] = {10, 20, 30, 40} By pre-index with update: X1[] = {10, 20, 30, 40}, Y1[] = {10, 20, 30, 40} By post-index: X1[] = {10, 20, 30, 40}, Y1[] = {10, 20, 30, 40} By register offset: X1[] = {10, 20, 30, 40}, Y1[] = {10, 20, 30, 40} *** Test swap *** First swap, index 1: X2[] = {1, -2, 3, 4, 5}, Y2[] = {-1, 2, -3, -4, -5} Second swap, index 3: X2[] = {1, -2, 3, -4, 5}, Y2[] = {-1, 2, -3, 4, -5} 3. [10] Textbook Chapter 5, Exercise 5 revised. Given the following memory content: Memory address Data 0x20008002 0xA1 0x20008001 0xB2 0x20008000 0xC3 0x20007FFF 0xD4 0x20007FFE 0xE5 What is the value in register r1 after the CPU executes the following instructions if r0 = 0x20008000? Assume the system is little endian (in this course, assume little endian unless stated otherwise). The sub-questions are independent. 1) LDRSB r1, [r0] 2) LDRSH r1, [r0] 3) LDRB r1, [r0] 4) LDRH r1, [r0]
4. [10] Textbook Chapter 5, Exercise 6. Suppose r0 = 0x20008000. What address is register r7 loaded from in the following instructions? What is the value of r0 after executing each instruction? Assume each instruction runs separately, i.e., they are independent. 1) LDMIA r0, {r1, r3, r7, r6, r2} 2) LDMIB r0, {r1, r3, r7, r6, r2} 3) LDMDA r0, {r1, r3, r7, r6, r2} 4) LDMDB r0, {r1, r3, r7, r6, r2} 5. [10] Textbook Chapter 5, Exercise 7. Suppose r0 = 0x20008000. What address is register r7 stored at in the following instructions? What is the value of r0 after executing each instruction? Assume each instruction runs separately, i.e., they are independent. 1) STMIA r0!, {r3, r9, r7, r1, r2} 2) STMIB r0!, {r3, r9, r7, r1, r2} 3) STMDA r0!, {r3, r9, r7, r1, r2} 4) STMDB r0!, {r3, r9, r7, r1, r2} Optional: Do the self-review exercises of Ch. 5 (the 4 th edition of the textbook only).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help