PEP8.03 looks good. I'll put it in the
lab this afternoon. Feel free to download it from the usual site.
Another wrinkle in PEP: If you
re-Execute without re-Load ing first, your memory locations will not be
restored to their original ones (e.g. if you initialize something to be
0 using .word 0, it won't be re-initialized. ) All that happens
is the PC is reset to 0. So ReLOAD, at least.
Please hand in the Listing from each program. And draw those arrows from each Branch to its target!
- - - - - - - - - - -
- - - - - - - - - - -
Postpone A, B, C below.
Reassigned Day 17 A. Linearize the flowchart
on your handout. (Redraw it so all the boxes are in one column.)
Reassigned Day 17 B. Run the C++ program of Figure 6.14 (p. 250)
Verify that the
loop counter continues to exist and is one bigger than the last value
in the loop, after the loop is done. In a highly structured
language you might expect that it should disappear after the counted
loop is finished. Write down your opinion on using the
value in the loop counter after the loop is finished, when working in a
structured environment.
Reassigned Day 17
C. Make a detailed pseudocode analysis or a flowchart
for this problem: count the number of 1's in the rightmost 4 bits
of the binary representation of a number input from the keyboard.
Output the original number and the number of 1's.
Reassigned Day 19 D.(postponed
from day 13).
Write a program that gets two
numbers from input. If the second is smaller than the first,
output an S. (If not, do nothing). At the end, output
"Bye". No loop, just an if.
Check it on input pairs 22 36, 22 22, 22 15. You may use
"global" type "variables." Hand in or email
code, hand in listing.
Postpone the rest:
Reassigned Day 19
Textbook p. 318, #2, #3(loop),
Reassigned
Day 18
#4 Before
(or after??) you figure out what it does, print out the program of
figure 6.16.
Put in all the arrows. There are small bits of "dead",
"inaccessible"
code, that never will be executed. Find and mark these. )
#12 (Write a while loop)
Reassigned Day 19 #13 Don't
write the
program.
Make a flow chart, with a diamond decision for each part of the if.
(For
example, one diamond for (ch>='A') and another for (ch<='Z')
)
Hand in your original flow chart, and a linearized one. (Notice,
no loop.) (Note: it took a while for a programmer trained in
a context without compound decisions like (a &&b) to learn to
use them. It's probably just as hard to figure out how to do
without.)
- - - - - - - - - - - - - - - - - - - -
Program 5, assigned Day 14 15, due Monday Day 17, Oct 22 For loop: What will
CHARO output? Write a program.
"Global" variable style is 0K.
For j = 0 to 127
output j, a space, the character with that ascii number, a space, the
character with
that ascii number + 128, and line feed.
Example: for decimal 66, the
output will be 66 B Â
<LF>
Save your output file, open it in Word or equivalent, and print out the
results for 30 up; describe any effects from values below 30 (you know
hex 0A = 10D is the linefeed)
Programming/debugging
suggestions. One problem is writing the "for" loop.
Write it so it just prints out the decimal numbers from 0 to 127, to
make sure it works. The other is printing out a
correct line of output. Write this so it works for a single
decimal value, for instance 66. Then put the two together.
(Or work on one and then the other. ) If you try to do both at
once, at this point, you're likely to get lost. "Top down" is
excellent, but you have to understand your building materials for it to
work.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = =
Notes: Continuing with If/else, Day
13
Branches must happen as soon as the flag is set, or at least
before something else changes a flag.
Flags stay if not affected by next op. Check
front of book: Which ops do NOT affect flags?
Str, Stbyte, Chari, Charo, Deco, Stro, all
BR's (& CALL, jump to procedure, RETn return from proc.,
RETTRreturn from trap, MOVSPA, MOVFLGA, STOP, and the NOPs) )
Some ops only affect N, Z. Which? Ldr,
Ldbyte, And, Or, Not. Deci
affects
NZV, ASR affects NZC
, Rotates affect only C.
So it's safe to Store a value before branching on it.
Altering a program with branches: It's very easy to
find you have to insert some code at a target, or (less often) take it
out, and without the structures of the higher order language, you can
forget to move your target labels! A helpful aid for this is a
NOP (there are NOP0, NOP1, 2, 3 in PEP8--they are
"placeholders" we can use to program traps). But NOP is a "no
operation operation" which does nothing, just "marks time". If
you make your "target" a NOP, you (probably) won't mess up your
branching when you change your code.
Loops: While, Do while (once thru at least), For j
= 1 to 5. Handout.
| To Sievers Home Page |
CS225-Fall06/Day14.htm
|
|