Digital Stopwatch (in ARMLite)
For this assignment, you are going to implement the functionality for a simple stopwatch interface our assignment must be built using this file as the interface. You will implement the Digital Stopwatch in the ARMlite ARM Assembler. Your aim is to replicate the functionality of the stopwatch as closely as you can, in the ARMlite simulator. See further details below.
- Stopwatch Beginnings: a program which displays Seconds incrementing in the text output display area in a sensible and perceivable way (i.e, so we can see each tick!) from when the program launches and allows the timer to be paused and un-paused. (20/60)
- Stopwatch Basics: a program which achieves all the above, and shows time ticking in real-time, and also offers the ability to start/pause and reset the timer. (30/60)
- Stopwatch with Benefits: Most stop watches provide a “Split” button that allows intermediate times (i.e., lap times) to be recorded and displayed. After you build a program which achieves all the tasks above, but also allows a split time to be displayed when requested (e.g., when “s” is entered), while also continuing to show the timer. (40/60)
- Stopwatch with Buffering: a program which achieves all the above, and also keeps track of the last 5 “Split” times during a single timed activity. The solution should show only one split time at a time, and thus allow the user to view each split time in turn. (50/60)
- Stopwatch of Beauty: a program that implements a stopwatch proper! – that is, all of the above, but displays all the digits on the ARMlite display screen (rather than the text output field). (60/60)
This criterion will consider the layout and readability of your code, but also the quality of the solution. That is, the extent to which your solution exhibits sound uses of relevant data structures such as variables and arrays, the stack, as well as the functional decomposition (i.e., use of functions) to implement the solution, and your solution’s adherence to ABI conventions.
The Correct Answer and Explanation is :
To implement a Digital Stopwatch in ARMlite ARM Assembler, you will follow these steps incrementally, starting with the basics and adding more functionality with each phase. The final solution will be a fully featured stopwatch, displaying times and handling multiple states.
Phase Breakdown and Solution:
1. Stopwatch Beginnings (Seconds Increment)
In this phase, the timer starts from 0 and increments by 1 every second. This can be achieved by implementing a loop that waits for a timer interrupt to simulate the passage of time. ARM Assembler doesn’t have built-in sleep functions, so you’ll need to simulate this by implementing a delay loop that waits for a specific number of cycles. The seconds count can be stored in a register, and when it increments, it’s displayed in the text output area.
MOV R0, #0 // Initialize the second counter
increment:
BL delay // Call delay function (waiting 1 second)
ADD R0, R0, #1 // Increment seconds
MOV R1, R0 // Copy seconds value to R1
BL display_seconds // Call display function
B increment // Repeat the process
2. Stopwatch Basics (Start/Pause and Reset)
You need to implement the start, pause, and reset functionality. This can be done using a flag variable to control the state of the timer (running or paused). When the pause button is pressed, the program stops incrementing the seconds, and when resumed, it continues from the last second.
MOV R2, #0 // Flag for paused state (0 = running, 1 = paused)
check_pause:
CMP R2, #0 // Check if paused
BEQ increment // If not paused, continue incrementing
B check_pause // If paused, wait
3. Stopwatch with Benefits (Split Time)
Add functionality to record and display lap times (split times). When the ‘s’ key is pressed, the current time is recorded, stored, and displayed while the timer continues.
MOV R3, R0 // Store the current second count as a split time
BL display_split_time // Display split time
4. Stopwatch with Buffering (Track Last 5 Split Times)
For this, you need an array to store the last 5 split times. This can be done by using memory space or a stack to store these times. After each new split, the oldest time is overwritten.
// Assume R4 is the split index counter
STR R3, [split_times, R4] // Store the split time
ADD R4, R4, #1 // Increment the split index
CMP R4, #5
BLT continue_splits
MOV R4, #0 // Reset index if we reach 5
5. Stopwatch of Beauty (Display on ARMlite Screen)
For this phase, the times will be displayed on the ARMlite screen, requiring you to write a function to convert the seconds count into a format suitable for display.
MOV R1, R0 // Move seconds to R1 for display
BL convert_to_display_format
BL display_on_screen // Function to display on the screen
Explanation:
The program leverages ARM Assembler’s basic instruction set for controlling flow, manipulating data, and calling functions to handle different tasks. The core functionality revolves around a timer that increments every second. To implement features such as pause/resume, split times, and storing the last 5 split times, ARM Assembler allows efficient use of registers and memory manipulation. For example, flags are used to control states (running/paused), and memory or registers are used to store and display split times. The final step involves formatting the output for display on the ARMlite screen, adding an element of visual interaction to the stopwatch, making it a complete solution.
By breaking down the problem into phases and incrementally adding complexity, you ensure that each feature is implemented and tested before adding the next, leading to a structured and maintainable solution.