22-Assignment-5-Raw-Memory - CS107 Spring 2007 Handout 22...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS107 Handout 22 Spring 2007 May 2, 2007 Assignment 5: Raw Memory Brought to you by Julie Zelenski and Jerry Cain. Bits and Bytes The first several weeks of CS107 are all about solidifying your understanding of memory: arrays, pointers, typecasts, parameter-passing, etc. and then supplementing it with a better understanding of compile-time language implementation: the layout and organization of memory, what kind of code is generated from a compiler, how the runtime memory structures (stack and heap) are managed, and so on. The implementation problem set is a break from the hard-core C coding. It’s your chance to try your hand at generating machine code, to do some in-depth experimentation with the compiler and the debugger in order to dissect your programs. Recall that you’re not expected to hand anything in for this assignment. You’re to work on the problems independently, compare your solutions to the answer key (to be provided on Friday), and ask questions where needed. To Be Completed By: May 9 th at 7:00 p.m. How to compile a program without a Makefile You may want to write little test programs for the lab problems. You're used to relying on the provided Makefiles we wrote to build multi-module programs, but it is possible to just directly invoke the compiler at the shell. Refer to the big UNIX handout for lots of details— here is just a brief summary: To compile and link one file into an executable, you use: % gcc binky.c -o binky which says to compile the file binky.cc , link it, and name the resulting executable binky . To compile multiple files into one executable, you first compile each file separately: % gcc -c streamtokenizer.c -o stremtokenizer.o % gcc -c wordgames.c -o wordgames.o This compiles the file streamtokenizer.c into the output file streamtokenizer.o and stops without linking it. (same for wordgames.c ). And then you invoke gcc again to link like this: % gcc streamtokenizer.o wordgames.o -o word-games that takes the two compiled object files and links them together into one executable called word-games . You can also add other flags for compiling after the gcc such as -Wall (to generate all warnings), -g (to include debugging information, and -O (for optimization).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Problem 1: Binary numbers and bit operations Since computers work entirely in binary, learning how to manipulate numbers in the base two system can sometimes come in handy. Here are a few suggestions of some exercises to test out your understanding of binary numbers. Try converting a few decimal numbers into binary form, do some binary arithmetic with them (add, subtract, maybe even a multiply), and convert the result back to decimal to verify you have it correct. This lets you know you are on top of the basic workings and know how to do all that tedious carrying. Write a test program to find out what happens when you overflow the range of a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2010 for the course CS 107 taught by Professor Cain,g during the Spring '08 term at Stanford.

Page1 / 6

22-Assignment-5-Raw-Memory - CS107 Spring 2007 Handout 22...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online