Notes: HW questions?
On board, in pairs: (Day 19 from Day 13/14) Textbook
p.
319 #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.)
How to multiply whole
numbers? (We will program this.)
Overview of procedures, Day 21
6.3 Procedures.
Recall Run-time stack=user stack.: Built in to CPU.
SP stack pointer. Gives Address of top of stack (latest
occupied slot)
Stack grows Backward through memory from FBCF (FBCF is top of
"empty" stack. Our first push will be to (FBCE, pushing a byte,)
or FBCD, pushing a word.)
"Function"~~"Procedure"~~"Subroutine" . Functions usually
return
a value, Subroutines and Procedures usually only change
parameters.
But language is imprecise.
Flow of code: Insert a chunk of code (written down
elsewhere) into a sequence. Unconditional branch TO the chunk,
and BACK to the next instruction after the branch away. Problem:
if you want to re-use this chunk somewhere else, there's no way to
branch back to this different place, with our existing
instructions.
Need special Procedure-managing instructions. Put return address
on the stack!
Procedure (function) call: CALL address:
In
calling program.
Pushes PC (address of next
instruction)
on stack.
SP<--SP-2
mem[SP]<--PC
Branches to address
PC<--address
"CALL address", with no addressing mode, == "CALL
address, i". The OprndSpec=Operand is what gets put into
the PC.
Return from Procedure RET0 (unary)
At End of Procedure.
Pops PC from stack (returns control to calling
program, right after where it left calling program.)
PC<--mem[SP]
SP<--SP+2
(We also have RET1....RET7; we'll look at them soon.)
Examples: Program, Fig 6.18 , p. 259
Tracing: Set Break points by putting checks
in boxes in Assembler listing, to run through
uninteresting code, switch to single step at interesting points.
(0012 =last * in PrintTri())
These operations allow code to be reused in different places in a
program,
with control returning to the next instruction after the call!
Nested procedure calls: Example below.
For now, no parameters! No local variables. (Can't do
much but output, immediate mode)
| To Sievers Home Page |
CS225-Fall06/Day22.htm
|
|