2018 CMSI 2210: Computer Systems Organization

CMSI 2210: Welcome to Week 01

WELCOME!!

Today, the first day of the semester, will be a pretty typical 'first day of class'. We'll cover the course syllabus, then take a brief tour of the course website so you'll know where to find your reading and homework assignment information.

Then during the rest of the week we will begin to look at some of the fundamental tools and development environment things you will need for the semester.

Finally, we'll end up with a little coding exercise which will make sure your C programming environment is set up.

The Grand Tour

First things first:

A little welcome message…

First we need to cover the basics, since fundamentals are critical to success in anything!

  • Syllabus and Textbook — know what to expect and what is expected
  • This Week's Agenda
  • Class Website
  • Classnotes page
  • Coding Standards
  • Be a Grammarian
  • Diagrams and modeling to express designs, concepts, and ideas

Helpful Links and Programming Information

Textbook links

There is no assigned textbook for this course. There are a number of books that address the concepts we will study, but they are all very expensive. While they do collect the information all in once place for convenience, you can find all the information on the Internet if you just apply yourself a bit. In addition, here are some very useful and informative links to related material:

You can also get a free downloadable textbook through the library called Programming with 64-Bit ARM Assembly Language. Log in to the Hannon Library website using your LMU credentials, search for that title, and download the book!

Tools you will use during the semester

The following items will be tools you need to do the work in this course:

  • You will need to get a copy of the GCC compiler to be able to do the exercises. We will be working with the C programming language, which is not only a time-honored tradition for creating operating system code [especially with UNIX/Linux flavors], but also is the best way to create code when speed of execution is of the essence [short of writing code in assembler, which is difficult and platform-specific].
    Link to MinGW, for Windows users to get the GCC environment ~ Mac users you probably already have it, check using terminal
    Also check my GitHub repo for a different Windows-only copy [which requires a bit more work to install]
  • You will need to download and install an assembler. The class will be using NASM which is one tool for building X86 code for Intel processors. There are lots of assemblers for this platform, but this is the one I'll be using for this class because it has a syntax that is most easily understood.
    Here is a link to nasm, to get the nasm assembler; this will require some unzipping, possibly installing, and search path redirection
  • If you are on an Apple platform with either an M1 or M2 processor, you will need a different application program for assembling. Actually you'll need TWO programs. One is called as, short for assembler. The other is called ld, short for loader. Both of these are already built into the terminal window, so you're pretty much assured to be good to go.

  • You will need to download and install a text editor. Text editors are literally everywhere. There are some which are full development environments, also known as Integrated Development Environments or IDEs; examples include the venerable Eclipse IDE from this site, and NetBeans, which is direct from Oracle at this location. Another one that you have probably already seen [if you haven't installed it already] is VS-Code.
    The rest of this list has editors that are mostly only the editor part of the equation, meaning you can edit code but there may not be much if any compileing, linking, or running from within the editor application itself; you'll need to have a terminal window open to compile, link, and run your code. These include Notepad++, Atom, SublimeText, and TextPad. All of these tools have the lovely syntax coloring which you can use stock or customize to your heart's content. Some allow you to add links to compile and even run your code. The IDEs have the advantage of compiling as you go, which shows you the error of your ways with nearly every keypress. All have ability to display the line numbers for the code, which is REALLY handy for collaborative debugging. Some people [like me] find the fact that IDE's correct things problematic. I'll talk about that in class.

    Personally, I like the feel of the totally hands-on approach, so I'll be using either TextPad, or SublimeText, or even [GASP!] Windows Notepad to create code in class, and the terminal window [or DOS window] to do compilation and running of the code.

    Initial Roll Call And Other Sundries

    …Just to make sure we're adults…

    And now for the dreaded pariah of all classes, the tell-the-professor-all-about-me excercise, which is guaranteed to have you all shifting uneasily in your seats! So, tell me a little about yourself, including:

    Group Work and Group Assignments

    We will be using an application which was created by LMU Students in the Spring Semester of 2024 to create groups for work this semester. The application is called Gruuper and this will help generate and maintain the group assignments. To use Gruuper, first you must join the 'class' and provide some information to the tool. Here are the steps:

    Assignment Submissions

    Homework assignments for this class must be done in groups. For each assignment, you and your partners turn in ONE copy of the assignment. Assignments are mixed, with exercises consisting of both programming projects and short answer questions. As many of you may have heard, I'm a big believer in fostering critical thinking skills, so there will be questions that are intended to make you think about what you are doing in various respects like morals, ethics, and decomposition of problem statements in addition to programming tasks.

    All homework must be submitted in GitHub. Please get an account if you don't already have one, and make a repository for this class. NOTE: because the assignments will be done in groups, you will need a single shared account for your group. If you WANT to make three accounts you are welcome to do so, but please be sure that I know which account will be the one you are using for the submissions. Note that means ONLY one account for submissions for the ENTIRE SEMESTER! I don't want to go chasing around through multiple repo's to find your submissions.

    Please name your repo using the phrase "CMSI-2210_" in the name, followed by the names of the team members. Please use uppercase for CMSI, then a dash, then the numbers, then an underscore, followed by your last names in alphabetical order. For example, if Anais Nin, Talia Shire, and Pablo Picasso are in a group, name your repo CMSI-2210_NinPicassoShire. Under your repository, please generate the following FOLDER structure [which I will demonstrate in class]:

    IMPORTANT SAFETY TIPS:

    I will be using this folder structure to perform the evaluations of your work. I use the GitHub desktop on my Windows machine to duplicate [clone] your repository to my local computer for doing those evaluations, and I have several scripts that I set up to facilitate compiling/assembling and running your programs. Any deviation from the above structure means my scripts will not work with your submissions, and you will NOT earn any credit.

    Additionally, CODE THAT DOES NOT COMPILE OR ASSEMBLE WILL NOT BE EVALUATED.
    PERIOD.
    FULL.
    STOP.
    The time for submitting code with compile errors is past since you have been through CMSI 185/186/1010. Make sure your code compiles/assembles FROM THE COMMAND LINE before you turn it in. I will be demonstrating how to do that in class in case you are unfamiliar.

    REMEMBER: I use the command line for compiling/assembling and running your programs. If you are using an IDE like NetBeans, VS-Code, or Eclipse, be sure your program can be successfully compiled/assembled from the REAL command line, and that it runs that way as well. It's an extra step for some of you, yes, but this operation/activity reflects the real world of software development – just because it works for you in VSCode doesn't mean that the USERS who run your code will be running it from Eclipse, if they even HAVE Eclipse. Most of your users will think Eclipse is that thing that happens in the sky with the sun.

    Development Notes

    You will be learning the C language during this course. You won't be experts, but you will be learning enough to be able to complete the course and to understand the concept of pointers, addressing, and memory allocation.

    You will also be learning assembly language during this course. Again, you won't become an expert, but you WILL get experience with how assembly lets you access the lowest levels of processor operations, which s a fundamental knowledge of how programs and applications work. Many students absolutely HATE assembly, at least at first, because it can be difficult to get programs to work properly since the concepts are so low-level. However, if you apply yourself and take the challenge, assembly can actually be fun, because you have full control of the computer and can make it do all sorts of things that are much more difficult [even impossible!] in any other language.

    Homework Assignments…

    Since there is not a textbook, homework assignments will be taken from other places. Most, if not all, of the programming assignments can be found, with their corresponding [potential] solutions, on the Internet. However, as clearly stated on the syllabus page, copying code from the Internet is plagiarism, unless you cite where you got it! If you download a solution to turn in, put a comment in the code in a header at the top of the file that says where it came from. You had also better be able to tell me HOW IT WORKS AND WHY IT'S A GOOD SOLUTION so that I can assess if you really understand it. Deviation from this policy will earn you a grade of zero on the assignment.

    Basics of C

    Practically since the time it was invented, people have hated programming in this language. It can be very tricky to use, since even though it is considered a 'higher level' language, it is only one step removed from assembly language. This makes it very fast, and speed is essential to success in many applications such as embedded sensor systems, avionics, automobiles, and operating systems. However, the idea of memory allocation, pointers, structures, and other such concepts are very confusing at first.

    C is a compiled language, but it's not compiled like Java. As you know, when you make a Java program, you compile it to byte code, then you start the JVM to run the program. The JVM handles all the access to operating system functions for you. However, with C you must handle such things yourself. There is no virtual machine middleware, your program is compiled directly to binary that the computer can execute, and is linked with a set of libraries that handle a lot of the low-level operating system calls for you.

    First things first: we will be using the command line! There is a brief list of common commands on the course web site at this link. I recommend that you read it and get familiar with these commands. Second, you are free to use an IDE to develop your code if you wish; but be aware that when I evaluate your work, I will be using the command line! Any code that doesn't work when I type in the command manually will not be given a grade.

    The definitive book on the C language is still the K & R book written by Kernighan and Ritchie sometime in the last century. In some ways, the language has changed a lot. In other basic ways, it is pretty much the same as it always was. It is those same parts we'll be using. If you can find a copy of the book you might snag a copy for yourself. For those who are looking to get into embedded systems programming it will be WAY more than just a doorstop or paperweight. The ISBN is 978-0131103627.

    Traditionally, the first program in any language is the hello world program. Actually, this probably started with C, since it is the first thing in the book. The program looks like this:

       #include <stdio.h>
    
       int main( int argc, char * argv[] ) {
    
          printf( "\n\n   Hello, world!\n\n" );
    
       }
                

    This should look very Java-esque to you, and for good reason. In fact, Java syntax [according to the Nutshell book] was initially modeled on the C language. I'll pick this program apart during class. This is the first program you will use to verify that your development environment is set up and working properly.

    Much of the language consists of standard libraries. There are quite a few of them, but you will most often use the stdio, stdlib, string, and a few others. We'll see them during the course. The point here, though, is to notice the #include line at the top of the file [which is pronounced pound include]. Here is a link to a very good [reference] website for learning all about the C standard library.

    C is statically typed, just like Java. You must declare the variables' types, and they must remain that type for the duration of the program or module [scope-based]. There are LOTS of types, and there is type coersion and casting as you'd expect. Vanilla C doesn't have objects, and that's another reason people don't like it; instead you have structs or structures, which allow you to define aggregated user-defined data types, that are like an object, but are NOT an object. There are 'strings', but they are treated as sequences [arrays] of characters and always must end with a null character, which in this language is the sequence \0. Sometimes it is put on the end of the string automatically by a function, and sometimes you have to add it yourself. Another thing which gives people fits is variable addressing, also known as pointers. This concept allows the programmer to de-reference a variable. We'll see how all this works as we go along.

    We Have Sample Programs…
    Get 'em While They Are HOT!!!

    One of the first things we'll learn about C programming is that there are LOTS of ways to make the programs and make them correctly. To start with, let's take a look at an old standby, a program to convert Fahrenheit to Celsius. Here is what it looks like in JavaScript:

       let f = parseFloat( prompt( "Enter a temperature in degrees Fahrenheit: " ))
       alert( f + " degrees F is " + (((f - 32) * 5) / 9) + " degrees C." );
                

    Note that it's two simple lines. By the way, you can run JavaScript code in this window. That makes it easy to test out simple JavaScript code, which we'll do in class.

    In Python it looks like this:

       f = float( input( "Enter a temperature in degrees Fahrenheit: " ) )
       print( f, "degrees F is ", (((f - 32) * 5) / 9), " degrees C" )
                

    In Java it looks like this:

       import java.util.Scanner;
       class CtoFconverter {
          public static void main( String args[] ) {
             System.out.println( "Enter a temperature in degrees Fahrenheit: ");
             Scanner myInput = new Scanner( System.in );
             double degreesF = Double.parseDouble(myInput.nextLine());
             System.out.println( degreesF + " degrees F is " + (((degreesF - 32.0) * 5.0) / 9.0) + " degrees C." );
          }
       }
                

    [Note to self: several things about this code to the class.]

    Now, here it is in C:

    #include <stdio.h>
    #include <stdlib.h>
    
    int main( int argc, char * argv[] ) {
    
       double degreesf;
       char   input[25];
       printf( "Enter a temperature in degrees Fahrenheit: " );
       degreesF = atof( gets( input ) );
       printf( "%10.3f degrees F is %10.3f degrees C. ", degreesF, (((degreesF - 32.0) * 5.0) / 9.0) );
       exit( 0 );
    
    }
                

    [Note to self: several things about this code to the class.]

    The Venerable Command Line

    As far as commanding, controlling, or operating a computer goes,
    ANYTHING you can do in a GUI, you can do from the command line!

    Sometimes this seems a bit counter-intuitive, because we have all become so used to using the Graphical User Interface [GUI] that we don't even stop to think about it. However, back in the days BEFORE there WAS a GUI, there was ONLY the command line, and we got along just fine! [An interesting read about this by author Neal Stephenson of Snow Crash fame is available for download as either a zip file for Windows or a stuffit file for Mac at this link.]

    The first thing to realize is there are two different versions of the command line, one for Windows and one for Mac, and they have different commands to do the same operations. We'll see how this goes in a few minutes.

    The second thing to realize is, there are multiple versions of the command line based on which version of UNIX/Linux you are using. For most Mac users, that will be either the bash shell or the zsh shell, which may be familiar to many of you. The word shell is applied to the Command Line Interpreter, also known as the CLI, which is the part of the Operating System [O/S] that interprets typed user commands on the command line.

    Some of the VERY basic commands are listed on this page of the web site so that you can have easy access to them. A simple Internet search will turn up hundreds or thousands of help pages as well, no matter what platform you are using.

    [move along to demonstrate some common commands in Windows. Don't forget to bring in a Mac if possible, or borrow one from a student to plug in for a terminal window demonstration.]

    In-class Assignment #1

    The purpose of this assignment is to make sure that you have all the parts set up for doing the work that will be part of this course. There are two parts: in part one you will work in class to get the coding environment set up and verify that it works; in part two you will modify the initial code from this classwork exercise

    1. Install a text editor on your computer if you haven't already done so. You can refer to the lists at the top of this page for links to the download pages for several popular editor applications.
    2. Install the GCC compiler on your computer if you haven't already done so. On Windows you can use either MinGW or the gcc and jens editor package from my repository.
    3. On Mac, check to see if gcc [or clang] is there already by opening a terminal window and typing gcc and press ENTER. If you get an error message that says:

      gcc: fatal error: no input files
      compilation terminated.

      …then you are good to go. This error simply means the operating system found the gcc program but you didn't give it a source file to work with.
    4. If you did NOT see that message, it means either gcc is not installed OR [more likely] your operating system doesn't know where gcc is because it is not in your search path. There are instructions for adding gcc to your search path in the repository as well, both for Windows and for Mac. I'll explain this in class and I'll try to help as many of you as I can, but if there are lots of you it may bleed over into office hours to get things set up for everyone. You can always work with a partner for this first exercise if you have a person in the class you know and can pair up with.
    5. Now for the actual assignment…
      Create a file called sayhello.c in a directory of your choosing by whatever method you are comfortable with.
    6. Edit the file and create a program that will simply print Hello, World! to the console using printf(); you'll need to include the stdio.h header file. Use the code shown in the previous example for F to C conversions as a model.
    7. Compile your program with the GCC compiler using the command:
         gcc sayhello.c -o sayhello
                          
    8. Run your program to make sure everything works. Here are the commands:
             ON MAC —→    ./sayhello
         ON WINDOWS —→    sayhello
                          
    9. Go to GitHub and set up your repo and submission structure if you haven't already done so. Be sure to use the naming convention and structure that is presented above.
    10. Upload and commit your completed sayhello.c file to your repo.
    11. Pat yourself on the back for a job well done! [Just don't hurt yourself…]

    Homework Assignment #1

    I wanted to give you a heads-up on the homework assignments that you will be doing this semester. They are all available from the syllabus page, but just to make sure… Both assignment number one and assignment number three are due Wednesday/Thursday of week three.

    Also note that homework #1 is an extended version of your in-class assignment for this week. You should end up with a copy of the in-class portion in your 'classwork01' folder, and another copy of that same file in your 'homework01' folder in your repository along with the expanded version of the program there. You only need to submit one copy of each for your group, and I won't actually be looking at them until week three. This is to give you time for your groups to be composed.

    Week One Wrap-up

    That's probably enough for the first week. Be sure to check out the links to the related materials that are listed on the class links page. Also, don't forget the project page!


    I hear, and I forget.
    I see, and I remember.
    I do, and I understand.
    Ancient Chinese Proverb