Advertisement
heavenriver

Esame2012giu20.asm

Jun 20th, 2012
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Exercise from June 20th, 2012 exam session
  2. ;Please note that only two of the four peripheral drivers are included in this solution.
  3.  
  4. org 400h
  5. motore equ 0h             ;Moves elevator up and down
  6. piano equ 1h              ;Elevator status flag: 0 = at kitchen, 1 = at dining room, 2 = moving in between
  7. chiama0 equ 2h            ;Calls elevator to kitchen via interrupt
  8. sensore0 equ 3h           ;Checks if elevator has reached kitchen via interrupt
  9. chiama1 equ 4h            ;Calls elevator to dining room via interrupt
  10. sensore1 equ 5h           ;Checks if elevator has reached dining room via interrupt
  11. array equ 0AAAh           ;Stores 2B of data contaning floor flags
  12. stato equ 0BBBh           ;Stores information concerning the elevator status
  13. code
  14. jsr init
  15. seti
  16. main: jmp main            ;Loops until interrupt
  17. halt
  18. init: push R0
  19. push R1
  20. movb #0, R0
  21. movb #array, R1
  22. movb R0, (R1)+            ;Initializes the array flags to zero
  23. movb R0, (R1)
  24. start chiama0             ;Starts all peripherals
  25. start sensore0
  26. start chiama1
  27. start sensore1
  28. pop R1
  29. pop R0
  30. ret
  31. driver 2, 700h            ;Driver for "chiama0"
  32. push R0
  33. push R1
  34. movl #piano, R0
  35. cmpl #0, R0               ;Checks current elevator position
  36. jz exitchiama             ;If elevator is already at kitchen floor, exits subroutine
  37. cmpl #1, R0
  38. jz muovi                  ;If elevator is at dining room floor, moves it
  39. movl #array, R1
  40. movb #1, R1               ;If elevator is already moving in between floors, sets kitchen array flag to 1
  41. jmp exitchiama            ;Then exits
  42. muovi: movl #stato, R1
  43. movl #2, (R1)             ;Sets elevator status to "moving"
  44. movl #0, R1
  45. outl R1, motore           ;Motor is set to bring elevator down from dining room floor to kitchen floor
  46. exitchiama: pop R1
  47. pop R0
  48. rti
  49. driver 3, 900h            ;Driver for "sensore0"
  50. push R0
  51. push R1
  52. movl #2, R0
  53. outl R0, motore           ;Elevator is stopped (flag #2 = elevator not moving)
  54. movl #array, R0
  55. movl #0, (R0)+            ;Sets kitchen floor flag to zero
  56. movl (R0), R1             ;Checks dining room floor flag
  57. cmpl #0, R1
  58. jz setflag                ;If flag equals zero, modifies it
  59. movl #stato, R0
  60. movl #2, R0               ;Sets elevator status to "moving"
  61. movl #0, R0
  62. outl R0, motore           ;Motor is set to bring elevator down from dining room floor to kitchen floor
  63. jmp exitsens
  64. setflag: movl #stato, R0
  65. movl #0, (R0)             ;Kitchen floor flag is reset to 0
  66. exitsens: pop R1
  67. pop R0
  68. rti
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement