Exam 1: EE319K Spring 2013 Exam 1 (Practice 1)
Exam 1: EE319K Spring 2013 Exam 1 (Practice 1)
Exam 1: EE319K Spring 2013 Exam 1 (Practice 1)
Exam 1
Date: February 21, 2013; 9:30-10:45am
Printed Name:
Last, First
Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat
on this exam:
Signature:
Instructions:
Closed book and closed notes.
No calculators or any electronic devices (turn cell phones off).
You must put your answers on pages 2-6 only.
You have 75 minutes, so allocate your time accordingly.
Show your work, and put your answers in the boxes.
Please read the entire quiz before starting.
EE319K Spring 2013 Exam 1 (Practice 1) Page 2
-117-128+11= -117
LM3S/LM4F
PE0
EE319K Spring 2013 Exam 1 (Practice 1) Page 3
Question 3
Part a) (10 points). Write an assembly subroutine, called ROL, that rotates a 32-bit number given in
R1 a number of times given in R2. That is, the input is passed by value in Registers R1 and R2, and the
output is returned in Register R3. You may use Registers R3 and R12 as scratch registers without
saving and restoring them. Notice that rotating an n-bit number k places to the left is the same as
rotating it n-k places to the right. (Check the ROR instruction)
Part b) (5 points). What specific modifications must be done to the subroutine in part (a) so that the
subroutine is AAPCS compliant?
; Inputs: R0 has number to rotate; R1 has places to rotate
; Output: R0 has result (R0 rotated left R1 places)
ROL MOV R3,#32
SUB R3,R3,R1 ;32-R1
ROR R0, R0, R3 ; rotate right
BX LR
ROL
EE319K Spring 2013 Exam 1 (Practice 1) Page 4
Part b) Given the state of the stack after part a), show the content of the stack, the SP and registers R3,
R4 after the following operation:
POP {R3-R4}
0x200003F4
0x200003F8 5
0x200003FC 3
SP-> 0x20000400 8
0x20000404 12
0x20000408
0x2000040C
R3: 5 R4: 3
Part c) Given the state of the stack after part b), show the content of the stack, the SP and registers R0-
R3 after the following operation:
PUSH {R0-R1}
POP {R0-R3}
0x200003F4
0x200003F8 12
0x200003FC 3
0x20000400 8
0x20000404 12
SP-> 0x20000408
0x2000040C
Part (a) Write a C function Init that initializes Port B, pins 0 and 7 as outputs, and pins 3 and 4 are
to be made input. (Ignore pull-up, pull-down resistors or high-amp drivers for outputs).
//Initializes GPIO port B with pins 0,7 as outputs and pins 3,4 as inputs
void Init(void) {
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_GPIOB; //Enable Clock
GPIO_PORTB_DIR_R |= 0x81; //pins 0,7 are output
GPIO_PORTB_DIR_R &= ~0x18; //pins 3,4 are input
GPIO_PORTB_AFSEL_R &= ~0x99; // Regular function
GPIO_PORTB_DEN_R |= 0x99; // Enable 0,3,4 and 7 pins
Part b) Assume the initialization in part a) has been executed. Write C function that toggles PB0 and
PB7 only when both inputs PB3 and PB4 are high. Otherwise PB0, PB7 are both off.
//Checks if both PB3 and PB4 are high and only then toggles PB0 and PB7
// otherwise turns both off.
void doIt(void) {
if((GPIO_PORTB_DATA_R & 0x18) == 0x18) {
GPIO_PORTB_DATA_R ^= 0x81;
} else {
GPIO_PORTB_DATA_R &= ~0x81;
}
}
EE319K Spring 2013 Exam 1 (Practice 1) Page 6
b. In C what is the size in bytes for each of the following data types:
Data Type Size(in bytes)
uint16_t 2
int32_t 4
int8_t 1
c. Register R1 has the value 0x80008001, what is its value after the following operations are
performed independently:
Operation R1
LSR R1,R1,#3 0x10001000
LSL R1,R1,#4 0x00080010
ASR R1,R1,#1 0xC0004000
Statement Purpose
EXPORT Start Put a symbol in global symbol table
When a C Program can calls an assembly subroutine the 2nd parameter it passes can be
found in register___R1____________