CSC270 Homework 8 Solution 2016

From dftwiki3
Revision as of 10:33, 11 April 2016 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut (talk) 10:16, 11 April 2016 (EDT)


<showafterdate after="20160101 00:00" before="20160601 00:00">

Problem 1


The hardware design is the same as the one we used in class, with 3 LEDs. Other designs could work, of course, but this one is fine.

With this design, storing a 1 at 8000 activates the first LED. Storing a 2 activates the 2nd one. Storing a 4 activates the 3rd one. Storing a 7 activates all 3. Storing a 0 turns them all OFF.

The trick here is that what you have is an output port. Once a flip-flop is set to some bit, either 0 or 1, there is no way for the processor to read that bit back to figure out if the attached LED is ON or OFF. So LDAA 8000, ORA 8000, ANDA 8000 won't work! They won't because they will all read from Address 8000, but there is nothing there to be read. What the 6811 will get is the input of the D flipflops. You cannot get the bits inside a flip-flop by looking at its input; only by looking at its Q output. So, these proposed solutions did not work.

But you can figure out what is stored in the flip-flops by storing the same information in a byte variable, in memory. Let's call this variable LEDs.

        LEDs         DB         0


Whenever you want to store a 1 in one of the LEDs, say the second one, you can do this:

        LDAA       #2                  ;get ready to turn LED 2 ON
        ORAA       LEDs              ;OR with that the current settings of the LEDs, as reflected in variables
        STAA       LEDs              ;update variable
        STAA       8000             ;store new configuration in real LEDs


This way all 3 LEDs are initialized, the 2nd one with a 1, the other 2 with the values they had before.

If we want to turn OFF an LED, say the third one, we can do this:

        LDAA       #255-4           ;get ready to turn LED 3 OFF
        ANDA       LEDs              ;AND with that the current settings of the LEDs, as reflected in variables
        STAA       LEDs              ;update variable
        STAA       8000             ;store new configuration in real LEDs


Software Loop


Here we do not need to remember the state of the LEDs in a variable, since we always want one LED ON and the other 2 OFF. So we don't need to remember their current state. The coding is simple. By the way, we have a function in the Monitor that waits one second if you call it. Its address is C027. Very useful!

LEDs    DB    0

start:  LDAA  #1    ; turn Green ON
        STAA  8000  

        JSR   C027  ; wait 1 sec
        JSR   C027  ; wait 2 sec
        JSR   C027  ; wait 3 sec

        LDAA  #2    ; turn Yellow ON
	STAA  8000  

        JSR   C027  ; wait 1 sec

        LDAA  #4    ; turn Red ON
	STAA  8000  

        JSR   C027  ; wait 1 sec
        JSR   C027  ; wait 1 sec
        JSR   C027  ; wait 1 sec
	
	JMP   start


Problem 2


There were several options here. Every body picked the idea of 1 flip-flop and 1 LED, as we had done in the lab. That's fine.

The fastest loop you can have, then, is no loop at all! Just write down 100 STAX instructions one after the other:

start:  LDAA  #1    ; to turn LED ON
        LDAB  #0     ; to turn LED OFF

        STAA  8000  
        STAB  8000  
        STAA  8000  
        STAB  8000  
        STAA  8000  
        STAB  8000  
        STAA  8000  
        STAB  8000  
...                                ; for a total of 100 STAX instructions
        STAA  8000  
        STAB  8000  
        STAA  8000  
        STAB  8000  

        JMP   C000           ; return to OS


each STAX takes 4 cycles. 100 x 4 = 400 cycles.
The class results for working solutions: 1 solution at 402 cycles, 1 solution at 500, 1 solution at 802, 2 solutions at 900, and 1 solution at 950 cycles.
We will see in class how we can create a solution that would take 104 cycles! Way cool!


</showafterdate>