midterm17f-soln

.pdf

School

University of Michigan *

*We aren’t endorsed by this school

Course

373

Subject

Electrical Engineering

Date

Feb 20, 2024

Type

pdf

Pages

5

Uploaded by GeneralTarsierMaster519

EECS 373 Midterm 1 Fall 2017 27 September 2017 No calculators or reference material. Pledge: I have neither given nor received aid on this exam nor observed anyone else doing so. Signature: Name: Unique name: 1. (10 pts.) Build process (a) (3 pts.) Consider the following makefile definition and rule. CFLAGS = -mcpu=cortex-m3 -mthumb -g3 -O1 %.o: %.c Makefile ${PREFIX}gcc ${CFLAGS} -c -o $@ $< ${PREFIX}objdump -D $@ > ‘basename $@ .o‘.lst ${PREFIX}nm $@ > ‘basename $@ .o‘.nm If the user has just completed a build, changes the CFLAGS optimization level in the makefile to 3, and types make again, will the source files be recompiled? Yes / No (b) (4 pts.) Sometimes a linker adds new labels and code to a program. Here is one such example. __*ABS*0x4000001_veneer: ldr pc, [pc, #-4] ; 2000001c <__*ABS*0x4000001_veneer+0x4> streq r0, [r0], #-1 When a program branches to this label, will the streq instruction be executed? Yes / No (c) (3 pts.) Circle the tool with the job of finalizing the offset literals within branch instructions. Compiler Assembler Linker 1
Make 2. (10 pts.) Interrupts (a) (2 pts.) Using one sentence, explain preemption. Preemption is the process of temporarily interrupting a running task to run another. (b) (1 pts.) Using one sentence, explain why it is useful in embedded systems. Preemption allows for system critical tasks to take priority when necessary. (c) (7 pts.) You have designed a robot controller with three external interrupts. Interrupt A occurs when the robot detects it will soon collide with an object. It is in the highest priority group (priority group 1) and has a subpriority of 2. Interrupt B occurs when the robot’s battery energy is low. It is also in the highest priority group (priority group 1) and has a subpriority of 3. Interrupt C occurs when the robot enters a power saving mode. It is in priority group 2 and has a subpriority of 1. For each of the following situations, indicate the order in which interrupts are handled by the processor, using “A”, “B”, and “C”. Assuming “handle” means “enter ISR”. i. All of the interrupts occur at the same time. A, B, C ii. Interrupt C is executing when interrupts A and B trigger at the same time. A, B, C iii. Interrupt B is executing when interrupts A and C trigger at the same time B, A, C 3. (10 pts.) MMIO Write a C function that takes an integer input, compares the input to a threshold, and turns on a LED if and only if the input is greater than the threshold. The LED is mapped to memory address 0x45001234 and has two states: on and off. The threshold value is an integer with range [0:255] and can be read from the register mapped to memory address 0x4500FFFF. The LED is active-high. void LEDoutput(int val) { volatile uint32_t * threshold_reg = (uint32_t *)(0x4500ffff); volatile uint8_t * led_reg = (uint8_t *)(0x45001234); if(val > *threshold_reg) { *led_reg = 1; } else { *led_reg = 0; } } 4. (10 pts.) The C implementation of greatest arr is on this page. The next page contains an assembly version with some lines missing. Fill in the missing lines so that the function works properly and is ABI compliant. The fill function takes in an array and places some values into it. This is a simple example of allocating an integer on the stack. Note that the stack grows downwards, and the integer is deallocated by adding to the stack pointer. allocate_int: sub sp, #4 mov r0, #2 str r0, [sp] add sp, #4 2
void greatest_arr(uint32_t arr1[], uint32_t return_arr[]){ uint32_t arr2[5]; int i = 0; fill(arr2); for(; i < 5; i++){ if(arr1[i] >= arr2[i]){ return_arr[i] = arr1[i]; } else { return_arr[i] = arr2[i]; } } return; } greatest_arr: push{r4, r5, r6, lr} sub sp, #20 mov r2, r0 //r2 = arr1 mov r0, sp // r0 = arr2 for fill, r1 = return_arr push{r0, r1, r2} bl fill pop{r0, r1, r2} mov r3, #0 // r3 = i mov r4, #5 // end loop loop: lsl r0, r3, #2 // r0 = i*4 ldr r5, [r2,r0] // r5= arr1[i] ldr r6, [sp, r0] // r6 = arr2[i] cmp r5, r6 blt else if: str r5, [r1,r0] //return_arr[i] = arr1[i] b endif else: str r6, [r1, r0] //return_arr[i] = arr2[i] endif: add r3, r3, #1 // i= i+ 1 cmp r3, r4 blt loop // branch if i < 5 add sp, #20 pop{r4, r5, r6, lr} bx lr 5. (10 pts.) Instruction Encoding Provide the machine code in hexadecimal for the following instructions. See the attached reference. Assume UAL. (a) (3 pts.) strb r1, [r2, #7]: 71d1 (b) (4 pts.) ldrh r7, [r2, #100]: f8b2 7064 (c) (3 pts.) cmp r2, #32: 2a20 3
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