COMP1070/2002/lec1/H.Melikian COMP1070 Lecture #2 Computers and Computer Languages Some terminology What is Software? Operating Systems
COMP1070/2002/lec1/H.Melikian Administrivia Class web page not much there yet, but keep your eyes on it. Almost everything from the Blackboard will be here except your grades, online staff ( exams, quizzes) and solutions
COMP1070/2002/lec1/H.Melikian Understanding computers How does a computer work? – Idiot savant – Very good with a small number of tasks – Completely clueless otherwise What can computers do well? – store and retrieve numbers – very quickly – very accurately – add, subtract, multiply, and divide – also fast and accurate – compare numbers (with 0) – follow a list of instructions and jump around in the list
COMP1070/2002/lec1/H.Melikian What about everything else? – more complex math combination of atomic operations – interaction with peripheral devices output: graphics cards and printers input: keyboards, mice, joysticks all sorts of specialized devices – everything done using numbers
COMP1070/2002/lec1/H.Melikian Computer numbers To the computer, everything is numbers. Computers use binary (base 2) – each digit is 0 or 1 – represents a power of 2 human numbers : You are familiar with decimal d n d n-1 d n-2... d 2 d 1 d 0 d n 10 n + d n-1 10 n-1 + d n-2 10 n-2... d d d 10 0
COMP1070/2002/lec1/H.Melikian binary b n b n-1 b n-2 … b 2 b 1 b 0 b n 2 n + b n-1 2 n-1 + b n-2 2 n-2 … b 2 b 1 b 0 2 0 Example: = 182
COMP1070/2002/lec1/H.Melikian More teminology bit: binary digit byte: a group of 8 bits word: a group of bytes that a specific computer is optimized for working with (usually 4 or 8) kilobyte (K or KB): 1,000 bytes, or sometimes 1,024 bytes (2 10 ) megabyte (M or MB): 1,000,000 bytes, or sometimes 1,028,576 bytes (2 20 )
COMP1070/2002/lec1/H.Melikian why all these powers of 2? Everything is little electronic switches – off or on, true or false, 0 or 1 Decimal is foreign to the computer – it can convert a number to decimal, but that’s really only for human convenience other numbering systems octal – base 8 – used rarely, but you should at least recognize it – digits are 0 through = 3 8 0 = 3 = = 1716
COMP1070/2002/lec1/H.Melikian hexadecimal ( base 16) – used occasionally – you can’t really avoid it – digits are 0-9, a-f 8b7e = 8 16 0 = 8 = = other numbering systems v You do not have to be fluent in either of these (octal or hex) for this class recognize them, don’t be scared of them v know how to convert if you need to but you will rarely need to
COMP1070/2002/lec1/H.Melikian inside the computer… Everything is bits Bits are always grouped – into bytes – into words Every byte is numbered – sequential – called an address – addresses are, of course, numbers themselves Computers execute computer instructions Instructions are numbers – memory access (get/put) – arithmetic (add, subtract, multiply, divide) – compare values (equal, greater than, less than) – change the order instructions are executed in often based on the result of a comparison
COMP1070/2002/lec1/H.Melikian The machine cycle
COMP1070/2002/lec1/H.Melikian what kinds of numbers do computers work with? Instructions, Addresses, Data– integers, real numbers – text – all sorts of other things What is a computer program? - A sequence of processor instructions designed to achieve a specific purpose Computers execute programs sequentially like driving directions – each instruction depends on the last one being completed
COMP1070/2002/lec1/H.Melikian What is a computer program? Each instruction has a numerical code Examples: – Get some data from memory – Add two numbers – If two numbers are equal, jump to a different part of the program Instructions are numbers This is important!
COMP1070/2002/lec1/H.Melikian Only numbers! B EC 83 EC 5C A 00 FF 15 B8 C FC 83 7D FC 00 7D 1B 68 0F B9 E E B C E8 90 FF FF FF 8D 45 EC 50 8B 0D 50 8D FF 15 C0 C FC 83 7D FC 00 7D F F B9 E E8 FD A B C8 E8 5B FF FF FF E9 9C B0 0F D B9 E E8 DD C B C8 E8 3B FF FF FF 8D 55 E D A 01 6A FF 15 C4 C E FC 83 7D FC 00 7C 1D 68 0F F0 68 B B9 E E8 A B C8 E8 FF FE FF FF EB 43 8B 45 FC E8 6A C F B 4D FC B9 E E8 6A B C8 E B C8 E C B C8 E8 BA FE FF FF FF 15 BC C2 42
COMP1070/2002/lec1/H.Melikian push ebp mov ebp,esp sub esp,5Ch push ebx push esi push edi push 0 B call dword ptr (0042c2b8)] mov dword ptr [ebp-4],eax cmp dword ptr [ebp-4],0 jge main+35h ( ) A push ( f) F push offset string "CoInitialize failed." ( ) mov ecx,offset cout (004299e8) call ostream::operator<< (004015a0) E mov ecx,eax v ( ) Part 1
COMP1070/2002/lec1/H.Melikian Part 2 lea eax,[ebp-14h] push eax mov ecx,dword ptr [pid (00428d50)] F push ecx call dword ptr (0042c2c0)] mov dword ptr [ebp-4],eax cmp dword ptr [ebp-4],0 D jge main+6Fh (004010af) F push ( f) push offset string "CLSIDFromProgID failed." (004260f8) mov ecx,offset cout (004299e8) E call ostream::operator<< (004015a0) A3 mov ecx,eax A5 ( ) AA jmp main+10Bh ( b) AF push ( f) B4 push offset string "CLSIDFromProgID succeeded." (004260d8)
COMP1070/2002/lec1/H.Melikian machine language The one “true” computer language – …except there isn’t just one Every computer has its own machine language All other computer languages created for human convenience The computer doesn’t understand C Must be converted into machine language computer languages Assembler ;essentially just machine language with some text codes Compiled languages ;converted into machine language before use – examples: C, Pascal, Fortran Interpreted languages; converted into machine language during use – examples: Basic, Java
COMP1070/2002/lec1/H.Melikian Why more than one? Meet different needs, Tradeoffs, Different approaches Special features Application domain – programmer prefers to think about the application Computer domain – programmer is willing to think about the computer Tradeoffs Control, Ease-of-programming, Performance flexibility different approaches Procedural Object-oriented Special features There are lots of special-purpose languages
COMP1070/2002/lec1/H.Melikian HW #2 Please send the solutions via to and hand in hard copy by the beginning of the class