Difference between revisions of "CSC270 Homework 8 Solution 2016"
(3 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
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. | 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. | ||
− | + | <br /> | |
+ | <source lang="asm"> | ||
+ | |||
LEDs DB 0 | LEDs DB 0 | ||
− | + | ||
+ | </source> | ||
+ | <br /> | ||
Whenever you want to store a 1 in one of the LEDs, say the second one, you can do this: | Whenever you want to store a 1 in one of the LEDs, say the second one, you can do this: | ||
<br /> | <br /> | ||
Line 35: | Line 39: | ||
</source> | </source> | ||
<br /> | <br /> | ||
− | + | ==Software Loop== | |
− | </ | + | <br /> |
+ | 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! | ||
+ | <source lang="asm"> | ||
+ | |||
+ | 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 | ||
+ | |||
+ | </source> | ||
+ | <br /> | ||
+ | =Problem 2= | ||
+ | <br /> | ||
+ | There were several options here. Everybody 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: | ||
+ | <br /> | ||
+ | <source lang="asm"> | ||
+ | |||
+ | |||
+ | 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 | ||
+ | </source> | ||
<br /> | <br /> | ||
+ | each STAX takes 4 cycles. 100 x 4 = 400 cycles. | ||
<br /> | <br /> | ||
+ | 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. | ||
<br /> | <br /> | ||
+ | We will see in class how we can create a solution that would take 104 cycles! Way cool! | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
+ | </showafterdate> | ||
+ | |||
+ | |||
<br /> | <br /> | ||
<br /> | <br /> |
Latest revision as of 10:33, 11 April 2016
--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. Everybody 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>