Started onSaturday, 9 May 2020, 12:53 PM
StateFinished
Completed onSaturday, 9 May 2020, 2:52 PM
Time taken1 hour 59 mins

Question 1

Complete
Marked out of 1.00

Question text

What is the minimum number of bits that an Analogue to Digital Converter with a range of  0-5.0V  should have to accurately measure a signal at a resolution of at least 5.0mV?

Question 2

Complete
Marked out of 3.00

Question text

Following is an assembly program written for ATmega 2560 microcontroller to reverse a string using the stack.


.equ string_length = 12
.def zero = r17

.dseg
.org 0x380
reversed_string:
.byte string_length+1
xvar:
.byte 1

.cseg
.org 0x0000
jmp main

.org 0x0072
string:
.db "ha ha ha ha!",0

main:
;init stack pointer
ldi yl,low(0x1811)
ldi yh,high(0x1811)
out spl,yl
out sph,yh

;set xvar
ldi zl,low(xvar)
ldi zh,high(xvar)
ldi r16, -1
st z, r16

;string address in program mem
ldi zl,low(string<<1)
ldi zh,high(string<<1)

;init
clr xl
clr xh
clr zero

;loop for reading from program mem and pushing
loop:
lpm r16,z+
cpi r16,0
breq storeback
push r16
adiw xh:xl,1
rjmp loop

;loop for popping and storing to data mem
storeback:
ldi zl, low(reversed_string)
ldi zh, high(reversed_string)

loop2:
pop r16
st z+,r16
subi xl,1
sbc xh,zero
cp xl,zero
cpc xh,zero
breq end
rjmp loop2

;store nullchar
end:
st z+,zero

halt:
rjmp halt

What is maximum length of the string (string_length in the program) that can be reversed, without the stack overwriting the memory location of xvar?

Question 3

Complete
Marked out of 3.00

Question text

Consider two single precision floating point numbers x and y in IEEE 754 format, where x = 0xC0C80000 and y = 0x40D00000. What is the hexadecimal value of x-y?

Question 4

Complete
Marked out of 1.00

Question text

The following table contains partial information regarding the TCCR0B register, which is used for configuring timer0 in ATMega2560.

Assume the user wants to configure timer0 such that approximately 244 timer0 interrupts would occur per second.  The following code fragment was written by a designer who decided to calculate the value later and instead used XXXXXXXX for the bits to be used. Which value of XXXXXXXX would correctly configure timer0 so that it would have the desired property? You may assume the clock speed of ATMega2560 is 16 MHz and the size of the counter for timer0 is 8-bits. Assume X=0 for all bits that are unknown.

 

in  r16, TCCR0B
ldi  r16, 0bXXXXXXXX
out TCCR0B, r16

Question 5

Complete
Marked out of 1.00

Question text

  1. Which of the following programs will never go out of “AAA” segment?

i)              

AAA:

  ldi r16, 10

  ldi r17, 10

  cp  r16, r17

  jmp BBB

  rjmp AAA

BBB: …

 

ii)            

AAA:

  ldi r16, 11

  ldi r17, 10

  cp  r16, r17

  brge BBB 

  rjmp AAA

BBB: …

 

iii)          

AAA:

  ldi r16, 10

  ldi r17, 10

  cp  r16, r17

  brge BBB

  rjmp AAA

BBB: …

 

Choose your answer from the following: i, ii, iii, i and ii, i and iii, all, none

Question 6

Complete
Marked out of 1.00

Question text

Following is an assembly program written for ATmega 2560 microcontroller.


.macro delay
clr r16
loop:
inc r16
nop
nop
cpi r16, @0
brne loop
.endmacro

delay 27
delay 153
delay 74
delay 237

What is minimum number of bytes required in the program memory to store this program?

Question 7

Complete
Marked out of 3.00

Question text

Match the most suitable instruction to the description given below:

The most suitable instruction to perform add immediate is

The most suitable instruction to jump over one instruction if a bit in a register is 0

The most suitable instruction to set particular bits in a register

Set the least significant bit in the status register

Set the most significant bit in the status register

Supposing carry was set to 0. Which instruction would be most suitable to subtract one register value from another?

Question 8

Complete
Marked out of 2.00

Question text

  1. A C program consists of six functions. Their call relations are shown as follows (the arguments and irrelevant C statements are omitted.):

 

                     int main(void)

                      {

                         …

                           if (x>0) func1(…);

                           else       func2(…);

                           func3(…);

                           …

                       }

                     void func1(…)

                     {

                          …

                          func1(…);

                           …

                      }   

                    void func3(…)

                     {

                          …

                           func3(…);

                          …

                      }   

                     void func2(…)

                     {

                           …

                           if (y>0) func4(…);

                           else func5(…);

                            …

                      }             

 

 

Both func1() and func3() are recursive functions. main() calls either func1() or func2() only once depending on the value of x.  func1() calls itself 10 times for the actual parameters given in main(). func2() calls either func4() or func5() only once depending on the value of y. func3() calls itself 20 times for the actual parameters given in main().  Neither func4() nor func5() calls any function. The sizes of all stack frames are shown as follows:

 

                         main():   70 bytes.

                         func1():  100 bytes.

                         func2():  570 bytes.

                         func3():  40 bytes

                         func4():  70 bytes

                         func5():  50 bytes

 

Assume that no interrupt occurs during the execution of this program. How much stack space is needed to execute this program correctly in the worst case?

Question 9

Complete
Marked out of 3.00

Question text

Match the numbers to the following questions

In the JMP instruction, how many bits are there for determining the target address?

How many bits does an RCALL instruction take

A 15 bit program counter can execute a maximum of _________K memory locations?

How many different values can be loaded into an 8-bit register?

The largest value that can be loaded into a 8 bit register is 0x_________

To set the lower nibble register to 1, we must OR the contents of the register with 0x____

Question 10

Complete
Marked out of 1.00

Question text

Q1.         Multiply two decimal values: 231 and 178 using MUL instruction in AVR. What is the value in r1 (in decimal) after multiplication?

Question 11

Complete
Marked out of 1.00

Question text

How many times is this loop going to get executed?

LDI R20, 10
LDI R21, 44
now: DEC R21
BRNE now
OUT PORTB, R20

Question 12

Complete
Marked out of 1.00

Question text

Which of the following is correct about BRNE instruction in avr microcontrollers?

Select one:

Question 13

Complete
Marked out of 1.00

Question text

In the above figure ton= 5 ms and toff = 6 ms. Calculate the duty cycle in percentage (to 2 decimal places).

Question 14

Complete
Marked out of 1.00

Question text

For an ATMega 2560 microcontroller which runs at a frequency of 8 MHz. If r17:r16 register pair stores the loop count, what is the number stored in r17:r16 for 6 ms timing delay?

-------------

loop:

    subi r16, 1

    sbci r17, 0

    nop

    nop

    nop

    nop

    brne loop ; branch takes two cycles.

Question 15

Complete
Marked out of 1.00

Question text

What is the relation between the target and the relative address?

Select one:

Question 16

Complete
Marked out of 1.00

Question text

  1. What 8-bit binary value does the instruction “ldi r16, (10 << 4) + (4 << 1)” load into r16?

i)               (200)10

ii)             (AF)16

iii)           (10101000)2

Select one:

Question 17

Complete
Marked out of 5.00

Question text

Following is an assembly program written for ATmega 2560 microcontroller.


.def n0=r16
.def n1=r17
.def n2=r18
.def n3=r19
.def count0=r20
.def count1=r21
.def count2=r22
.def count3=r23
.def pattern=r24
.def zero=r25
.def one=r26

clr count0
clr count1
clr count2
clr count3
clr zero
ldi one,1

ldi n0, 0x45
ldi n1, 0x43
ldi n2, 0xFF
ldi n3, 0xFF

ldi pattern,0x33

loop:
lsl pattern
brcc increment_count
inc pattern

increment_count:
add count0,one
adc count1,zero
adc count2,zero
adc count3,zero
cp count0,n0
cpc count1,n1
cpc count2,n2
cpc count3,n3
brne loop

What is the value of the pattern (r24) in hexadecimal at the end of the program? (Enter the answer in form 0x00)

Question 18

Complete
Marked out of 30.00

Question text

A student wrote an assembly program for ATmega2560 microcontroller to detect push button presses and displays the count using LEDS. The microcontroller clock is running at 16 MHz. The specification of the program was as follows:

 

  • The push button is connected to PD0 (INT0) of PORTD.
  • Each push button press increments an 8-bit counter that resides in data memory.
  • The counter is displayed in binary using 8 LEDs connected to PORTC.
  • Button pressed are detected using falling edge external interrupts on INT0.
  • Software debouncing has been implemented using a flag stored in data memory and a delay implemented using the 16-bit timer 1.
    • The flag is initially cleared.
    • When the flag is cleared, a button press turns the flag on and turns on timer 1.
    • Any interrupts will be ignored when the flag is turned on.
    • When the timer overflows, the flag is reset.
    • The delay for debouncing should be ~262 milliseconds.

 

The program assembles successfully, but it has 11 logical bugs which affects the intended functionality. Identify at least 10 bugs and explain how those bugs can be fixed in the table provided. Note that there are no bugs where instruction in/out has been interchanged with lds/sts.

 

1)   

.include "m2560def.inc"

2)   

 

3)   

.dseg

4)   

.org 0x200

5)   

 

6)   

count_m : .byte 1

7)   

flag_m : .byte 1

8)   

 

9)   

.cseg

10) 

 

11) 

.org 0x0000

12) 

rjmp RESET

13) 

.org INT0addr

14) 

rjmp EXT_INT0

15) 

.org OVF1addr

16) 

rjmp Timer1OVF

17) 

 

18) 

.org 0x0072

19) 

 

20) 

; interrupt subroutine to External interrupt request 0

21) 

EXT_INT0:

22) 

       ; prologue

23) 

       push r16

24) 

       in r16, SREG ;

25) 

       push r16

26) 

       push r17

27) 

 

28) 

       ;if dobouncing flag is set just return, else turn on debouncing flag

29) 

       lds r16, flag_m                                                   

30) 

       cpi r16, 1

31) 

       reti                                                                                                      

32) 

       inc r16

33) 

       sts flag_m, r16

34) 

 

35) 

       ;enable timer and update the count

36) 

       ldi r17, 0b00000001                                                      

37) 

       sts TCCR1B, r17

38) 

       lds r17, count_m

39) 

       inc r17

40) 

       sts count_m, r17

41) 

       out DDRC,r17

42) 

 

43) 

return:

44) 

       ;epilogue

45) 

       pop r16

46) 

       pop r17                                                                                      

47) 

       out SREG, r16

48) 

       pop r16            

49) 

       reti

50) 

 

51) 

; interrupt subroutine to Timer1

52) 

Timer1OVF:

53) 

       push r16

54) 

       in r16, SREG

55) 

       push r16

56) 

      

57) 

       ; reset debouncing flag and disable timer

58) 

       clr r16

59) 

       sts flag_m<<1, r16

60) 

       sts TCCR1B, r16

61) 

 

62) 

       pop r16

63) 

       out SREG, r16

64) 

       pop r16

65) 

       ret                                                        

66) 

 

67) 

; main program

68) 

RESET:

69) 

 

70) 

       ldi r16, low(RAMEND)      

71) 

       out SPH, r16                                                                          

72) 

       ldi r16, high(RAMEND)

73) 

       out SPL, r16                                                                   

74) 

       ;set port directions and init variables

75) 

       cbi DDRD, 0

76) 

       sbi PORTD, 0

77) 

       ser r16      

78) 

       in r16, DDRC                                                                   

79) 

       clr r16

80) 

       sts count_m, r16

81) 

       out PORTC, r16     

82) 

       sts flag_m, r16

83) 

 

84) 

       ; configure timer in normal mode

85) 

       sts TCCR1A, r16

86) 

       sts TCCR1B, r16

87) 

       sts TCNT1H, r16    

88) 

       sts TCNT1L, r16

89) 

       ldi r16, 1<<TOIE1

90) 

       sts TIMSK1, r16

91) 

 

92) 

 

93) 

       ;set INT0 as falling edge

94) 

       ldi r16, (1 << ISC01)

95) 

       sts EICRA, r16

96) 

       in r16, EIMSK

97) 

       ori r16, (0<<INT0)

98) 

       out EIMSK, r16

99) 

 

100)         

       cli                                                                                                

101)         

       rjmp halt

102)         

 

103)         

halt:

104)         

    rjmp halt

 

line number Bug explanation / fix
 71 LOW(RAMEND) being stored in SPH.
Effect: Bad memory accesses
Fix: Store in SPL
 73 HIGH(RAMEND) being stored in SPL.
Effect: Bad memory accesses
Fix: Store in SPH
 76

Setting PORTD bit when it has been defined as an input bit
Effect: Undesirable consequences
Fix: Remove line

 97

INT0 is being disabled instead of enabled
Effect: Button interrupt won't be detected
Fix: ori r16, (1<<INT0)

 100

Global Interrupt Enable flag disabled.
Effect: Push button press won't be detected
Fix: Enable global interrupts with sei

 41

DDRC used instead of PORTC
Effect: Count won't be shown
Fix: out PORTC, r17

 45 Conflict registers are being popped in the wrong order
Fix: pop r17; pop r16
 59

Address reference for flag_m does not need to be left shifted
Fix: sts flag_m, 16

31

Return from Interrupt is always performed
Fix: Branch statement to go to the return label

 56 There is no implementation of a 262ms delay
Fix: Implement