Exam1

docx

School

Western Washington University *

*We aren’t endorsed by this school

Course

234

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

docx

Pages

4

Uploaded by zerogaming0723

Report
EE234 Exam 1 Spring 2024 Name : Score: Part 1 : (3 points each) (C )1. Which of the following statements regarding the N flag of the status register SREG is true? (a) N is set when operation has a carry out (b) N is set when the operation result is 0 (c) N is set when the operation result is negative (d) N is set when the operation causes overflow (D )2. Which of the following is true regarding the H flag of the status register SREG? (a) H is set when there is a borrow during a subtraction (b) H is set when the operation is negative (c) H is set when the operation result is zero (d) H is set when there is a carry from bit 3 to bit 4 (A )3. Which of the following instructions is wrong? (a) ldi r0,0x30 (b) lds r1, 0x1000 (c) ldd r10,Y+20 (d) st -Z, r16 (B )4. Which register is used to specify the target address for the indirect jump instruction (IJMP)? (a) X pointer (b) Z pointer (c) Y pointer (d) EIND register (D )5.If you want to copy the contents of register r0 to r17, which of the following instruction should be used? (a) ldi r17,r0 (b) ldd r17, r0 (c) ld r0, r17 (d) mov r17, r0 (A )6. Assume that the contents of Z is 0x1000, then which of the following data memory location receives the value of r0 after the execution of the instruction “std Z+10, r0”? (a) location at 0x100A (b) location at 0x1009 (c) location at 0x1000 (d) location at 0x1020 (B )7.If [r3] = 0xD5, and C flag is 0, which of the following is correct after the execution of the instruction “asr r3”? (a) [r3] = EA, C = 0 (b) [r3] = 0xEA, C = 1 (c) [r3] = 0xAA, C = 0 (d) [r3] = 0xBB, C =1 (C )8. Which of the following instructions can be used to access the contents of a location in program memory? (a) ldd (b) ld (c) lpm (d) std (A )9. When does a for-loop evaluate the loop termination condition? (a) at the start of the loop (b) in the middle of the loop (c) at the end of the loop (d) can do it any place (C )10. Assume that [r0] = 0xAA, and [r1] = 0x55, what will be the new value of r0 after the execution of the instruction “eor r0, r1”? (a) 0x44 (b) 0x00 (c) 0xFF (d) 0x88 (A )11. After the execution of “ldi ZL,low(0x2010<<1)” and “ldi ZH,high(0x2010<<1)”, what is the value in the Z pointer? (a) 0x4020 (b) 0x8040 (c) 0x2010 (d) 0x1008 1
(A )12. After the execution of the instruction movw r16, r26, which of the following operation is performed? (a) r16 [r26], r17 [r27] (b) r26 [r16], r27 [r17] (c) r16 [r27], r17 [r26] (d) r26 [r17], r27 [r16] (D )13. Let [r16] = 0x6B, and C = 1, what is the new value for r16 and C after execution of ror r16? (a) [r16] = 0x6B, C = 0 (b) [r16] = 0x5B (c) [r16] = 0xB5, C = 0 (d) [r16] = 0xB5, C = 1 (B )14. The value in r16 register is divisible by 8, then what would be the value in r16 after the execution of andi r16, 0x07? (a) 0xFF (b) 0 (c) 0x55 (d) 0xA0 0000 0111 (A )15. For the instruction rcall k, which of the following is correct? (a) k is the distance of the subroutine (from this instruction) to be called (b) k is the address of the subroutine to be called (c) k is a register that holds the address of the subroutine to be called (d) the address of the subroutine to be called is in Z pointer Part II (10 points each) 1. Write an instruction sequence to copy the contents of program memory at 0x1050 to data memory location 0x2060 and copy the contents of program memory location at 0x1051 to data memory locations 0x2070. Solution: ldi ZL, low(0x1050) ldi ZH, high(0x1050) lpm r16, Z+ lpm r17, Z sts 0x2060, r16 sts 0x2070, r17 2. Write an instruction sequence to add 33 to the 16-bit value stored at data memory 0x2010~0x2011 and subtract 47 to the 16-bit value stored at 0x2040~0x2041. Solution : lds r24, 0x2010 lds r25, 0x2011 adiw r24, 33 sts 0x2010, r24 sts 0x2011, r25 lds r24, 0x2040 lds r25, 0x2041 sbiw r24, 47 sts 0x2040, r24 2
sts 0x2041, r25 3. Write an instruction sequence to store 9, 13, and 39 at data memory locations at 0x2010, 0x2015, and 0x2020, respectively. Solution: ldi r16, 9 sts 0x2010, r16 ldi r16, 13 sts 0x2015, r16 ldi r16, 39 sts 0x2020, r16 4. Write a subroutine to set bits 6, 4, and 2 of every element in an array in data memory. The array count and the pointer to the array are passed in r16 and Z pointer. Solution: setBits : ld r19, Z ori r19, 0x54 st Z+, r19 dec r16 brne setBits ret 5. Write an instruction sequence to pull the PORTA pin 7, 0 to low and pull the PORTA pin 6 and 1 to high, and toggle PORTA pin 4 and 2. Do not change the voltage of PORTA pin 5 and 3. Solution: ldi r16, 0x81 sts PORTA_OUTCLR, r16 ldi r16, 0x42 sts PORTA_OUTSET, r16 ldi r16, 0x14 sts PORTA_OUTTGL, r16 6. Write loop to turn on the LEDs driven by PC7 for 700ms, then turn on the LED driven by PC5 for 500 ms and then turn on the LED driven by PC3 for 300 ms, and repeat ( turn on one LED at a time ). The subroutine delayby100ms is available for you to call and the multiple is passed using register r16 . 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Solution: loop: ldi r17, 0x80 sts PORTC_OUT, r17 ldi r16, 7 call delayby100ms ldi r17, 0x20 sts PORTC_OUT, r17 ldi r16, 5 call delayby100ms ldi r17, 0x08 sts PORTC_OUT, r17 ldi r16, 3 call delayby100ms jmp loop 7. Convert the following instruction sequence into a subroutine: ldi r20, 15 lpm r1, Z+ add r1, r20 st X+, r1 Solution: add15: ldi r20, 15 lpm r1, Z+ add r1, r20 st X+, r1 ret 4