EASy68K  
It is currently Sun Apr 23, 2017 5:35 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Terminating a loop
PostPosted: Thu Dec 22, 2016 5:39 pm 
Offline

Joined: Thu Dec 22, 2016 5:21 pm
Posts: 2
Hi, I'm after some help and yes this is with an assignment but a rather specific part with which I've become a little bogged down and no amount of research seems to have helped clarify this for me. I'm making a timer that starts and stops when the user presses a key to start and stop the program. I've used the below to read the single character which starts the program fine. I get this is because the following sits outside of my timer loop and so just waits for a user input before calling the time and entering the loop
Code:
    MOVE    #5,D0
            TRAP    #15


I want the timer to be printed continuously until the user presses a key again and the program will then end. My issue is reading the second key press as using task #5 the program sits there until a key is pressed and thus the loop stops. Is there a way around this? Perhaps where a finite amount of time is spent waiting for the second input? I think I/O Task#7 may be of use but I cant find out much about it's use.

Any help would be greatly appreciated.

Jim.


Top
 Profile  
 
 Post subject: Re: Terminating a loop
PostPosted: Thu Dec 22, 2016 7:21 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1036
Location: Monroe County Community College, Monroe Michigan, U.S.A.
I through something together. Trap task 7 is used to test for keyboard input.

Code:
*-----------------------------------------------------------
* Title      : Read key without waiting
* Written by : Charles Kelly
* Date       : Dec-22-2016
* Description: Read a keypress from the keyboard without
*              waiting for input.
*-----------------------------------------------------------
    ORG    $1000
START:                  ; first instruction of program

* Put program code here
    clr.l   count       ; count = 0
Loop
    add.l   #1,count    ; count = count + 1
    move.b  #7,D0       ; Task 7, Check for keyboard input. Set D1.B to 1 if keyboard input is pending,
                        ; otherwise set to 0. Use task 5 to read pending key.
    trap    #15
    if.b D1 <eq> #1 then.s    ; if keyboard input pending
        move.b  #5,D0   ; Task 5, Read single ASCII character from the keyboard into D1.B.
        trap    #15
        move.l  count,D1    ; get count value
        move.b  #3,D0   ; Task 6, Display number in D1.L
        trap    #15     ; Display loop count
    endi
    bra loop
   

    SIMHALT             ; halt simulator

* Put variables and constants here
count   ds.l    1       ; loop counter
    END    START        ; last line of source

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject: Re: Terminating a loop
PostPosted: Thu Dec 22, 2016 9:40 pm 
Offline

Joined: Thu Dec 22, 2016 5:21 pm
Posts: 2
profkelly, that was a great help.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group