Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Exercise from June 20th, 2012 exam session
- ;Please note that only two of the four peripheral drivers are included in this solution.
- org 400h
- motore equ 0h ;Moves elevator up and down
- piano equ 1h ;Elevator status flag: 0 = at kitchen, 1 = at dining room, 2 = moving in between
- chiama0 equ 2h ;Calls elevator to kitchen via interrupt
- sensore0 equ 3h ;Checks if elevator has reached kitchen via interrupt
- chiama1 equ 4h ;Calls elevator to dining room via interrupt
- sensore1 equ 5h ;Checks if elevator has reached dining room via interrupt
- array equ 0AAAh ;Stores 2B of data contaning floor flags
- stato equ 0BBBh ;Stores information concerning the elevator status
- code
- jsr init
- seti
- main: jmp main ;Loops until interrupt
- halt
- init: push R0
- push R1
- movb #0, R0
- movb #array, R1
- movb R0, (R1)+ ;Initializes the array flags to zero
- movb R0, (R1)
- start chiama0 ;Starts all peripherals
- start sensore0
- start chiama1
- start sensore1
- pop R1
- pop R0
- ret
- driver 2, 700h ;Driver for "chiama0"
- push R0
- push R1
- movl #piano, R0
- cmpl #0, R0 ;Checks current elevator position
- jz exitchiama ;If elevator is already at kitchen floor, exits subroutine
- cmpl #1, R0
- jz muovi ;If elevator is at dining room floor, moves it
- movl #array, R1
- movb #1, R1 ;If elevator is already moving in between floors, sets kitchen array flag to 1
- jmp exitchiama ;Then exits
- muovi: movl #stato, R1
- movl #2, (R1) ;Sets elevator status to "moving"
- movl #0, R1
- outl R1, motore ;Motor is set to bring elevator down from dining room floor to kitchen floor
- exitchiama: pop R1
- pop R0
- rti
- driver 3, 900h ;Driver for "sensore0"
- push R0
- push R1
- movl #2, R0
- outl R0, motore ;Elevator is stopped (flag #2 = elevator not moving)
- movl #array, R0
- movl #0, (R0)+ ;Sets kitchen floor flag to zero
- movl (R0), R1 ;Checks dining room floor flag
- cmpl #0, R1
- jz setflag ;If flag equals zero, modifies it
- movl #stato, R0
- movl #2, R0 ;Sets elevator status to "moving"
- movl #0, R0
- outl R0, motore ;Motor is set to bring elevator down from dining room floor to kitchen floor
- jmp exitsens
- setflag: movl #stato, R0
- movl #0, (R0) ;Kitchen floor flag is reset to 0
- exitsens: pop R1
- pop R0
- rti
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement