Task 1
The process of how the subroutine works within an operating environment is as follows. While the main part of the program is running, there will be a call command sent to the CPU to tell it to stop wherever the program is at, store the W, Z and status along with where in the main program the CPU is at in the stack. Then the main program is cleared from memory and the subroutine is loaded for the CPU to start processing the code. Once the subroutine has finished, the subroutine code is deleted from memory and the CPU will load up the main program back on and will retrieve from stack the stored information (W, Z and status) which will allow the CPU know exactly where it needs to start from.
What a program stack does is simply stores …show more content…
Here below is a screenshot of a program created in flow code that uses macros (meaning that you don’t need to repeat yourself) along with a simulation/real hardware to show that this code works.
Task 4
Using the code idea from task 3, this one uses an interrupt to further improve and optimise the code so it can as efficient as possible.
An interrupt is used when you want to quickly get the chips (CPU) attention at hardware level for a short amount of time when the value set has been meet (this is great as this removes barriers as stated on matrixtsl.com, you can with your program wake the controller when it’s in a low power state which you can’t do at software level). An interrupt works when you are running a program on an endless loop and meets a certain condition set in the program, this triggers the interrupt which will tell the CPU at hardware level (quicker than software level) to go to the sub program and once finished processing the sub-program, it will return back to the main program.