MOVEM.L A0-A5/D7,-(SP)
MOVEM.L (SP)+,A7/D0-D5
[12 marks]RD_STA_FIELDS: MOVE.L D2,-(SP) /* save temporary register */ /* Field 1 */ MOVE.L STAT_REG, D2 /* get original longword */ CLR.L D0 /* clear field 1 return register */ AND.L #0xE000001F, D2 /* mask unnecessary bits */ MOVE.B D2, D0 /* move bits 4-0 to return reg */ LSR.L #8, D2 /* shift to get bits 31-29 */ LSR.L #8, D2 /* note: LSR takes immediate values */ LSR.L #8, D2 /* from 1 - 8 only */ OR.L D2, D0 /* move bits 31-29 to return reg */ /* Field 2 */ MOVE.L STAT_REG, D2 /* get original longword */ CLR.L D1 /* clear field 2 return register */ AND.L #0x1FE00000, D2 /* mask unnecessary bits */ LSR.L #8, D2 /* shift to get bits 28-21 */ LSR.L #8, D2 LSR.L #5, D2 MOVE.B D2, D1 /* move bites 28-21 to return reg */ /* Field 3 */ MOVE.L STAT_REG, D2 /* get original longword */ CLR.L A2 /* clear field 3 return register */ AND.L #0x001FFFE0, D2 /* mask unnecessary bits */ LSR.L #5, D2 /* shift to get bits 20-5 right aligned */ BITREV.L D2 /* reverse bit order to desired order */ LSR.L #8, D2 /* shift to get bits 20-5 right aligned */ LSR.L #8, D2 MOVE.W D2, A2 /* move bites 20-5 to return reg */ MOVE.L (SP)+, D2 /* restore temporary register */ RTS /* return from subroutine */Notes: MOVE.B and MOVE.W takes low order bytes or words. When saving and restoring temporary registers, do not save/restore D0, D1 or A2 because these will be changed at the end. If you restore them, then you will overwrite your return values just before the RTS.
Pre-emptive multitasking allows tasks to run depending on task priority. Each task is assigned a priority number, and usually the same priority number cannot be assigned to more than one task (that is, the priorities are unique). The highest priority task at any time is always scheduled to run on the CPU. The only time that a lower priority task can execute is if all other higher priority tasks are blocked (say waiting for timers or semaphores). If some event causes a high priority task to become unblocked, then it will immediately be scheduled to run on the CPU instead of a lower priority task. An advantage of pre-emptive multitasking is that, by using high-priority tasks to handle more time-critical activities in the system, the system will be able to provide more predictable real-time response times to events. A potential disadvantage of pre-emtive multitasking is that low priority tasks may be starved of execution time on the CPU if too often there is a ready-to-run higher priority task.
Co-operative multitasking relys on the tasks to give up control of the CPU
voluntarily. When a task gets control over the CPU, the task gives up control
after it has completed running or needs to wait. The advantage of this method is it ensures a task
completes the desired execution (critical sections) on the CPU before giving up control. The drawback
is it relys on the individual tasks to share the CPU placing the responsibility
on the programmer to ensure that all tasks co-operate to meet the system objectives.
In order to handle hard real-time constraints, pre-emptive multitasking is likely to be
the most effective. This is because predictable response times are important.
By using pre-emptive multitasking, the tasks that must handle the hard real-time
contraints can be set to a high priority to ensure they are run promptly.