Advertisement
Guest User

Untitled

a guest
May 26th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. ;; 203 Lab#7 - Spring 2014
  2.  
  3. .ORIG X3000
  4. ;; initially, stop any note playing by setting FGCR to zero
  5. AND R0 ,R0,#0
  6.  
  7. LD R3, ASCII_KEYS
  8. NOT R3, R3
  9. ADD R3, R3, #1
  10.  
  11. STI R0, FGCR_ADDR ; mem[x440a] = R0 = 0
  12. ; set FGCR = 0 to stop playing note
  13. BR WAIT_FOR_KEY
  14. ;;
  15. ;; Starting the main loop WAIT_FOR_KEY
  16. ;; Test KPDR until it is non-zero,
  17. ;;indicating key pressed
  18.  
  19. WAIT_FOR_KEY
  20. LDI R0,KPDR_ADDR ; R0 = ascii(typed_key),
  21. ; typed_key ranged from 1 to 9
  22. ; ascii code will be from x31 to x39
  23.  
  24. BRz WAIT_FOR_KEY ; If zero, no key yet. Loop back
  25. ;;
  26. ;; Got a key! RO = TYPED KEY.
  27. ;; Convert the typed ASCII_# into an index (0-8)
  28. ;; which means that convert "1" to 0, "2" to 1, and etc.
  29. ;;
  30. ;; Write your convertion code here!!!!!!!!!!!!!!!
  31. ;; You will put the converted index number in R0!
  32. ;; R0 should be in the range of 0-8,
  33. ;;
  34.  
  35. ADD R0, R0, R3
  36.  
  37. ;; However, let's doubtcheck it for safety.
  38. ;; WRITE you codes here to check if R0 is out of range
  39. ;; If the number is out of range,
  40. ;; branch back to WAIT_FOR_KEY
  41. ;;
  42.  
  43. BRn WAIT_FOR_KEY
  44.  
  45. ADD R2, R0, #-8
  46.  
  47. BRp WAIT_FOR_KEY
  48.  
  49.  
  50. ;; now R0 in within 0 and 8, which means that
  51. ;; the key_in number is within '1' and '9'.
  52. ;;
  53. ;; Write the next piece of codes to
  54. ;; play the note by looking up the frequency.
  55. ;; Use LEA to load the starting address of note_freq_array
  56. ;; into a register.
  57.  
  58.  
  59. LEA R1, NOTE_FREQ_ARR
  60. ADD R1, R1, R0
  61. LDR R1, R1, #0
  62. STI R1, FGDR_ADDR
  63. STI R1, FGCR_ADDR
  64.  
  65.  
  66.  
  67.  
  68.  
  69. ;; Write this frequency to the frequency generator FGDR
  70. ;; To play this musical note, you need to write any
  71. ;; non-zero number to FGCR
  72. ;; Now the note will be played through the speaker!!
  73.  
  74.  
  75.  
  76. ;;
  77. ;;
  78.  
  79. WAIT_FOR_RELEASE
  80. LDI R0, KPDR_ADDR
  81. BRz KEY_RELEASED
  82. BRnp WAIT_FOR_RELEASE
  83.  
  84.  
  85. KEY_RELEASED
  86. AND R1, R1, #0
  87. STI R1, FGCR_ADDR
  88. STI R1, FGDR_ADDR
  89. BR WAIT_FOR_KEY ; repeat
  90. ;;
  91. HALT
  92.  
  93. ;; LABEL DEFINITIONS
  94. ;; 9 numeric keys
  95. ASCII_KEYS
  96. .STRINGZ "123456789"
  97. ;; KPDR holds the most recent key to be pressed.
  98. KPDR_ADDR
  99. .FILL x4400
  100. ;;KPSR tracks the number of milliseconds since the last key was pressed.
  101. KPSR_ADDR
  102. .FILL x4402
  103. ;; FGDR specifes the frequency for the output tone.
  104. FGDR_ADDR
  105. .FILL x4408
  106. ;; FGCR controls the behavior of the function generator.
  107. FGCR_ADDR ; If FGCR = 0, stop playing musical notes.
  108. .FILL x440a ; non-zero FGCR will generate musical notes.
  109. ;;
  110. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  111. ;; 9 frequencies for 9 key_in numbers
  112. NOTE_FREQ_ARR
  113. .FILL 440 ;; x01B8
  114. .FILL 466 ;; x01D2
  115. .FILL 493 ;; x01ED
  116. .FILL 523 ;; x020B
  117. .FILL 554 ;; x022A
  118. .FILL 587 ;; x024B
  119. .FILL 622 ;; x026E
  120. .FILL 698 ;; x02BA
  121. .FILL 783 ;; x030F
  122. ;;
  123. ;; RESERVE some memory for recording application
  124. NOTE_ARRAY
  125. .BLKW 32
  126. .END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement