Sie sind auf Seite 1von 3

CME331: Microprocessor, 2018-19, Term 1

Assignment 3: 10 marks
Online submission is accepted ONLY. Please answer questions Q1 and Q2, scan, and upload in BB.
For Q3, upload your C-code (main.c) only.

Q1. Fill out the table below with the new value of the registers (R0, R1, R2) after the execution of each
assembly code. Write the results in Hexadecimal. [4 marks]
Note: You may verify the results by running the code in Keil uVision or CCS Simulator

Instruction R0 R1 R2

MOV R0, #0x45 0x45 0x00 0x00

MOV R1,#0x02 0x45 0x02 0x00

ADD R2, R0, R1 0x45 0x02 0x47

SUB R2, R0, R1 0x45 0x02 0x43

SUBS R2, R0, R1 0x45 0x02 0x43

AND R2, R0, #0x01 0x45 0x02 0x01

ORR R1, R0, #0x02 0x45 0x47 0x01

MOV R0, #0x0F 0x0F 0x47 0x01

ADD R1, R0, R2 0x0F 0x10 0x01

SUBS R2, R0, R1 0x0F 0x10 0xFFFF FFFF

Q2. What will be the final value of register R0 after executing the following code? You may write the new
value of R0 after every instruction is executed. [3 marks]

mydata .field 0xA0000120, 32 ;


MOV R0, #0x05 ; R0 = 0x05 (new value of R0 - example shown)
LSL R0, R0, #1 ; R0 = 0x0A
LDR R1, mydata ; ; R0 = 0xA0000120
ORR R0, R0, R1 ; R0 = 0xA000012A
ASR R0, R0, #1 ; R0 = 0xD0000095

Page | 1
CME331: Microprocessor, 2018-19, Term 1

Q3. (Exercise D4.20, p. 183) The circuit diagram shows below interfaces four switches to PD3-PD0 and four
LEDs to PE3-PE0. Switches PD3-PD2 represent a 2-bit unsigned number (i.e., 0, 1, 2, 3). Switches PD1-PD0
represent a second 2-bit unsigned number (i.e., 0, 1, 2, 3). The four LEDs display a 4-bit unsigned number in
binary (i.e., 0 to 15). Write software in C that initializes the ports, reads two 2-bit numbers from the switches,
multiplies them, and displays the result on the LEDs. [3 marks]

(a) Hardware setup for verification

Note: You may test your codes using the Launchpad and Digilent ADM as shown in the figure.

Page | 2
CME331: Microprocessor, 2018-19, Term 1

Sample Code:

#define SYSCTL_RCGC2 (*((volatile unsigned long *)0x400FE108))

// GPIO initialization p.610


#define GPIO_PORTD_DATA (*((volatile unsigned long *)0x400073FC)) // p.615, data port, bit masking, p.608
#define GPIO_PORTD_DIR (*((volatile unsigned long *)0x40007400)) // p.616, set data flow direction
#define GPIO_PORTD_AFSEL (*((volatile unsigned long *)0x40007420)) // p.625, enable alternate functions
#define GPIO_PORTD_DEN (*((volatile unsigned long *)0x4000751C)) // p.636, make port digital
#define GPIO_PORTD_PCTL (*((volatile unsigned long *)0x4000752C)) // p.641, port control (for alt. func. only)
#define GPIO_PORTD_PUR (*((volatile unsigned long *)0x40007510)) // p.631, enable weak-pull-up, needed for SW1 and SW2
#define GPIO_PORTE_DATA (*((volatile unsigned long *)0x400243FC))
#define GPIO_PORTE_DIR (*((volatile unsigned long *)0x40024400))
#define GPIO_PORTE_AFSEL (*((volatile unsigned long *)0x40024420))
#define GPIO_PORTE_DEN (*((volatile unsigned long *)0x4002451C))
#define GPIO_PORTE_PCTL (*((volatile unsigned long *)0x4002452C))
#define GPIO_PORTE_PUR (*((volatile unsigned long *)0x40024510))

void init_gpio (void);

void init_gpio (void) {


volatile unsigned long delay_clk; // delay for clock, must have 3 sys clock delay, p.424
SYSCTL_RCGC2 |= 0x00000018; // enable clock gating for port D and E, p.424
delay_clk = SYSCTL_RCGC2; // this is a dummy instruction to allow clock to settle, no-operation

GPIO_PORTD_DIR |= 0x00; // 0,1,2,3 are inputs (Port D)


GPIO_PORTD_DEN |= 0x0F;
GPIO_PORTD_AFSEL &= ~0x0F;

GPIO_PORTE_DIR |= 0x0F; // 0,1,2,3 are outputs (Port E)


GPIO_PORTE_DEN |= 0x0F;
GPIO_PORTE_AFSEL &= ~0x0F;
}

int main (void) {


init_gpio ();
int number;
int bin_val1;
int bin_val2;
while (1) {
number = GPIO_PORTD_DATA; //binary value from port D
bin_val1 = number& 0x03; //2 left bits
bin_val2 = (number >>2) &0x03 ; //shift 2 to the right, and assign only 2 bits
GPIO_PORTE_DATA = bin_val1*bin_val2; // multiplies
}
}

Page | 3

Das könnte Ihnen auch gefallen