c++ Intro-2020
c++ Intro-2020
Assembly Languages,
and High-level Languages
• Machine language For a real
– Only language computer directly understands example:
– Defined by hardware design run “od” on
• Machine-dependent an a.out
– Generally consist of strings of numbers file.
• Ultimately 0s and 1s
– Instruct computers to perform elementary operations
• One at a time
– Cumbersome for humans
– Example:
+1300042774 0100 1101 0111 1101 0001 0100 0001 0110
+1400593419 0101 0011 0111 1011 0101 1100 0000 1011
+1200274027 0100 0111 1000 1010 1011 1010 0110 1011
Assembly Languages,
and High-level Languages
2. Assembly language
– English-like abbreviations representing
elementary computer operations
– Clearer to humans
– Incomprehensible to computers
• Translator programs (assemblers)
– Convert to machine language
– Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
2003 Prentice Hall, Inc. All rights reserved.
1.6 Machine Languages, 4
Interpreters
– Source code
• the original program in a high level language
– Object code
• the translated version in machine language
Slide 5
2003 Prentice Hall, Inc. All rights reserved.
Copyright © 2003
Pearson Education, Inc.
Linkers
• A Linker combines
– The object code for the programs we write
and
– The object code for the pre-compiled routines
into
The machine language program the CPU can run
C=a-b
cout
Slide 6
2003 Prentice Hall, Inc. All rights reserved.
Copyright © 2003
Pearson Education, Inc.
History Note
• First programmer
– Ada Augusta, Countess of Lovelace
• Colleague of Babbage
Slide 7
2003 Prentice Hall, Inc. All rights reserved.
Copyright © 2003
•
and
Algorithm
Problem Solving
– A sequence of precise instructions which
leads to a solution
• Program
– An algorithm expressed in a language the computer
can understand
Display 1.6
Slide 8
2003 Prentice Hall, Inc. All rights reserved.
Copyright © 2003
Pearson Education, Inc.
Program Design
Slide 9
2003 Prentice Hall, Inc. All rights reserved.
Copyright © 2003
Pearson Education, Inc.
Problem Solving Phase
Slide 10
2003 Prentice Hall, Inc. All rights reserved.
11
1.14 Basics of a Typical C++
Environment
– C++ Language definition
– Program-development environment (tools)
• compiler, linker, editor, debugger
– C++ Standard Library (software)
• precompiled routines you can use
– Syntax-grammar/rules -is a girl good sita
– Semantics –meaning –Sita is a good girl.
– Sqrt(190)-math.h, cos(), pow(7,4)
– Iostream.h-cout, cin. Get(), Put()
Compiler
foo.o Compiler creates object code and
stores it on disk (.o file)
C++ Library Linker foo Linker links the object code with the
(a.out) libraries, stores in a.out on disk.
Loader
Loader puts program
Run in memory (RAM)
..
(load and execute) ..
..
./foo, ./a.out
Environment
• Input/output streams in C++
– cin (pronounce “see in”)
• Standard input stream
• Normally keyboard
– cout(pronounce “see out”)
• Standard output stream
• Normally computer screen
– cerr (pronounce “see air”)
• Standard error stream
• Display error messages (normally, screen)
• May be different from cout
if cout is being directed to a file, for example with
a.out > foo.dat, or if program is logging errors to a file.
Welcome to C++!
Welcome
to
C++!
• Variable names
– Correspond to actual locations in computer's memory
– Every variable has name, type, size and value
– When new value placed into variable,
overwrites previous value
– Reading variables from memory is nondestructive
integer1 45
std::cin >> integer1;
– Assume user entered 45 integer2 0
sum -3
integer1 45
std::cin >> integer2;
– Assume user entered 72 integer2 72
sum -3
1.24 Arithmetic
* Multiplication
/ Division
Integer division truncates remainder
7 / 5 evaluates to 1
% Modulus operator returns remainder
7 % 5 evaluates to 2
1.24 Arithmetic
Equality operators
= == x == y x is equal to y
!= x != y x is not equal to y