Exam-Microcomputers-Exam Paper 03-Electrical and Computer Engineering, Exams of Microcomputers

PIC24, Assembly Language, Arithmetic, Overflow, Indirect Addressing, Stack Frame, Weak Internal Pullup, Open Drain Output, Processor, Microcomputers, Exam Papers, Dr Jeff Jackson, Department of Electrical and Computer Engineering, University of Alabama, United States of America.

Typology: Exams

2011/2012

Uploaded on 03/02/2012

cristelle
cristelle 🇺🇸

4.5

(53)

374 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE383 Sample questions for Exam #2 The exam will be open book/notes.
The exam will focus on material from lecture 5 through lecture 8, slide 25. Knowledge from earlier lectures (1-4) may be
required, but will not be the focus of the exam questions.
1. Write PIC24 assembly language equivalents for the following C code fragments.
uint32 i, j, k;
int32 x, y, z;
i=j+k;
x=y-z;
int32 r, s;
int16 t;
if(r<10) r++;
s=(int32) t;
// i=j+k;
mov j,w2
mov j+2,w3
mov k,w0
mov k+2,w1
add w0,w2,w0
addc w1,w3,w1
mov w0,i
mov w1,i+2
// x=y-z;
mov z,w2
mov z+2,w3
mov y,w0
mov y+2,w1
sub w0,w2,w0
subb w1,w3,w1
mov w0,x
mov w1,x+2
//if(r<10) r++;
mov r,w2
mov r+2,w3
mov #9,w0
mov #0,w1
sub w2,w0,w4
subb w1,w3,w5
bra gt,end_if
mov r,w2
mov r+2,w3
add w2,#1,w2
addc w2,#0,w3
mov w2,r
mov w3,r+2
end_if:
pf3
pf4
pf5

Partial preview of the text

Download Exam-Microcomputers-Exam Paper 03-Electrical and Computer Engineering and more Exams Microcomputers in PDF only on Docsity!

ECE383 Sample questions for Exam #2 The exam will be open book/notes.

The exam will focus on material from lecture 5 through lecture 8, slide 25. Knowledge from earlier lectures (1-4) may be required, but will not be the focus of the exam questions.

  1. Write PIC24 assembly language equivalents for the following C code fragments.

uint32 i, j, k; int32 x, y, z;

i=j+k; x=y-z;

int32 r, s; int16 t;

if(r<10) r++; s=(int32) t;

// i=j+k; mov j,w mov j+2,w mov k,w mov k+2,w add w0,w2,w addc w1,w3,w mov w0,i mov w1,i+

// x=y-z; mov z,w mov z+2,w mov y,w mov y+2,w sub w0,w2,w subb w1,w3,w mov w0,x mov w1,x+

//if(r<10) r++; mov r,w mov r+2,w mov #9,w mov #0,w sub w2,w0,w subb w1,w3,w bra gt,end_if mov r,w mov r+2,w add w2,#1,w addc w2,#0,w mov w2,r mov w3,r+ end_if:

// s=(int32) t; mov t,w clr w btsc w0,# setm w mov w0,s mov w1,s+

  1. Give an example of arithmetic overflow when adding two unsigned 8-bit numbers.

0xFF+0x01=0x

  1. Give an example of arithmetic overflow when adding two signed 8-bit numbers.

0x7F+0x01=0x

  1. How is overflow detected in hardware?

V=C (^) MSB xor C (^) MSB-

  1. Given the following PIC24 assembly language code, give the machine code for the branch instruction.

Location Machine Code Label Instruction

0200 loop_top

0202

0204

0206 31FFFC^ bra geu,loop_top

  1. Assume the following C code is executed.

int16 i, j, k; int16* p_i; i=0x4000; j=0xFFFF; p_i=&i; k=*p_i;

Give the values of the following memory locations after all the instructions have executed. Complete all cells in the table.

Location Variable Contents

0x800 i 0x

0x802 j 0xFFFF

0x804 k 0x

0x806 p_i 0x

Give the assembly language implementation of the above C code. You must use register indirect addressing to implement *p_i.

mov #0x4000,w mov w0,i setm w mov w0,j mov #i,w mov w0,p_i mov p_i,w

13: int8 i, j; 14: i=5; 02B6 B3C050 mov.b #0x5,0x 02B8 984710 mov.b 0x0000,[0x001c+1] 15: j=my_sub(i); 02BA 90401E mov.b [0x001c+1],0x 02BC 07FFE9 rcall 0x 02BE 784F00 mov.b 0x0000,[0x001c] 16: return 0; 02C0 EB0000 clr.w 0x 17: } 02C2 FA8000 ulnk 02C4 060000 return

  1. What are the differences, and similarities, between LATx and PORTx?

When performing write operations to a pin on the PIC24, the LATx and PORTx function the same (i.e. they both write to the LATx register). When performing reads, a LATx read reads from the LATx register while a PORTx read is directly from the pin.

  1. What is the purpose of weak internal pullup and open drain output capabilities on the PIC24 processor?

The weak internal pullup capability is provided so that an external pullup resistor is not needed on pins with CNy functionality. The open drain output allows an external pullup resistor to be used to pull output pins up to logic ‘1’ where the output voltage may be something other than the typical +3.3V.

  1. What is the purpose of the MCLR# pin on the PIC24 processor?

The MCLR# pin on the PIC24 processor is used to reset that processor when the pin is asserted low.

  1. Assume the following circuit is used in a PIC24 system.

a) Write an inline macro named CONFIG_SW1() that, when used, would correctly configure RB12 as a digital input as shown.

inline void CONFIG_SW1() { CONFIG_RB12_AS_DIG_INPUT(); ENABLE_RB12_PULLUP(); }

b) Write an inline macro named CONFIG_LED1() that, when used, would correctly configure RB13 as a digital output as shown.

#define CONFIG_LED1() CONFIG_RB13_AS_DIG_OUTPUT()

c) Write an inline macro named CONFIG_LED2() that, when used, would correctly configure RB14 as a digital output as shown.

#define CONFIG_LED2() CONFIG_RB14_AS_DIG_OUTPUT()

d) What is the purpose of the two resistors in series with LED1 and LED2?

They function as current limiting resistors so that the maximum current source/sink for the PIC24 processor will not be exceeded.

e) Write a C program that would use the macros defined above and would alternate lighting LED1 and LED2 every time SW1 is pressed.

#define LED1 _LATB #define LED2 _LATB #define CONFIG_LED1() CONFIG_RB13_AS_DIG_OUTPUT() #define CONFIG_LED2() CONFIG_RB14_AS_DIG_OUTPUT()

inline void CONFIG_SW1() { CONFIG_RB12_AS_DIG_INPUT(); ENABLE_RB12_PULLUP(); }

#define SW1 _RB #define SW1_PRESSED() SW1== #define SW1_RELEASED() SW1==

main() { CONFIG_SW1(); CONFIG_LED1(); CONFIG_LED2(); LED1=0; LED2=0; while(1) { while(SW1_RELEASED()); DELAY_MS(15); while(SW1_PRESSED()); DELAY_MS(15); LED1=1; LED2=0; while(SW1_RELEASED()); DELAY_MS(15); while(SW1_PRESSED()); DELAY_MS(15); LED1=0; LED2=1; } }