CS225,  Fall 2006, Friday Oct. 13, Day 21 Hit reload! After class

(Re) Read Ch. 6.2, Branching and flow of control.  Read Ch. 2.3, C++ functions

Take-home midterm handed out today, Oct 11 (day 20) due the following Wednesday.  Through If/Else.
I will be basing "6-week grades" on the HW I  have received today Oct 11 at the beginning of class.
Beginning code for problem 9 Midtermfile.htm

HW Day 21,
Due Mon. Day 22

A.  Revisiting Stack frame use:  Rewrite the program of Fig. 6.12 (pp. 248-50, a Do loop) so that the variables are stored on the stack as "locals".  Note in the program as given that the While label is never used; nothing branches to it; it's only used as a "comment" marker here. 

D).
  Think about how to multiply a number by a 4-bit number, in binary, in PEP.  Come in with a pseudocode or flowcharted algorithm. (With or without a loop, your choice.)


Program 5,  Program 5 assigned Day 21, Friday Oct 13, Due Wednesday Day 23, Oct 16
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.   You should have done the output for a single j for Day 19, Problem A.  So now you just need to put it in a For loop.


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Notes:  Homework questions?  What was different in A when you ran it with batch input and with interactive I/O?
Input stream in interactive I/O:  PEP doesn't read the input stream till you hit the Enter key.  But then it reads the Enter key as a "character" in the input stream.  So a <enter>  is two characters, gets *?*?


; Program A, day 20, simple version
    br main
ch: .block 1    ;for input
main:    lda 0x0000, i  ;zero out A
    chari ch, d
while:    ldbytea ch, d
        cpa 'y', i
    BREQ endwh
    charo '*', i
    charo '?', i
    chari ch, d
    BR while
endwh:    charo '!', i
    charo '!', i
    stop
    .end


<> REVIEW  Loops:  While, Do while, For  Handout.
       The loop examples from the text
      p. 247,
Fig. 6.10, while.
Homework:  Put up #12, # 15 (p.318) on the board. 
      p. 249, Fig 6.11, do while. 
      p. 251, Fig 6.12, for  (with stack)

How to multiply whole numbers?   (We will program this.)

Look ahead to procedures & functions:  (Ch. 2.3)
C++ "functions"   (Use "procedure" when there's no returned value)
    Main:  We know how to allocate & de-allocate space for local variables, on the stack.  Ignore the Return 0 in a "real" C++ environment.

Procedure with no parameters, no returned value:  Branch to the procedure code("call" it): how do we know where to come back to?
      Answer:  Push the Return Address on to the Stack! as we branch to the procedure, return there at end.   (special instructions: CALL, RETn)

Procedure with "Call-by-value" parameters, no returned value:  void Proc1(int n)
      Call-by-value parameters get copies made for use inside the procedure; the original parameters are left unchanged.  Copies go on the stack.

Procedure with "Call-by-reference" parameters, no returned value:  void Proc2(int& k)
      
Call-by-reference parameters are variables that can be used and changed directly by the procedure.  Their Addresses! go on the stack.
          
(How is this different from global variables?  We just go ahead and use the "global" memory addresses, not mediated through anything on the stack.)

Procedure with "Call-by-value" parameters, a returned value:  int Proc1(int n) 
      
The returned value is put on the stack by the procedure, is retrieved by the calling program.

At the assembly level (or the compiler-writing level) we have to decide on a standardized protocol: in what order these are put on the stack, and which part of the program (caller or callee) has responsibility for allocating and de-allocating.  Warford's protocol is one of several variations that are possible.
We'll start simple and build up.



To Sievers Home Page
CS225-Fall06/Day21.htm 
3pm, 10/11/06
This page belongs to Sally Sievers who is solely responsible for its content. Please see our statement of responsibility.