Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Machine Model Memory

Similar presentations


Presentation on theme: "The Machine Model Memory"— Presentation transcript:

1 The Machine Model Memory
A one dimensional array of individually addressable storage elements. Each element, called a byte, holds 8 binary digits (bits) of information. It is extremely important to understand and be able to distinguish the address of a storage element the contents of a storage element

2 The Machine Model Memory the address of a storage element
Addresses begin at 0 and increase in unit steps to N-1 where N is the total number of bytes in the address space. A pointer variable holds an address. the content of a storage element Since each byte consists of only 8 bits, there are only 256 different values that can be contained in a storage element. These range from binary to binary , which corresponds to decimal numbers 0 to 255.

3 The Machine Model Aggregation of basic memory elements
More than 8 bits are needed for useful application to numerical problems. Thus it is common to group adjacent bytes into units commonly called words. Multiple word lengths are common, and common word lengths include 2 bytes, 4 bytes, and 8 bytes. In some architectures (Sun Sparc) it is required that the address of each word be a multiple of word length. That is, the only valid addresses of 4-byte words are 0, 4, 8, 12, 16, ...) .

4 C Programming Language
Developed at AT&T Bell Labs in early 1970s Unix also developed at Bell Labs All but core of Unix is in C Standardized by American National Standards Institute (ANSI)

5 Introduction to C Procedural language
Facilitates a structured and disciplined approach to computer program design Provides low-level access Highly portable

6 Structure of a C Program
Preprocessor Directives Global Declarations int main ( ) { } // main Other functions as required Local Declarations Executable code Basic Block

7 C Program Structure The Basic Block - { declaration of variables
executable code } Historically, unlike in Java and C++, all variable declarations must precede the first line of executable code within the block. With newer compilers this restriction may not be true, but in any case, scattering variable declarations throughout a program has adverse effects on the readability and maintainability of a program. Nesting of blocks is legal and common. Each interior block may include variable declarations.

8 Declaration of variables
Two generic types of basic (unstructured) variables exist: integer floating point Integer variables may be declared as follows: char a; /* 8 bits */ short b; /* (usually) 16 bits */ int c; /* (usually) 32 bits */ long d; /* 32 or 64 bits */ long long e; /* (usually) 64 bits */

9 Declaration of variables
These declarations implicitly create signed integers. An 8 bit signed integer can represent values in the range [-27,...0, ] Signed integers are represented internally using 2's complement representation.

10 Declaration of variables
Unsigned integers Each of the preceding declarations may also be preceded by the qualifier unsigned. unsigned char a; /* 8 bits */ unsigned short b; /* (usually) 16 bits */ An 8 bit unsigned integer can represent values in the range [0, ] In all modern computer systems different hardware instructions are used for signed and unsigned arithmetic.

11 Encoding of integer constants:
Integer constants may be expressed in several ways decimal number 65 hexadecimal number 0x41 octal number 0101 ASCII encoded character 'A' ALL of the above values are equivalent ways to represent the 8 bit byte whose value is:

12 Encoding of integer constants:
Constants of different representation may be freely intermixed in expressions. x = 11 + 'b' '\t'; x = 0xb + 0x62 - 0x2d + 0x9; x = ; x = 73;

13 Floating point data Two variations on floating point variables float 32 bits double 64 bits Example float a, b; double c; Floating point constants can be expressed in two ways Decimal number Scientific notation e+3 avogadro = e+23;

14 Executable code Expressions: consist of (legal combinations of): constants variables operators function calls Operators Arithmetic: +, -, *, /, % Comparative: ==, != , <, <=, >, >= Logical: !, &&, || Bitwise: &, |, ~, ^ Shift: <<, >>

15 Executable code Special types of expression A statement consists of an expression followed by a semicolon An assignment expression consists of lvalue = expression; lvalue is short for "left-value", which in turn represents any entity that may legitimately be assigned a value: The two most common examples are: A simple variable A pointer dereference

16 Executable code Warnings: Non-assignment statements (with the exception of function calls) are syntactically legal but (generally) semantically useless: x + y - 3; x <= 2; x == y;

17 Executable code Warnings: Use parentheses to avoid problems with: operator precedence (the order in which the operators are evaluated) y = x + 5 & z - 5; and operator associativity (the direction in which operations of equal precedence are evaluated) y = 10 / 5.0 * 4.0;

18 Executable code Control flow: if and while if (expression)
statement | basic-block <--- Executed if expression value is true else statement | basic-block <--- Executed if expression value is false while (expression) statement | basic-block <--- Executed while expression remains true do <--- Executed until expression becomes false statement | basic block while (expression);

19 Executable code Control flow: if and while There is no boolean type in C. Integers are used for this purpose. An expression is false <=> its value is 0 If the expression is an assignment, the value of the expression is the value that is assigned. Be particularly careful not to confuse the following: if (x = (a + b)) if (x == (a + b)) Be careful not to accidentally use: while (x < y);

20 Executable code Function definitions
A C function is comprised of 4 components the type of value returned by the function the name of the function parenthesized declaration of function parameters at least one basic block containing local variable declarations and executable code int main(int argc, char *argv[]) { --- basic block --- } /* argc - number of command line arguments */ /* argv - array of pointers to command line arguments */

21 Compiling and Running a Program
To compile and print all warning messages, type gcc –Wall prog-name.c If using math library (math.h), type gcc –Wall prog-name.c -lm By default, the compiler produces the file a.out

22 Compiling and Running a Program
To execute the program type ./a.out The ./ indicates the current directory To specify the filename for the object code, for example, p1.o, type gcc –Wall –o p1.o prog1.c then type ./p1.o to execute the program


Download ppt "The Machine Model Memory"

Similar presentations


Ads by Google