Implementing a Stopwatch Program using a 68K Based Processor

Verified

Added on  2023/04/21

|3
|914
|414
Homework Assignment
AI Summary
This assignment presents a comprehensive design and implementation of a stopwatch functionality using a 68K-based processor. The program is controlled by a single button to start and stop the timer, displaying the time elapsed. The program flow involves resetting the timer, waiting for button presses, getting and storing the system time, calculating the time difference, and displaying the timer count in tenths of seconds, seconds, and minutes. The code is written in 68K assembly language, including initialization of variables, reading keyboard input, clearing the screen, getting the timer value, performing calculations, and displaying the time. The program continuously checks for button presses to either stop or reset the timer, creating a functional and interactive stopwatch application.
Document Page
Objective:
To design a stop watch functionality using 68K based processor.
Introduction:
The program is expected to be controlled by a single button that starts the timer. And when pressed
again it stops the timer. The time display is held at the same value. The timer value resets every
alternate button press.
Program Flow:
1. Reset Timer count to 0.
2. Display Timer count
3. Wait for button press until key pressed
4. Get the current system time in hundredths of second
5. Store the value as base value to compare the time lapse
6. Read the system time again
7. Find the difference between this time and base time
8. Divide the difference by 10 to get value in 10th of seconds
9. Divide this count again by 10 to get value in seconds as quotient and remainder as tenth of
seconds
10. Store value of tenth_sec in counter
11. Divide the value of seconds by 60 to obtain value in mintues and remaining seconds
12. Store value of seconds in counter
13. Store value of minutes in counter
14. Display Timer count
15. Check for button press
16. If no key pressed loop back to step 6
17. Else wait for the next button press to restart the timer from 0.
Program Code:
*-----------------------------------------------------------
* Title :
* Written by :
* Date :
* Description:
*-----------------------------------------------------------
ORG $1000
start_time: DC.L $0
tenth_sec: DC.W $0
sec: DC.W $0
min: DC.W $0
ORG $1100
START: ; first instruction of program
* Put program code here
LEA tenth_sec(PC),A1 ; initialize pointers to tenth_sec,sec
and minute
LEA sec(PC),A2
LEA min(PC),A3
JSR DISP_FUNC
wait_for_start:
MOVE #7,D0 ; read if keyboard input is pending,
wait for button press
TRAP #15
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
BTST #0,D1
BEQ wait_for_start
* here when button pressed to start timer
MOVE.L #0,D1
MOVE D1,(A1) ; reset tenth_sec
MOVE D1,(A2) ; reset sec
MOVE D1,(A3) ; reset min
MOVE.L D1,(A0) ; reset start_time
MOVE #$FF00,D1
MOVE #11,D0
TRAP #15 ; clear screen
;JSR DISP_FUNC
* get timer value and store
MOVE #8,D0
TRAP #15
LEA start_time(PC),A0
MOVE.L D1,(A0) ; D1 holds timer start value and must
be stored as start time
MOVE #5,D0
TRAP #15 ; clear keybaord input pending
interrupt
interval_time:
MOVE #8,D0
TRAP #15 ; D1 holds current time
MOVE.L (A0),D2 ; get start time
SUB.L D2,D1 ; D1 = Current time - start time
MOVE.L D1,D2 ; hold interval for calculations
DIVU #10,D1 ; divide be 10 to get interval as 10th of seconds
AND.L #$0000FFFF,D1 ; Value is now in 10th of seconds
DIVU #10,D1 ; get 10th of sec and sec
MOVE.L D1,D2 ; keep a copy
LSR.L #8,D1
LSR.L #8,D1 ; now holds tenth sec
MOVE D1,(A1)
MOVE.L D2,D1
AND.L #$0000FFFF,D1 ; holds only seconds
DIVU #60,D1 ; get minute and seconds
MOVE.L D1,D2 ; keep a copy
LSR.L #8,D1
LSR.L #8,D1 ; now holds sec
MOVE D1,(A2)
MOVE.L D2,D1
AND.L #$0000FFFF,D1 ; holds only min
MOVE D1,(A3)
JSR DISP_FUNC
* check if button was pressed then stop and reset else loop
MOVE #7,D0 ; read if keyboard input is pending, wait for
button press
TRAP #15
BTST #0,D1
BEQ interval_time
* here if button pressed , reset and loop
MOVE #5,D0
TRAP #15 ; clear keybaord input pending interrupt
; JSR DISP_FUNC
BRA wait_for_start
* SIMHALT ; halt simulator
* display here the time interval
Document Page
DISP_FUNC:
MOVE (A3),D1 ;get min and display
MOVE #3,D0
TRAP #15
MOVE #58,D1
MOVE #6,D0
TRAP #15
MOVE (A2),D1 ;get sec and display
MOVE #3,D0
TRAP #15
MOVE #58,D1
MOVE #6,D0
TRAP #15
MOVE (A1),D1 ;get tenth_sec and display
MOVE #3,D0
TRAP #15
MOVE #$0D,D1
MOVE #6,D0
TRAP #15
RTS
END START ; last line of source
chevron_up_icon
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]