CS225,  Fall 2006,  Friday Oct 27, Day 27 Hit reload!

  Read  about Arrays (global) 6.4 pp.282-286.  Understand indexed ( x ) addressing mode.

HW Day 24, Due Mon Day 25 
<>Please hand in the Listing from each program.   And draw those arrows from each Branch to its target!
A. Continue to investigate arrays and their addresses in C++.  Addresses in C++ handout. 
              Forgotten how to run a C++ program?  http://aurora.wells.edu/~ccs/cs131/hints.htm      
    a)Can you find out the address of a pointer variable, that is, one that holds an address?  In the first program of the handout, try outputting &adrg.  That's the address of the address of g.   Can you store it in a variable?  If so, how?
    b) Double arrays.  Run the last program (double arrays)  and examine the results.  Look for the pattern.

Read Null&Lobur, Arrays, pp. 575-577  (outside my door) 
   in there, p. 273, #9  Specifically, if you had a matrix (double array),  short arr[5][4],   of two-byte integers,  how many bytes must the block be to store it in? What would the Index be (just the count of data items from 0), and what would the offset be (contents of Index register) to address arr [0][0]?  arr[2][0]?  arr[2][3]?  (It might be easiest to mark out a rectangle with the correct number of rows and columns, and count.)  Can you find a formula for arr[j][k]?
fill in each rectangle the INDEX &OFFSET.  The CONTENTS are already there, randomly chosen numbers)

0
1
2
3
0
__  __    155
__  __   135
__  __   126
__  __   134
1
__  __   136
__  __   190
__  __   146
__  __   144
2
__  __   180
__  __   180
__  __   167
__  __   143
3
__  __   180
__  __   188
__  __   176
__  __   125
4
__  __   197
__  __   178
__  __   166
__  __   135

         
B.  a) Understand the program of Fig. 6.34, p. 284
      b) Rewrite it to process an array of 6 numbers
      c) Rewrite it to process an array of 4 characters.

C.  Take the first program on the arrays handout, and add in this alteration:  Get a number k from the input, and a character, and substitute that character for Msg[k] in memory.  Then output as was.  So if the input is 3 and P, the output is (printed vertically) HelPo.

Program 8, Assigned Day 27, Due Wed. Day 29, Nov. 1
Do #27, p. 323, in Warford.  Note hint on next page, which may or may not be useful, depending on how you choose to do it.

Amnesty: 
Any  old "Programs" handed in  by Monday at 3pm will not be counted as late.  By Wed. at 3 pm will be only 1 day late.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Notes: 

What are we to do with our remaining 5 weeks?  Usually we do a joint programming project in Assembler, and I lecture about other interesting things as you work on the project & we plan, track results and critique.  I've taught enough (after arrays) that we can do it, and usually people enjoy it and find it a very worthwhile enterprise (software engineering without a net).  But there's not a lot of actual programming experience here yet.... CHOICES:
    Group project:  TicTacToe or Chomp(stupid machine) in PEP
    Separate projects (program something extensively in PEP; explore another environment at assembly language level)
    No project; more programs, more "book-learning" about other aspects of operating system and machine architecture.
Email me your thoughts/feelings.  Decision  will be announced Monday.  Decision may be partly based on whether I get any Program 7's .

ARRAYS:  See day 26
  
In PEP:  Use indexed addressing mode (x).    Oprnd = Mem[Oprndspec + X] 
    A label (symbol) labels
the address of the first byte of the first item, the Index register holds the offset.
   Compare to stack relative: 
Oprndspec is the offset to SP.  Indexed: Oprndspec is the base, X the offset.
Examples:  handoutpasteable
    If array elements are one byte (1 address) long, then offset = index.
    If array elements are 2 bytes (2 addresses) long (e.g. PEP numbers), then offset = 2 times index.

At board:  Input 3 numbers from input  into an array, 
Array: .block  ??
   Use indexed addressing,  "for" loop if you can, if not, just straight code.

Double arrays:  int array[2][3].  Just two arrays of length  3 laid end to end in memory; array[0][k] followed by array[1][k].  So the "index" ( counting items from 0) can be thought of as just going from 0 to 6.  Easiest to see in a rectangle.  There is a formula for getting from double index  [ j][k] to count-from-0 index.  [ 2][3] --> 6.  What about the others?  (HW.  Also Discrete I or II)

Fancier Addressing modes:  Investigate n (indirect),  sf, sx, sfx, "cold" using RTL (p. A4)


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