Anda di halaman 1dari 24

7 Final Exam Questions and Solutions

1a. A system consists of a five-step processor, ROM, RAM, and two I/O
devices. A 16-bit address space is used. ROM and RAM are each 16kbytes in
size. ROM is at address 0. RAM immediately follows the end of ROM. Each
I/O device reserves 16kbytes in the address space (even if the full range is
not used). Design the address decoding for this system and fill in the table.

1b. Write the simplest Boolean logic expressions for the device-select
signals for all four devices that are described in part (a).

1-whatever. There will be a question about implementing this using either


FPGA or separate chips. The exam might ask to explain the hardware or
draw the logic diagram.
3b. Write a NIOS II assembly-language loop (a complete program is not
required) to transfer data words to the external device connected to the
given port. The words to be transferred begin at location LIST, and the
number of words to be transferred is available at location N (this is the
terminating condition, which changes). The port status flag is in bit 3.

1. movia r2,LIST
2. movia r4, N
3. movia r3,STATUS_REG
4. LOOP: ldw r5,0(r3) /*get status register data */

5. andi r5,r5,STATUS_FLAG /*mask off status bit */


6. movi r6, STATUS_FLAG

7. bne r5,r6, LOOP /*polling loop to wait for status flag */

8. ldw r7,0(r2) /*load word*/


9. addi r2,r2,4 /*increment word list pointer*/
10. subi r4,r4,1 /*decrement number of words*/

11. movia r8, DATA_REG


12. stwio r7, 0(r8) /*send word to port*/

13. bne r4,r0, loop /*go back to start if all words aren't sent */
4b. Logic Diagram: An I/O device X is assigned bit 3 within the appropriate
registers in part (a). The device asserts a signal IRQx when it seeks to
obtain interrupt service. Describe the full logic path, beginning with how the
device generates IRQx and ending with the final signal to the internal
processor control logic.
4c. Show assembly language instructions for initializing the appropriate
registers in part (a) to properly support use of interrupts for device X in part
(b).

1. movi r3,0x8
2. wrctl ienable,r3 /*enable interrupts for device x*/

3. movi r3,0x1
4. wrctl status,r3 /*enable interrupts in processor*/

4c. Show assembly language instructions for the exception/interrupt handler


to properly check for a device X hardware interrupt request, and to properly
return to the main program.
1. rdctl et,ipending
2. andi et,et,0x8

3. beq et,r0,end
4. call forX
5. forX: |
6. <code for device X interrupt>
7. |
8. end: eret

1. #include "nios2_control.h"
2. #define JTAG_UART_DATA (volatile unsigned int*) 0x00005800
3. #define JTAG_UART_STATUS (volatile unsigned int*) 0x00005804

4. #define TIMER_STATUS (volatile unsigned int*) 0x00005000


5. #define TIMER_CONTROL (volatile unsigned int*) 0x00005004
6. #define TIMER_START_LO (volatile unsigned int*) 0x00005008
7. #define TIMER_START_HI (volatile unsigned int*) 0x0000500C

8. #define INPORT (volatile unsigned int*) 0x00003000


9. #define OUTPORT (volatile unsigned int*) 0x00003400

10. #define ASCII_START_NUM 0x30


11. #define ASCII_START_LETTER 0x41
12. #define DATA_MASK 0xFFFF0000
13. #define NEWLINE 0x0D

14. unsigned volatile int one_second;


15. unsigned volatile int count;
16. void init()
17. {

18. *TIMER_START_LO=0x9680;
19. *TIMER_START_HI=0x0098;

20. *TIMER_STATUS=0;
21. *TIMER_CONTROL=7;

22. one_second=0;
23. count=0;
24. *OUTPORT=0x00;

25. NIOS2_WRITE_IENABLE(0x1);
26. NIOS2_WRITE_STATUS(0x1);
27. }

28. void interrupt_handler()


29. {

30. unsigned int ipending = NIOS2_READ_IPENDING();


31. if(ipending &0x1) {

32. *TIMER_STATUS=0;
33. count=count+1;
34. if(count>=5) {
35. one_second=1;
36. count=0;
37. }
38. }
39. }

40. void PrintChar(int ch)


41. {
42. while((*JTAG_UART_STATUS & DATA_MASK)==0);
43. *(JTAG_UART_DATA)=ch;
44. }

45. void main()


46. {

47. unsigned int input_character=*INPORT;


48. unsigned int display_character_LO;
49. unsigned int display_character_HI;
50. unsigned int second_count;
51. init();

52. while(1) {
53. if(one_second) {
54. one_second=0;
55. second_count=second_count+1;
56. if(second_count>=256) {
57. second_count=0;
58. }
59. *OUTPORT=second_count;
60. }

61. if (*INPORT != input_character)


62. {

63. input_character=*INPORT;
64. display_character_LO = (input_character & 0x0F);
65. display_character_HI = (input_character & 0xF0>>4);

66. if(display_character_LO <= 9)


display_character_LO=display_character_LO + ASCII_START_NUM;
67. else display_character_LO=display_character_LO + ASCII_START_LETTER;
68. if(display_character_HI <= 9) display_character_HI=display_character_HI
+ ASCII_START;
69. else display_character_HI=display_character_HI + ASCII_START_LETTER;

70. PrintChar(display_character_HI);
71. PrintChar(display_character_LO);
72. PrintChar(NEWLINE);
73. }
74. }
75. }

Anda mungkin juga menyukai