This document is an assignment focused on AVR Advanced Assembly Language Programming, containing a series of questions and programming tasks related to AVR architecture, EEPROM memory, macro programming, and various assembly instructions. It includes true/false questions, programming challenges, and inquiries about registers and addressing modes. The assignment aims to assess the understanding of AVR programming concepts and practical applications.
This document is an assignment focused on AVR Advanced Assembly Language Programming, containing a series of questions and programming tasks related to AVR architecture, EEPROM memory, macro programming, and various assembly instructions. It includes true/false questions, programming challenges, and inquiries about registers and addressing modes. The assignment aims to assess the understanding of AVR programming concepts and practical applications.
1. Which register is the low byte of the X register? 2. True or false. The AVR EEPROM memory is used for both program code and data. 3. True or false. The ATmega32 has 1,024 bytes of EEPROM memory. 4. True or false. In the AVR, EEPROM contents are lost when power to the chip is cut off. 5. True or false. In the AVR, EEPROM memory is read and write memory. 6. True or false. Every AVR chip comes with 1 KB of EEPROM. 7. Discuss the benefits of macro programming. 8. List the three parts of a macro. 9. Explain and contrast the macro definition and invoking the macro. 10. Write a program to find y where y = x2 + 2x + 5, and x is between 0 and 9. 11. Write a program to find y where y = 20x + 5, and x is between 0 and 9. 12. Write a program to read the following message from ROM and place it in data RAM starting at 40: .ORG 0x700 MYDATA: .DB "The earth is but one country",0 13. True or false. In all AVR members we can access the Flash ROM memory. 14. True or false. The ELPM instruction works for all AVR members. 15. Assume that the lower four bits of PORTB are connected to four switches. Write a program to send the following ASCII characters to a PORTC, based on the status of the switches: 0000 ‘0’ 0001 ‘1’ 0010 ‘2’ 0011 ‘3’ 0100 ‘4’ 0101 ‘5’ 0110 ‘6’ 0111 ‘7’ 1000 ‘8’ 1001 ‘9’ 1010 ‘A’ 1011 ‘B’ 1100 ‘C’ 1101 ‘D’ 1110 ‘E’ 1111 ‘F’ 16. Write a program to generate a square wave with 75% duty cycle on bit PB5. 17. Write a program to generate a square wave with 80% duty cycle on bit PC7. 18. Write a program to monitor PB4. When it goes HIGH, the program will generate a sound (square wave of 50% duty cycle) on pin PB7. 19. Write a program to monitor PC1. When it goes LOW, the program will send the value $55 to PD. 20. The pointer registers are _____-bit registers. 21. Write a program that adds 2 to the contents of locations $90–$9A and stores the results in locations $200–$20A. 22. Which registers may be used for register indirect addressing mode if the data is in the data memory? 23. The Instruction “LD R19,0x95” uses _________ addressing mode. 24. The instruction “LPM” uses register _____ as the address pointer. 25. What register holds data once it is read by the LPM Rd,Z instruction? 26. What is the size of Z? How much ROM space does it cover? 27. What register is incremented upon execution of the LPM Rd,Z+ instruction? 28. What is the difference between the LPM and ELPM instructions? 29. Write a program that calculates the sum of the values of locations $10 to $20 of EEPROM. 30. Find the checksum byte for the following ASCII message: “Hello” 31. Identify the addressing mode for each of the following: (a) OUT PORTB,R20 (b) LDI R20, 0x50 (c) LDS 0x40,R20 (d) ADD R20,R25 (e) MOV R20,R25 32. Indicate the addresses assigned to each of the following: (a) PORTB (b) PORTC (c) DDRC (d) DDRD (e) SPL (f) SPH (g) SREG 33. In accessing the I/O registers, we should use ______ addressing mode. 34. What does the following instruction do? “STS 0xF0,R20” 35. What does the following instruction do? “OUT PORTC,R19” 36. The byte addresses assigned to the internal SRAM are _____ to _____ in ATmega32. (Hint: To calculate the address of the last location, add the size of SRAM in ATmega32 to the address of the first location of SRAM and decrease the result by one.) 37. The byte addresses assigned to the SRAM are _____ to _____ in ATmega16. 38. Write a program to add the following data and place the result in RAM location $200: The data values are 6, 9, 2, 5, 7 39. Which registers are allowed to be used as a pointer for register indirect addressing mode when accessing data RAM? Give their names and show how they are loaded. 40. Write a program to copy $AA into RAM locations $80 to $9F. 41. In each of the following cases perform checksum calculation to see if data is corrupted or not. (a) Data = $65, $09, and $95; checksum = $23. (b) Data = $71, $69, $38, and $81; checksum = $6D. 42. True or false. If we add all bytes, including the checksum byte, and the result is $00, there is no error in the data. 43. Write a program to (a) get the data “Hello, my fellow world citizens” from program ROM, (b) calculate the checksum byte, and (c) test the checksum byte for any data error. 44. To display data on LCD or PC monitors, it must be in ________ (binary, BCD, ASCII). 45. Write a program to convert a series of packed BCD numbers to ASCII. Assume that the packed BCD is located in ROM locations starting at $700. Place the ASCII codes in RAM locations starting at $40. .ORG $700 MYDATA: .DB $76, $87, $98, $43 46. Write a program to convert a series of ASCII numbers to packed BCD. Assumethat the ASCII data is located in ROM locations starting at $300. Place the BCD data in RAM locations starting at $60. .ORG $300 MYDATA: .DB "87675649" 47. Write a program to get an 8-bit binary number from PORTD, convert it to ASCII, and save the result in RAM locations $40, $41, and $42. What is the result if PORTD has 1000 1101 binary as input? 48. Give two advantages of macros. 49. Which uses more program Flash ROM space: a macro or a subroutine? 50. When should we make our look-up table in RAM? 51. True or false. We can write into program memory using the SPM instruction. 52. True or false. All registers of the AVR are bit-addressable. 53. True or false. The status register of the AVR is bit-addressable. 54. Indicate which of the following registers are bit-addressable. (a) Port A (b) Port B (c) R19 (d) status register (e) PC register 55. How would you check to see whether bit D1 of R23 is HIGH or LOW? 56. Show how to clear the carry flag. 57. State what each instruction does. (a) SBR R16,0x1 (b) CBR R30,0x7 (c) BST R19,2 (d) SBI PORTB,4 (e) CBI SREG,1 (f) CLI 58. Indicate the value loaded into the registers in the following program: .EQU C1 = 0x20 .EQU C2 = 0x6F .EQU C3 = 0x14 LDI R20,(C1&C2)|C3 LDI R21,C2-(C1+C3) 59. Indicate the value loaded into R30, R31, and R20 in the following program: .ORG 0x0 .EQU DATA_ADDR = (OUR_DATA<<1) LDI R30,LOW(DATA_ADDR) LDI R31,HIGH(DATA_ADDR) LPM R20,Z .ORG 0x100 OUR_DATA: .DB 20,’A’,’C’ 60. Which of the following are invalid uses of immediate addressing mode? (a) LDI R20,0x24 (b) STS 0x70, 0x30 (c) OUT 0x20,0x42 61. Indicate the value loaded into the registers in the following program: .EQU CONST1 = 0x10 .EQU CONST2 = 0x91 .EQU CONST3 = 0x14 .EQU ADDR = (0x91 << 1)+1 LDI R20,CONST1&CONST2 LDI R21,CONST2|CONST3 LDI R30,LOW(ADDR) LDI R31,HIGH(ADDR) 62. What does the following code do? LDI R16,(1<<SREG_V)|(1<<SREG_Z) OUT SREG,R16 ;SREG = 0b00011000 63. Using the assembler directives write a program that sets the Z and C flags and clears the other flags. 64. True or false. I/O registers are not bit-addressable. 65. Write instructions to save the C flag bit in bit 4 of location 0x60. 66. Write instructions to save the H flag bit in bit 2 of location 0x160. 67. Write instructions to save the Z flag bit in bit 7 of location 0x120. 68. Write instructions to see whether the D0 and D1 bits of register R20 are LOW. If so, divide register R20 by 4. 69. Write a program to see whether the D7 bit of register R25 is HIGH. If so, send 70. Write a program to set HIGH all the bits of the PORTC I/O register using the following methods: (a) byte addresses (b) bit addresses 71. Write a program to see whether the R24 register is divisible by 8. 72. Write a program that writes 0 in EEPROM locations $0 to $30. 73. Write a program to copy 10 bytes of data starting at RAM address $80 to EEPROM locations starting at $10. 74. Write a program to copy 10 bytes of data starting at EEPROM address $10 to RAM locations starting at $80. 75. Calculate the values that are loaded into the TCNT1L and TCNT1H I/O registers. LDI R16,HIGH(15900) OUT TCNT1H,R16 ;TCNT1H = HIGH(15900) LDI R16,LOW(15900) OUT TCNT1L,R16 ;TCNT1L = LOW(15900)re the result in R20. 76. Can the programmer of a microcontroller make up new addressing modes? 77. Show the instructions to load 1000 0000 (binary) into register SPL. 78. True or false. In immediate addressing the value comes immediately after the opcode. 79. True or false. We can access the extended I/O registers using the I/O direct addressing mode. 80. True or false. SPL is an I/O register. 81. True or false. Using the names of the registers makes the code more portable. 82. Write a program to clear RAM locations $90 to $12F. 83. Write a program to copy 10 bytes of data starting at RAM address $80 to RAM locations starting at $90. 84. Write a program to toggle RAM locations $80 to $8F. 85. Compile and state the contents of each ROM location for the following data: .ORG 0x200 MYDAT_1: .DB "Earth" MYDAT_2: .DB "987-65" MYDAT_3: .DB "GABEH 98" 86. Compile and state the contents of each ROM location for the following data: .ORG 0x340 DAT_1: .DB 0x22,0x56, 0b10011001, 32, 0xF6, 0b11111011 87. Which register is allowed to be used as a pointer for register indirect addressing mode when accessing data stored in program ROM? Give the name and show how it is loaded. 88. What is the size of the Z register? How much ROM space does the LPM instruction cover? 89. Write a program to read data from the low byte of Flash ROM location 0x200. 90. Write a program to read data from the high byte of Flash ROM location 0x340. 91. Write a program to read the following message from ROM and place it in data RAM starting at 0x60: .ORG 0x600 MYDATA: .DB "1-800-999-9999",0 92. What register does the carry flag belong to? 93. What bit address is assigned to the Z flag? 94. Which of the following instructions are valid? If valid, indicate which bit is altered. (a) SBI PORTB,1 (b) CBI PORTC.3 (c) SBR SREG,1 (d) SBR R20,1 (e) BLD PORTD,0 (f) BST R20,3 (g) CLV R3 (h) CLN 95. “SBI PORTB, 0” is a(n) _______ (valid, invalid) instruction. 96. Which of the I/O ports of PORTB, PORTC, and PORTD are bit-addressable? 97. Which of the general purpose registers are bit-addressable? 98. Give an instruction to clear the carry flag. 99. Show how would you check whether the C flag is HIGH. 100. Show how would you check whether the Z flag is HIGH. 101. Give the bit locations in the status register assigned to the flag bits C, Z, H, and V.