+ All Categories
Home > Documents > introduction to c++

introduction to c++

Date post: 25-Apr-2017
Category:
Upload: izami-ariff
View: 219 times
Download: 0 times
Share this document with a friend
22
1. Introduction TO COMPUTERS, LANGUAGES, COMPILERS … 18 Feb. 2014 1
Transcript
Page 1: introduction to c++

1. Introduction TO COMPUTERS, LANGUAGES, COMPILERS …

18 Feb. 2014

1

Page 2: introduction to c++

Computers and Programs• A simplified computer – consists of a processing unit (CPU) and a Memory.

• CPU can understand simple instructions:• read/write a memory location• add two numbers• compare numbers• etc.

2

Page 3: introduction to c++

Machine Code• An executable program – sequence of these simple instructions.• Stored in memory.

• The CPU processes the simple instructions sequentially.• Some instructions can tell the CPU to jump to a new place in memory to get the next instruction.

3

Page 4: introduction to c++

Instructions• Each instruction is stored in memory as a bunch of bits.

• The CPU decodes the bits to determine what should happen.

• Example, the instruction to add 2 numbers might look like this:

10100110

4

Page 5: introduction to c++

Memory• Memory holds program and data.• Each piece of data – a bunch of bits.• Typically the memory is organized in chunks of 8 bits – a byte.

• Each chunk (byte) has an address.

5

Page 6: introduction to c++

Memory address6

Page 7: introduction to c++

Memory address7

Page 8: introduction to c++

A picture – Memory and CPU 8

CPU...

...memory

012345

813458134681347

Address

...

...

Page 9: introduction to c++

Sample Program# Instruction1 Set memory[801] to hold 000000012 Set memory[802] to hold 000000003 If memory[802] = 10 jump to instruction #84 increment memory[802]5 set memory[803] to 2 times memory[801]6 put memory[803] in to memory[801]7 jump to instruction #38 print memory[801]

9

Page 10: introduction to c++

A picture – Memory and CPU

10

CPU

Instruction #1

Instruction #2

Instruction #3

Instruction #4

Instruction #5

Instruction #6...

...memory

012345

801802803

Address

Page 11: introduction to c++

Human vs. Machine Programs• Machine Language – Computer can only understand the bits (the encoded program).

• Assembly Language – Humans don't like to deal with bits, so they developed english-like abbreviations for programs.

11

Page 12: introduction to c++

Assembly vs. Machine Language

12

ST 1,[801]ST 0,[802]

TOP: BEQ [802],10,BOTINCR [802]MUL [801],2,[803]ST [803],[801]JMP TOP

BOT: LD A,[801]CALL PRINT

Assembly Language00100101 1101001100100100 1101010010001010 01001001 1111000001000100 0101010001001000 10100111 1010001111100101 10101011 00000010001010011101010111010100 1010100010010001 01000100

Machine Language

Page 13: introduction to c++

Assembly Language – An example

13

Page 14: introduction to c++

An Assembler

14

AssemblyLanguageProgram

ST 1,[801]. . .

MachineLanguageProgram

0100100110010100

Assembler

Page 15: introduction to c++

Higher-Level Languages• Assembly Language – much easier to deal with than Machine Language• Need to know about all the instructions.

• People developed languages that were independent of the specific machine language.• More abstract representation of instructions.

15

Page 16: introduction to c++

Higher-Level Languages• Many high-level languages have been developed.• Different ways of representing computations.• Different languages for different needs:

• Symbolic vs. Numeric computation• Human efficiency vs. Program efficiency• Portability• Extensibility

16

Page 17: introduction to c++

17

Page 18: introduction to c++

C++• An extension of C.• First developed in the early 1980s (back in the last century!).

• Focus was on Object Oriented Programming• View computer programs as collection of objects.• Objects have attributes and actions.

18

Page 19: introduction to c++

As a C/C++ program

19

set memory[801] to hold 00000001

set memory[802] to hold 00000000

if memory[802] = 10 jump to instruction #8

increment memory[802]

set memory[803] to 2 times memory[801]

put memory[803] in to memory[801]

jump to instruction #3

print memory[801]

x=1;

i=0;

while (i!=10) {

i++;

x=x*2;

}

printf("%d",x);

}

Page 20: introduction to c++

Compiler

20

C++ Program

int main() {int i=1;. . .

MachineLanguageProgram

0100100110010100

C++ Compiler

Page 21: introduction to c++

Many Different Compilers• Different C++ Compilers:

• Microsoft Visual C++• Borland C++• GNU g++• IBM xlc• Sun CC• Eclipse CDT

21

Page 22: introduction to c++

Eclipse CDT• In class we will use both Visual C++ and GNU g++• Windows• Linux

• Also Eclipse CDT• http://www.eclipse.org/cdt/• Open source• Easy to learn• MAC, WINDOWS, LINUX

22


Recommended