Question
The Clock (Mars Tool) consists of two parts, a display and a key pad. The display is connected directly to the register $t8. It simply
The Clock (Mars Tool) consists of two parts, a display and a key pad. The display is connected directly to the register $t8. It simply display in the form HH:MM:SS. To control this display, simply set the register $t8 to a desired value. The second part (SS) is associated with the lower 8-bit of the register $t8 (bit 7 to bit 0). The minute part (MM) is associated with bit 15 to bit 8. Lastly, the hour part (HH) is associated with bit 23 to bit 16. For example, if you set the value of the register $t8 to 0x0001020B, the display will show 01:02:11. There is a special value for resetting the Clock (Mars Tool). If you set the register $t8 to 0x01000000, it will reset the clock by enabling Clock, Stop Watch, and Timer buttons and disabling Hour, Minute, Second, Start, Stop, and Reset buttons.
There are 9 buttons on the key pad. These buttons are connected directly to the register $t9. If the value of the register $t9 is currently equal to 0 and a button is pressed, the value of the register $t9 will be change according to the pressed button as shown in Table 1. Note that these buttons has no effect if the content of the register $t9 is not equal to 0. Thus, it is your responsibility to change the content of the register $t9 to 0 when your program is ready to get a new key pad input. Note that the Clock (Mars Tool) does not use syscall. Thus, there is no special instruction for your program to wait for the keyboard input. Your program has to loop checking the value of the register $t9 until it is not zero. The non-zero value will be the input. Again, do not forget to set the register $t9 back to 0 when you are ready to receive the next key pad input.
Requirements The following are requirements that you must follow:
Your program should be named clock.asm
Since the Simple Calculator (Mars Tool) uses registers $t8 and $t9, do not use these registers for any other purposes.
You can only use registers $s0 to $s7 and $t0 to $t9 in your program.
No need to have functions in your program. In other words, do not use instructions jal and jr or stack pointer ($sp). You may already learn how to create a function in assembly language and feel tempted to do so.
No memory reference instructions are allowed (no load and store instructions).
Your program should have only the text segment (.text) and no data segment (.data).
You are allowed to use unsigned multiplication (multu) and division (divu) instructions.
Your program must follow the predefined behavior (see below) Your clock program must behave according to the following:
When the program starts, your program should be in the clock mode and it should display the current time in the form of HH:MM:SS (24 hours format).
In the clock mode while it is displaying the current time:
If a user click Clock, do nothing. Simply keep displaying the current time.
If a user click Stop Watch, it should change to your stop watch mode and display 00:00:00. 2
If a user click Timer, it should change to your timer mode and display 00:00:00.
In stop watch mode (while it is not running)
If a user click Clock, it should change to your clock mode and display the current time.
If a user click Stop Watch, it should display 00:00:00 (just like reset). If a user click Timer, it should change to your timer mode and display 00:00:00.
If a user click Start, it should start counting up. Note that if a user click Start, then Stop without reset, and click Start again, your program should start counting up from where it left off.
If a user click Stop, simply do nothing since it is not currently counting.
If a user click reset, reset the display to 00:00:00. In stop watch mode (while it is running)
If a user click Clock, it should change to your clock mode and display the current time.
If a user click Stop Watch, it should display 00:00:00 (just like reset).
If a user click Timer, it should change to your timer mode and display 00:00:00.
If a user click Start, simply do nothing since it is currently counting up.
If a user click Stop, simply stop counting up.
If a user click reset, reset the display to 00:00:00.
In timer mode (while it is not running)
If a user click Clock, it should change to your clock mode and display the current time.
If a user click Stop Watch, it should display 00:00:00. If a user click Timer, it should change to your timer mode and display 00:00:00 (just like reset)
. If a user click Hour, it should increase the hour by 1. If the hour is greater than 23, it should change it back to 0.
If a user click Minute, it should increase the minute by 1. If the minute is greater than 59, it should change it back to 0.
If a user click Second, it should increase the second by 1. If the second is greater than 59, it should change it back to 0.
If a user click Start, it should start counting down. Note that if a user click Start, then Stop without reset, and click Start again, your program should start counting down from where it left off.
If a user click Stop, simply do nothing since it is not currently counting.
If a user click reset, reset the display to 00:00:00.
In timer mode (while it is running) 3
If a user click Clock, it should change to your clock mode and display the current time.
Second, or Start, simply do nothing (keep counting down).
If a user click Stop, simply stop counting down.
If a user click reset, reset the display to 00:00:00.
Note that if it counts down to 0, it should simply stop.
Hints
Focus on a small task at a time (clock, stop watch, and timer)
The system time (system call number 30) returns the number of milliseconds since January 1, 1970. It is a 64-bit number. The system call 30 puts the high 32-bit in the register $a1 and the low 32-bit in the register $a0.
To get the total number of seconds since January 1, 1970, you need to divided the total number of millisecond by 1000. This requires 64-bit division. We will discuss this method in class To get the second value, simply mod the total number of second by 60
To get the minute value, first, calculate the total number of minutes since January 1, 1970 by divided the total number of seconds by 60. Then mod the total number of minutes by 60
. To get the hour value, first, calculate the total number of hours since January 1, 1970 by divided the total number of minutes by 24. Then mod the total number of hours by 24. Note that the hours value that you get must be subtracted by 4 to get the Eastern time. Also be careful, after subtracted by 4, your hour may turn negative. You need to fix it.
When system time is used for stop watch and timer, only use the lower 32 bit. No need to use all 64 bits.
ButtonV in $t9 Clock Stop Watch Timer Hour Minute Second Start Stop Reset 16 32 i1 128 256 Table 1: Associated Values of Buttons ButtonV in $t9 Clock Stop Watch Timer Hour Minute Second Start Stop Reset 16 32 i1 128 256 Table 1: Associated Values of ButtonsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started