Docsity

Optimizing Code, The Memory Hierarchy - Lab Work | CS 4400, Lab Reports of Computer Science

Partial preview of the text

Download Optimizing Code, The Memory Hierarchy - Lab Work | CS 4400 and more Lab Reports Computer Science in PDF only on Docsity!

CS 4400

Computer Systems

August 24, 2009 — LECTURE 1

Administrative details

What to expect from CS 4400

Overview of computer systems

Background

● The purpose of this course is to help you bridge the gap

between high-level programming and the actual

computer system.

● (^) “from a programmer's point of view” ●

A computer system consists of hardware and software

working together to run application programs.

● (^) processors, memory, OS, compilers, networks, ... ●

You must have already taken CS 3500 and 3810.

●

Familiarity with C++ is assumed. We will use C.

Lab Work

● (^) Data representation —implement logical and arithmetic functions by manipulating the bits that make up values. ● (^) Disassembling an object code file —reverse engineer a program to determine what it does. ● (^) Implementing a buffer overrun attack —modify the run-time behavior of a program to exploit a buffer overflow bug. ● (^) Performance optimization —transform source code to make it run faster. ● (^) Exceptional control flow —implement your own Unix shell. ● (^) Dynamic storage allocation —implement your own version of C's malloc and free functions.

Your Responsibilities

● Attend class. When you must miss, check the web and ask

classmates for material covered.

●

Complete the problem sets. They will prepare you for exams

and are for credit.

● Submit assignments on time. Or suffer the consequences of the

late policy. All programs must run in CADE lab1!

●

Keep up with your grades. See the course staff promptly if you

have a dispute (within one week of getting grade).

● Do not fall behind. If you do, see the course staff ASAP.

● Become self-sufficient , if you aren't already. (more later)

Life of a Program—Source

●

Example :

●

How is this program “born”?

#include <stdio.h> int main(void) { printf("hello, world\n”); return 0; } hello.c 2369 6e63 6c75 6465 203c 7374 6469 6f2e 683e 0a0a 696e 7420 6d61 696e 2876 6f 6429 207b 0a20 2070 7269 6e74 6628 2268 656c 6c6f 2c20 776f 726c 645c 6e22 293b 0a0a 2020 7265 7475 726e 2030 3b0a 7d0a hello.c in hexl-mode (emacs) 23 is ASCII code for '#' in hex (35 in decimal)

Life of a Program—Translation

●

Same bit patterns read by the computer during execution?

● The compiler translates a source file into an executable

object file.

● (^) preprocessing—more later ● (^) compilation—translates hello.c into hello.s (assembly lang) ● (^) assembly—translates hello.s into hello.o (machine lang) ● (^) linking—links hello.o to standard C library to get hello ... call printf addl $16, %esp movl $0, %eax ... hello.s (x86 assembly language) unix> gcc -o hello hello.c

Life of a Program—Execution

●

The shell is a command-line interpreter.

● (^) first word is built-in shell command or name of executable file

● The shell loads the executable file hello (copying the

code and data from disk to main memory).

●

The processor executes the instructions in main.

● (^) copies the data (i.e., the string) from main memory to cache ● (^) then copies the string to the display device (and to the screen) unix> ./hello hello, world unix> Unix shell

Organization of Storage: A Hierarchy

●

A lot of time is spent moving information around.

● (^) Does all of this copying slow the “real work” of the program? ●

Larger storage devices are slower than smaller ones.

Faster storage devices are more expensive than slower.

DISK MEMORY siz e decreasing speed increasing cost REGISTERS

● The processor can read data

from a register nearly 100x

faster than from main memory.

●

But, the register file stores

only a few hundred bytes.

MAIN MEMORY CACHE

The Operating System

●

Although hello requires the keyboard, display, disk,

and main memory—none of them are accessed directly.

● The operating system is a layer of software between the

application program (hello) and the hardware.

●

Three fundamental abstractions:

● Processes —the illusion that hello is the only program running

●

Virtual memory —each process appears to have exclusive use of

main memory ●

Files —every I/O device viewed uniformly as a file

Useful Outcomes of CS 4400

●

You will be a more effective programmer.

● (^) detecting and fixing bugs more efficiently ● (^) understanding and tuning program performance ●

You will be more resourceful and self-sufficient.

● (^) better at figuring things out yourself ● (^) making effective use of available documentation

● You will be comfortable using the terminal and command-line

(having already mastered IDEs in previous classes).

●

You will have a firm foundation for specialized systems classes

in CS and real-world SW development.