Computer Systems Organization

Start Lecture #1

Chapter 0: Administrivia

I start at 0 so that when we get to chapter 1, the numbering will agree with the text.

0.1: Contact Information

0.2: Course Web Page

There is a web site for the course. You can find it from my home page, which is http://cs.nyu.edu/~gottlieb

0.3: Textbook

The course has two texts

0.4: Computer Accounts and Mailman Mailing List

0.5: Grades

Grades are based on the labs, midterm, and the final exam, with each very important. The weighting will be approximately
30%*LabAverage + 30%*MidtermExam + 40%*FinalExam> (but see homeworks below).

0.6: The Upper Left Board

I use the upper left board for lab/homework assignments and announcements. I should never erase that board. Viewed as a file it is group readable (the group is those in the room), appendable by just me, and (re-)writable by no one. If you see me start to erase an announcement, let me know.

I try very hard to remember to write all announcements on the upper left board and I am normally successful. If, during class, you see that I have forgotten to record something, please let me know. HOWEVER, if I forgot and no one reminds me, the assignment has still been given.

0.7: Homeworks and Labs

I make a distinction between homeworks and labs.

Labs are

Homeworks are

0.7.1: Homework Numbering

Homeworks are numbered by the class in which they are assigned. So any homework given today is homework #1. Even if I do not give homework today, the homework assigned next class will be homework #2. Unless I explicitly state otherwise, all homeworks assignments can be found in the class notes. So the homework present in the notes for lecture #n is homework #n (even if I inadvertently forgot to write it to the upper left board).

0.7.2: Doing Labs on non-NYU Systems

You may solve lab assignments on any system you wish, but ...

0.7.3: Obtaining Help with the Labs

Good methods for obtaining help include

  1. Asking me during office hours (see web page for my hours).
  2. Asking the mailing list.
  3. Asking another student, but ...
    Your lab must be your own.
    That is, each student must submit a unique lab. Naturally, simply changing comments, variable names, etc. does not produce a unique lab.

0.7.4: Computer Language Used for Labs

Each lab will indicate the language that must be used.

0.8: A Grade of Incomplete

The rules for incompletes and grade changes are set by the school> and not the department or individual faculty member.> The rules set by CAS can be found in , which states:

The grade of I (Incomplete) is a temporary grade that indicates that the student has, for good reason, not completed all of the course work but that there is the possibility that the student will eventually pass the course when all of the requirements have been completed. A student must ask the instructor for a grade of I, present documented evidence of illness or the equivalent, and clarify the remaining course requirements with the instructor.

The incomplete grade is not awarded automatically. It is not used when there is no possibility that the student will eventually pass the course. If the course work is not completed after the statutory time for making up incompletes has elapsed, the temporary grade of I shall become an F and will be computed in the student's grade point average.

All work missed in the fall term must be made up by the end of the following spring term. All work missed in the spring term or in a summer session must be made up by the end of the following fall term. Students who are out of attendance in the semester following the one in which the course was taken have one year to complete the work. Students should contact the College Advising Center for an Extension of Incomplete Form, which must be approved by the instructor. Extensions of these time limits are rarely granted.

Once a final (i.e., non-incomplete) grade has been submitted by the instructor and recorded on the transcript, the final grade cannot be changed by turning in additional course work.

0.9 Academic Integrity Policy

This email from the assistant director, describes the policy.

    Dear faculty,

    The vast majority of our students comply with the
    department's academic integrity policies; see

      www.cs.nyu.edu/web/Academic/Undergrad/academic_integrity.html
      www.cs.nyu.edu/web/Academic/Graduate/academic_integrity.html

    Unfortunately, every semester we discover incidents in
    which students copy programming assignments from those of
    other students, making minor modifications so that the
    submitted programs are extremely similar but not identical.

    To help in identifying inappropriate similarities, we
    suggest that you and your TAs consider using Moss, a
    system that automatically determines similarities between
    programs in several languages, including C, C++, and Java.
    For more information about Moss, see:

      http://theory.stanford.edu/~aiken/moss/

    Feel free to tell your students in advance that you will be
    using this software or any other system.  And please emphasize,
    preferably in class, the importance of academic integrity.

    Rosemary Amico
    Assistant Director, Computer Science
    Courant Institute of Mathematical Sciences
  

Remark: The chapter/section numbers for the material on C, agree with Kernighan and Plauger. However, the material is quite standard so, as mentioned before, if you already own a C book that you like, it should be fine.

Chapter 1: A Tutorial Introduction

Since Java includes much of C, my treatment can be very brief for the parts in common (e.g., control structures).

1.1: Getting Started

Hello World

  #include <stdio.h>
  main() {
    printf("Hello, world\n");
  }

1.2: Variables and Arithmetic Expressions

1.3: The For Statement

1.4 Symbolic Constants

Fahrenheight-Celsius

  #include <stdio.h>
  main() {
    int F, C;
    int lo=0, hi=300, incr=20;
  
    for (F=lo; F<=hi; F+=incr) {
      C = 5 * (F-32) / 9;
      printf("%d\t%d\n", F, C);
    }
  }

Floating Point Fahrenheight-Celcius

#include <stdio.h>
#define LO 0
#define HI 300
#define INCR 20
main() {
      int F;
      for (F=LO; F<=HI; F+=INCR) {
          printf("%3d\t%5.1f\n", F, (F-32)*(5.0/9.0));
      }
  }

1.5: Character Input and Output

getchar() / putchar()

The simplest (i.e., most primitive form of character I/O is getchar() and putchar(), which read and print a single character.

1.5.1: File Copying

File copy is conceptually trivial: getchar() a char and then putchar() the char until eof. The code is on the right and does require some comment despite is brevity.

#include <stdio.h>
main() {
    int c;
    while ((c = getchar()) != EOF)
	putchar(c);
}
  

Homework: Write a (C-language) program to print the value of EOF. (This is 1-7 in the book but I realize not everyone will have the book so I will type them in.)

Homework: (1-9) Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.

1.5.2: Character Counting

1.5.3: Line Counting

1.5.4: Word Counting

The Unix wc Program

The Unix wc program prints the number of characters, words, and lines in the input. It is clear what the number of characters means. The number of lines is the number of newlines (so if the last line doesn't end in a newline, it doesn't count). The number of words is less clear. In particular, what should be the word separators?

#include <stdio.h>
#define WITHIN   1
#define OUTSIDE  0
main() {
  int c, num_lines, num_words, num_chars, within_or_outside;
  within_or_outside = OUTSIDE; /* C doesn't have Boolean type */
  num_lines = num_words = num_chars = 0;
  while ((c = getchar()) != EOF) {
    ++num_chars;
    if (c == '\n')
      ++num_lines;
    if (c == ' ' || c == '\n' || c == '\t')
      within_or_outside = OUTSIDE;
    else if (within_or_outside == OUTSIDE) { /* at beginning word */
      ++num_words;
      within_or_outside = WITHIN;
    }
  }
  printf("%d %d %d\n", num_lines, num_words, num_chars);
}

Homework: (1-12) Write a program that prints its input one word per line.