ECE6483 Quiz Spring 2022 (Open book, notes and Laptop only) Name: _____________________________________
ID: _____________________________________
NYU Tandon School of Engineering
1. Observe the following ARM Assembly code implementation of Function:
Copyright By PowCoder代写 加微信 powcoder
EXPORT Function
stmfd sp!, {r2-r9, lr}
mov r4, r1
mov r3, r4
sub r1, r1, #1
mov r9, r1
mov r5, r0
mov r4, r3
add r2, r0, #4
ldr r6, [r5], #4
ldr r7, [r2], #4
cmp r7, r6
strhs r6, [r2, #-4]
strhs r7, [r5, #-4]
subs r4, r4, #1
subs r9, r9, #1
ldmfd sp!, {r2-r9, pc}^
Comment each line of this code and determine what this function does. Be specific about data type (bytes, long etc.) and memory locations.
2. Suppose I have the following C code snippet, which simply sums 6 numbers:
int sum6(int a1, int a2, int a3, int a4, int a5, int a6);
int main() {
int t; t=sum6(1,2,3,4,5,6); while(1);
int sum6(int a1, int a2, int a3, int a4, int a5, int a6) {
int total;
total =a1+a2+a3+a4+a5+a6; return total;
a. Write the equivalent ARM assembly code in the following structure. Be sure to comment each line.
AREA sum, CODE
EXPORT __main
__main PROC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; PUT YOUR CODE HERE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
stop B stop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; PUT YOUR CODE HERE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3. We learned in class how to set up GPIO pins for input and output. We also know that the vendor specific HAL provides libraries like DigitalWrite, DigitalRead etc. But often these libraries are bloated, since they need to support so many different possible configuration and need to be generic. This question requires us to write these two functions ourselves, so that we can do GPIO more efficiently.
SPECIFICALLY USING THE REGISTERS IN LECTURE 6 (for Arm Cortex M0+), implement the following functions:
Int MyPortWrite(int MyPort, int WriteMask, int MyPinValues)
//My port is 0 or 1 selecting the port
//WriteMask holds a 32 bit integer where there are 1¡¯s in the bits/pins you wish to write //MyPinValues has a 32 bit int with the write values for the pins indicated in WriteMask //Example: WritePort = 0, WriteMask=0x00002401=Pins 0, 10, and 13 are being written //MyPinValues = 0x00002400 = Write Port 0 Pin 0=0, Pin 10=1 and Pin 13 = 1 (ignore all //others)
//Don¡¯t forget to set DIR, INEN etc….And check for erroneous parameters //Return 1 if successful, 0 if failed
Int MyPortRead(int MyPort, int *PullEnable)
//My port is 0 or 1 selecting the port
//PullUpEnable holds the address of a 32 bit integer that returns the bit mask of those //pins already configured with the Pull resistor enabled.
//Example: MyPort = 0,
//MyPortRead = 0x00002401 = All pins on Port 0 are 0, except Pin 0, 10 and 13 //*PullEnable returns is assigned 0x01200480, Pins 7, 10, 21, and 24 have pull resistor //enabled
//Don¡¯t forget to set DIR, INEN etc….And check for erroneous parameters
//You may assume the port has already been configured.
//Return 1 if successful, 0 if failed
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com