C和汇编代写-EL648
时间:2022-03-21
NYU TANDON SCHOOL OF ENGINEERING Name: ________________________________
EL648 – Real Time Embedded Systems ID: ________________________________
Midterm 1 Fall 2021
Instructions: Answer all questions on this paper. You may use any reference materials from class or
from our class websites and/or reference sheets.

Question 1:
Although GPIO is not specifically part of this exam, we spent a significant amount of time in class
discussing how to read and write memory using both C and assembly. Since our architecture uses
memory mapped I/O, setting up the GPIO registers is simply reading and writing the appropriate
memory locations. The following algorithm can be used for our controller to do a block GPIO write,
meaning writing all port pins (15 in total) simultaneously, for any port (say PORTA).
PORTA has a base address of 0x40020000

A. Set each pin in the MODER register to general purpose output mode





B. Set each pin in the OTYPER register to output push-pull

C. Set each pin in the PUPDR register to 0, meaning no pull up or down resistor









D. Set the ODR register bits to a 1 or 0, depending on if the pin is turned on or off.

a. Write a C function:

uint32_t BlockWritePortA(uint16_t PinVals) {
//Code Here
}
PinVals is a 16 bit number with 1’s in positions to turn “on” and 0’s in the pin positions to turn
“off”. The function should implement algorithms parts A., B., C. and D. described above and
return the value of the ODR register above. Note, the addresses of the registers (memory) are
the Base Address + Offset as indicated above.
b. Write an ARM assembly function called “_BlockWritePortA” that implements part A
above.
NOTE: Be careful how you use LDR, as there are limits to the “mem” parameter!
.globl _BlockWritePortA
.syntax unified

_BlockWritePortA
;
; Code Here
;
bx lr
c. Write the short C program that calls the ARM Assembly function _BlockWritePortA in its
main();

Question 1 Solution:
Question 2:
Consider the following ARM assembly code segment.
a. Accurately comment each line of code
b. Describe what parameters r0 and r1 (passed into the function) are used for.
c. What are each of the local variables r4-r8 used for?
d. What is the purpose of this function?
e. Explain in detail the specific purpose of “stmfd” and “ldmfd” in this function.

.globl _MyFunc
.text
_MyFunc:
stmfd sp!, {r4, r5, r6, r7, r8, lr}
cmp r1, #1
ble end_outer

sub r5, r1, #1
mov r4, r0
mov r6, #0

loop_start:
ldr r7, [r4], 4
ldr r8, [r4]
cmp r7, r8
ble no_go

mov r6, #1
sub r4, r4, 4
swp r8, r8, [r4]
str r8, [r4, 4]!
no_go:
subs r5, r5, #1
bne loop_start

end_inner:
cmp r6, #0
beq end_outer

mov r6, #0
mov r4, r0
sub r5, r1, #1
b loop_start

end_outer:
ldmfd sp!, {r4, r5, r6, r7, r8, pc}

Question 2 Solution:


essay、essay代写