Top Banner
Computers Binary Representations, Components, Architectures, Programming Languages BBM 101 - Introduction to Programming I Hacettepe University Fall 2016 Fuat Akal, Aykut Erdem, Erkut Erdem 1 Today Stored program computers Components of a computer Von Neumann architecture Programs and Data Binary data representations Bit operations Programming languages (PLs) Syntax and semantics Dimensions of a PL Programming paradigms A partial history of PLs Today Stored program computers Components of a computer Von Neumann architecture Programs and Data Binary data representations Bit operations Programming languages Syntax and semantics Dimensions of a PL Programming paradigms A brief history of PLs Recall: Stored Program Concept Stored-program concept is the fundamental principle of the ENIAC’s successor, the EDVAC (Electronic Discrete Variable Automatic Computer) Instructions were stored in memory sequentially with their data Instructions were executed sequentially except where a conditional instruction would cause a jump to an instruction someplace other than the next instruction Slide credit: G. Kesden
20

Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

Aug 11, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

ComputersBinaryRepresentations,Components,Architectures,ProgrammingLanguages

BBM101- IntroductiontoProgrammingI

Hacettepe UniversityFall2016

FuatAkal,AykutErdem,Erkut Erdem

1

Today• Storedprogramcomputers

– Components ofacomputer– VonNeumannarchitecture

• ProgramsandData– Binarydatarepresentations– Bitoperations

• Programming languages(PLs)– Syntaxandsemantics– DimensionsofaPL– Programmingparadigms– ApartialhistoryofPLs

Today• Storedprogramcomputers

– Components ofacomputer– VonNeumannarchitecture

• ProgramsandData– Binarydatarepresentations– Bitoperations

• Programming languages– Syntaxandsemantics– DimensionsofaPL– Programmingparadigms– AbriefhistoryofPLs

Recall:StoredProgramConcept• Stored-program concept isthefundamentalprincipleoftheENIAC’s successor, theEDVAC(ElectronicDiscreteVariableAutomaticComputer)

• Instructionswerestoredinmemory sequentiallywiththeirdata

• Instructionswereexecuted sequentially exceptwhereaconditional instructionwouldcauseajumptoaninstruction someplaceotherthanthenextinstruction

Slidecredit:G.Kesden

Page 2: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

StoredProgramConcept

• “Fetch-Decode-Execute” cycle

CentralProcessingUnit

ArithmeticUnit

Registers

Input Output

Memory

Address Contents20010000001(ADDtoR1)201 01100110(datavalue102)202 10010001(ADDtoR1)20301100110(dataataddress102)20411110111(JUMP7bytes)Slidecredit:G.Kesden

StoredProgramConcept• Mauchly andEckertaregenerallycreditedwiththeideaofthestored-program

• BUT:JohnvonNeumannpublishesadraftreportthatdescribes theconceptandearnstherecognitionastheinventoroftheconcept– “vonNeumannarchitecture”– AFirstDraftofaReportoftheEDVACpublishedin1945

– http://www.wps.com/projects/EDVAC/

Slidecredit:G.Kesden

TheIntegratedCircuit• RobertNoyce andJackKilby arecreditedwiththeinventionoftheintegratedcircuit(IC)ormicrochip.– Kilby winsNobelPrizeinPhysicsin2000.– RobertNoyce co-founded Intelin1968.

• Bythemid1970s,ICscontainedtensofthousands oftransistorsperchip.– In1970,Intelcreatedthe1103--thefirstgenerallyavailableDRAMchip.

– Today,youwouldneedmorethan65,000ofthemtoput8MBofmemoryintoaPC.

Slidecredit:G.Kesden

UnitsofMemory• Byte B 8bits(8b)• Kilobyte KB 1024B =210 bytes ≈103 bytes• Megabyte MB 1024KB =220 bytes ≈106 bytes• Gigabyte GB 1024MB =230 bytes ≈109 bytes• Terabyte TB 1024GB =240 bytes ≈1012 bytes• Petabyte PB 1024TB =250 bytes ≈1015bytes

• Howmanybytescanbestoredina4GBflashdrive?

• Howmanybytes/second isa16Mbpscablemodemconnection?

Slidecredit:G.Kesden

Page 3: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

HowTimeFlies

Commodore64(1982)40cmX22cmX8cm64KBofICmemory$595

AppleiShuffle (2008)3cmX3cmX1cm2GBofflashmemory$49

Slidecredit:G.Kesden

Moore’sLaw• GordonMooreco-foundedIntelCorporation in1968.

• Famousforhispredictiononthegrowthofthesemiconductorindustry:Moore’sLaw

– ftp://download.intel.com/research/silicon/moorespaper.pdf– Anempiricalobservationstatingineffect thatthecomplexityof

integratedcircuitsdoublesevery18months.(“complexity”generallymeansnumberoftransistorsonachip)

Slidecredit:G.Kesden

Moore’sLaw

Source:IntelCorporation

ADetailedView 8 Chapter 1 A Tour of Computer Systems

Figure 1.4Hardware organizationof a typical system. CPU:Central Processing Unit,ALU: Arithmetic/LogicUnit, PC: Program counter,USB: Universal Serial Bus.

CPU

Register file

PC ALU

Bus interface I/Obridge

System bus Memory bus

Mainmemory

I/O busExpansion slots forother devices suchas network adaptersDisk

controllerGraphicsadapter

DisplayMouse Keyboard

USBcontroller

Diskhello executable

stored on disk

systems, but all systems have a similar look and feel. Don’t worry about thecomplexity of this figure just now. We will get to its various details in stagesthroughout the course of the book.

Buses

Running throughout the system is a collection of electrical conduits called busesthat carry bytes of information back and forth between the components. Busesare typically designed to transfer fixed-sized chunks of bytes known as words. Thenumber of bytes in a word (the word size) is a fundamental system parameter thatvaries across systems. Most machines today have word sizes of either 4 bytes (32bits) or 8 bytes (64 bits). For the sake of our discussion here, we will assume a wordsize of 4 bytes, and we will assume that buses transfer only one word at a time.

I/O Devices

Input/output (I/O) devices are the system’s connection to the external world. Ourexample system has four I/O devices: a keyboard and mouse for user input, adisplay for user output, and a disk drive (or simply disk) for long-term storage ofdata and programs. Initially, the executable hello program resides on the disk.

Each I/O device is connected to the I/O bus by either a controller or an adapter.The distinction between the two is mainly one of packaging. Controllers are chipsets in the device itself or on the system’s main printed circuit board (often calledthe motherboard). An adapter is a card that plugs into a slot on the motherboard.Regardless, the purpose of each is to transfer information back and forth betweenthe I/O bus and an I/O device.

Image:R.E.Bryant,D.R.O’Hallaron,G.Kesden

8 Chapter 1 A Tour of Computer Systems

Figure 1.4Hardware organizationof a typical system. CPU:Central Processing Unit,ALU: Arithmetic/LogicUnit, PC: Program counter,USB: Universal Serial Bus.

CPU

Register file

PC ALU

Bus interface I/Obridge

System bus Memory bus

Mainmemory

I/O busExpansion slots forother devices suchas network adaptersDisk

controllerGraphicsadapter

DisplayMouse Keyboard

USBcontroller

Diskhello executable

stored on disk

systems, but all systems have a similar look and feel. Don’t worry about thecomplexity of this figure just now. We will get to its various details in stagesthroughout the course of the book.

Buses

Running throughout the system is a collection of electrical conduits called busesthat carry bytes of information back and forth between the components. Busesare typically designed to transfer fixed-sized chunks of bytes known as words. Thenumber of bytes in a word (the word size) is a fundamental system parameter thatvaries across systems. Most machines today have word sizes of either 4 bytes (32bits) or 8 bytes (64 bits). For the sake of our discussion here, we will assume a wordsize of 4 bytes, and we will assume that buses transfer only one word at a time.

I/O Devices

Input/output (I/O) devices are the system’s connection to the external world. Ourexample system has four I/O devices: a keyboard and mouse for user input, adisplay for user output, and a disk drive (or simply disk) for long-term storage ofdata and programs. Initially, the executable hello program resides on the disk.

Each I/O device is connected to the I/O bus by either a controller or an adapter.The distinction between the two is mainly one of packaging. Controllers are chipsets in the device itself or on the system’s main printed circuit board (often calledthe motherboard). An adapter is a card that plugs into a slot on the motherboard.Regardless, the purpose of each is to transfer information back and forth betweenthe I/O bus and an I/O device.

TheVonNeumann architecture

Page 4: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

MotherboardLayout(Intel486)

Slidecredit:D.Stotts

MotherboardLayout(Intel486)

CPUregscache

MainmemoryRAM

Diskdrives,DVD

Network,cloud

USB

Slidecredit:D.Stotts

What Happens When You Power on Your Computer?

• Aminimumamountofinformationisreadfromsecondarymemoryintomainmemory

• Controlistransferredtothatareaofmainmemory;thiscodereadsthecoreoftheOS,calledthekernel

• Thekernelexecutesthe initialprocess

• ThisprocessloadsafullOSoffdisk(orcloud)

• Calledbootstrapping (pullingoneselfupbyone’sbootstraps)…thecomputer“bootsup”

• OSthenrunsalltheotherprogramsyouwriteanduse…Slidecredit:D.Stotts

MainmemoryRAM

kernel

CPUDisk

OSloads

kernel

CPUrunskernel

Kerneltalkstodisk

CPUrunsfullOSOS

KeyboardMic

camera

Userinput

Datatoprograms

Dataoutputwireless,usb,net,printport,sound,video

CPUrunsprograms

Slidecredit:D.Stotts

Page 5: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

Memory• Fixed-sizeunits(cells)

tostoredata

• Eachcellhasitsownaddress.

• Volatilevs.non-volatile

– Volatilememories loseinformationifpoweredoff(e.g.RAM)

– Nonvolatilememoriesretainvalueevenifpoweredoff(e.g.ROM,cachememory,SSDs)

BusinterfaceBusinterfaceBusinterfaceBusinterfaceBusinterfaceBusinterfaceBusinterfaceBusinterface

048.....

address

a memorycell

Arithmetic-LogicUnit(ALU)• ALU+Control=Processor• Registers. Storagecellsthatholdsheavilyusedprogramdata

– Withoutaddress,specificpurpose– e.g. theoperandsofanarithmeticoperation, theresultofanoperation, etc.

PC

Businterface

ALU

Registerfile

CPUchip

TraditionalBusStructure• Abusisacollectionofparallelwiresthatcarryaddress,data,

andcontrolsignals.• Busesaretypicallysharedbymultipledevices.

Mainmemory

I/ObridgeBusinterface

ALU

Registerfile

CPUchip

Systembus Memorybus

Image:R.E.Bryant,D.R.O’Hallaron,G.Kesden

DiskDrives

SpindleArm

Actuator

Platters

Electronics(includingaprocessorandmemory!)

SCSIconnector

ImagecourtesyofSeagateTechnology

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

Asolid-statedrives(SSDs)• Nomovingparts

Magneticdiskdrives• Rotatingdisks

Page 6: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

TheMemoryHierarchy• Storagedevicesformahierarchy• Storageatonelevelservesasacacheforstorageatthenext

lowerlevel.14 Chapter 1 A Tour of Computer Systems

CPU registers hold words retrieved from cache memory.

L1 cache holds cache lines retrieved from L2 cache.

L2 cache holds cache linesretrieved from L3 cache.

Main memory holds disk blocks retrieved from local disks.

Local disks hold filesretrieved from disks onremote network server.

Regs

L3 cache(SRAM)

L2 cache(SRAM)

L1 cache(SRAM)

Main memory(DRAM)

Local secondary storage(local disks)

Remote secondary storage(distributed file systems, Web servers)

Smaller,faster,and

costlier(per byte)storagedevices

Larger,slower,

andcheaper

(per byte)storagedevices

L0:

L1:

L2:

L3:

L4:

L5:

L6:

L3 cache holds cache linesretrieved from memory.

Figure 1.9 An example of a memory hierarchy.

Just as programmers can exploit knowledge of the different caches to improveperformance, programmers can exploit their understanding of the entire memoryhierarchy. Chapter 6 will have much more to say about this.

1.7 The Operating System Manages the Hardware

Back to our hello example. When the shell loaded and ran the hello program,and when the hello program printed its message, neither program accessed thekeyboard, display, disk, or main memory directly. Rather, they relied on theservices provided by the operating system. We can think of the operating system asa layer of software interposed between the application program and the hardware,as shown in Figure 1.10. All attempts by an application program to manipulate thehardware must go through the operating system.

The operating system has two primary purposes: (1) to protect the hardwarefrom misuse by runaway applications, and (2) to provide applications with simpleand uniform mechanisms for manipulating complicated and often wildly differentlow-level hardware devices. The operating system achieves both goals via the

Figure 1.10Layered view of acomputer system.

Application programs

Operating system

Main memory I/O devicesProcessor

Software

Hardware

Image:R.E.Bryant,D.R.O’Hallaron,G.Kesden

ComponentsofaComputer(cont’d)

• Sequentialexecutionofmachineinstructions– Thesequenceofinstructionsare

storedinthememory.¢ Oneinstructionatatime isfetched

fromthememorytothecontrolunit.– Theyarereadinandtreated

justlikedata.

• PC(programcounter)isresponsible fromtheflowofcontrol.

• PCpointsamemory locationcontaininganinstructiononthesequence.

• Earlyprogrammers(coders)writeprogramsviamachineinstructions.

Memory

Control ALU PC

inst1inst2inst3..instN

AssemblyLanguage• Alow-levelprogramming languageforcomputers

• Morereadable, English-likeabbreviations forinstructions

• Architecture-specific

• Example:

MOV AL, 61hMOV AX, BXADD EAX, 10XOR EAX, EAX

CPU

• Programmer-VisibleState– PC:Programcounter

• Addressofnextinstruction– Registerfile

• Heavilyusedprogramdata– Conditioncodes

• Storestatusinformationaboutmostrecentarithmeticoperation

• Usedforconditionalbranching

PC Registers

Memory

ObjectCodeProgramDataOSData

Addresses

Data

Instructions

Stack

ConditionCodes

–Memory• Byteaddressablearray• Code,userdata,(some)OSdata• Includesstackusedtosupportprocedures

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

AssemblyProgrammer’sView

Page 7: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

TheOperatingSystem(OS)• Theoperatingsystemisalayerofsoftwareinterposed

between theapplicationprogramandthehardware.– Unix,Linux,MacOS,Windows,etc.

• AllattemptsbyanapplicationprogramtomanipulatethehardwaremustgothroughtheOS.

• Theoperatingsystemhastwoprimarypurposes:1. Toprotectthehardwarefrommisusebyrunawayapplications,and2. Toprovideapplicationswithsimpleanduniformmechanismsfor

manipulatingcomplicatedandoftenwildlydifferent low-levelhardwaredevices.

14 Chapter 1 A Tour of Computer Systems

CPU registers hold words retrieved from cache memory.

L1 cache holds cache lines retrieved from L2 cache.

L2 cache holds cache linesretrieved from L3 cache.

Main memory holds disk blocks retrieved from local disks.

Local disks hold filesretrieved from disks onremote network server.

Regs

L3 cache(SRAM)

L2 cache(SRAM)

L1 cache(SRAM)

Main memory(DRAM)

Local secondary storage(local disks)

Remote secondary storage(distributed file systems, Web servers)

Smaller,faster,and

costlier(per byte)storagedevices

Larger,slower,

andcheaper

(per byte)storagedevices

L0:

L1:

L2:

L3:

L4:

L5:

L6:

L3 cache holds cache linesretrieved from memory.

Figure 1.9 An example of a memory hierarchy.

Just as programmers can exploit knowledge of the different caches to improveperformance, programmers can exploit their understanding of the entire memoryhierarchy. Chapter 6 will have much more to say about this.

1.7 The Operating System Manages the Hardware

Back to our hello example. When the shell loaded and ran the hello program,and when the hello program printed its message, neither program accessed thekeyboard, display, disk, or main memory directly. Rather, they relied on theservices provided by the operating system. We can think of the operating system asa layer of software interposed between the application program and the hardware,as shown in Figure 1.10. All attempts by an application program to manipulate thehardware must go through the operating system.

The operating system has two primary purposes: (1) to protect the hardwarefrom misuse by runaway applications, and (2) to provide applications with simpleand uniform mechanisms for manipulating complicated and often wildly differentlow-level hardware devices. The operating system achieves both goals via the

Figure 1.10Layered view of acomputer system.

Application programs

Operating system

Main memory I/O devicesProcessor

Software

Hardware

AbstractionsProvidedbyanOS• Theoperatingsystemachievesbothgoalsviathefundamental

“abstractions”– Processes:Theoperatingsystem’sabstractionforrunningprograms.– VirtualMemory:Anabstractionthatprovideseachprocesswiththe

illusionthatithasexclusiveuseofthemainmemory.– Files:AbstractionsforI/Odevices

Section 1.7 The Operating System Manages the Hardware 15

Figure 1.11Abstractions provided byan operating system.

Main memory I/O devicesProcessor

Processes

Virtual memory

Files

fundamental abstractions shown in Figure 1.11: processes, virtual memory, andfiles. As this figure suggests, files are abstractions for I/O devices, virtual memoryis an abstraction for both the main memory and disk I/O devices, and processesare abstractions for the processor, main memory, and I/O devices. We will discusseach in turn.

Aside Unix and Posix

The 1960s was an era of huge, complex operating systems, such as IBM’s OS/360 and Honeywell’sMultics systems. While OS/360 was one of the most successful software projects in history, Multicsdragged on for years and never achieved wide-scale use. Bell Laboratories was an original partner in theMultics project, but dropped out in 1969 because of concern over the complexity of the project and thelack of progress. In reaction to their unpleasant Multics experience, a group of Bell Labs researchers—Ken Thompson, Dennis Ritchie, Doug McIlroy, and Joe Ossanna—began work in 1969 on a simpleroperating system for a DEC PDP-7 computer, written entirely in machine language. Many of the ideasin the new system, such as the hierarchical file system and the notion of a shell as a user-level process,were borrowed from Multics but implemented in a smaller, simpler package. In 1970, Brian Kernighandubbed the new system “Unix” as a pun on the complexity of “Multics.” The kernel was rewritten inC in 1973, and Unix was announced to the outside world in 1974 [89].

Because Bell Labs made the source code available to schools with generous terms, Unix developeda large following at universities. The most influential work was done at the University of Californiaat Berkeley in the late 1970s and early 1980s, with Berkeley researchers adding virtual memory andthe Internet protocols in a series of releases called Unix 4.xBSD (Berkeley Software Distribution).Concurrently, Bell Labs was releasing their own versions, which became known as System V Unix.Versions from other vendors, such as the Sun Microsystems Solaris system, were derived from theseoriginal BSD and System V versions.

Trouble arose in the mid 1980s as Unix vendors tried to differentiate themselves by adding newand often incompatible features. To combat this trend, IEEE (Institute for Electrical and ElectronicsEngineers) sponsored an effort to standardize Unix, later dubbed “Posix” by Richard Stallman. Theresult was a family of standards, known as the Posix standards, that cover such issues as the C languageinterface for Unix system calls, shell programs and utilities, threads, and network programming. Asmore systems comply more fully with the Posix standards, the differences between Unix versions aregradually disappearing.

Today• Storedprogramcomputers

– Components ofacomputer– VonNeumannarchitecture

• ProgramsandData– Binarydatarepresentations– Bitoperations

• Programming languages– Syntaxandsemantics– DimensionsofaPL– Programmingparadigms– ApartialhistoryofPLs

BinaryDataRepresentations

0.0V0.5V

2.8V3.3V

0 1 0

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

¢ Binary - takingtwovalues¢ bit=0 or 1

§ FalseorTrue§ OfforOn§ LowvoltageorHighvoltage

Page 8: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

EncodingByteValues• Byte=8bits– Binary000000002 to111111112– Decimal:010 to25510– Hexadecimal0016 toFF16• Base16numberrepresentation• Usecharacters‘0’to‘9’and‘A’to‘F’

0 0 00001 1 00012 2 00103 3 00114 4 01005 5 01016 6 01107 7 01118 8 10009 9 1001A 10 1010B 11 1011C 12 1100D 13 1101E 14 1110F 15 1111

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

Byte-OrientedMemoryOrganization

• ProgramsRefertoVirtualAddresses– Conceptuallyverylargearrayofbytes– Systemprovidesaddress spaceprivatetoparticular“process”

• Programbeingexecuted• Programcanclobberitsowndata,butnotthatofothers

• Compiler+Run-TimeSystemControlAllocation– Wheredifferentprogramobjectsshouldbestored– Allallocationwithinsinglevirtualaddress space

• • •

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

MachineWords• MachineHas“WordSize”– Nominalsizeofinteger-valueddata• Includingaddresses

– Mostcurrentmachinesuse32bits(4bytes)words• Limitsaddresses to4GB• Becomingtoosmallformemory-intensiveapplications

– High-endsystemsuse64bits(8bytes)words• Potentialaddressspace≈1.8X1019 bytes• x86-64machinessupport48-bitaddresses:256Terabytes

– Machinessupportmultipledataformats• Fractionsormultiplesofwordsize• Alwaysintegralnumberofbytes

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

Word-OrientedMemoryOrganization

• Addresses SpecifyByteLocations– Addressoffirstbyte inword– Addressesofsuccessivewordsdifferby4(32-bit)or8(64-bit)

000000010002000300040005000600070008000900100011

32-bitWords Bytes Addr.

0012001300140015

64-bitWords

Addr =??

Addr =??

Addr =??

Addr =??

Addr =??

Addr =??

0000

0004

0008

0012

0000

0008

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

Page 9: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

vonNeumannRevisitedProgramsandtheirdataallstoredtogetherinmemory!

• Some0’s1’schunksstandfornumbers

• Somestandforcharacters, text

• Somestandforimages,videos,etc.

• Somestandformemory locations

• Somestandforprogram instructions like“add2numbers”or“saveregister5tomemory location2145768”

• Computer sortsitalloutduring thefetch-execute cycle

Adoptedfrom:D.Stotts

ByteOrdering

• Howshouldbyteswithinamulti-bytewordbeorderedinmemory?

• Conventions– BigEndian:Sun,PPCMac,Internet• Leastsignificantbytehasthehighestaddress

– LittleEndian:x86• Leastsignificantbytehasthelowestaddress

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

ByteOrderingExample• BigEndian– Leastsignificantbytehashighestaddress

• LittleEndian– Leastsignificantbytehaslowestaddress

• Example– Assumewehavea4-bytedatarepresentation0x01234567storedattheaddress0x100

0x100 0x101 0x102 0x103

01 23 45 67

0x100 0x101 0x102 0x103

67 45 23 01

Big Endian

Little Endian

01 23 45 67

67 45 23 01

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

TheOriginof“endian”

“Gulliverfindsoutthatthereisalaw,proclaimedbythegrandfatherofthepresentruler,requiringallcitizensofLilliputtobreaktheireggsonlyatthelittleends.Ofcourse,allthosecitizenswhobroketheireggsatthebigendswereangeredbytheproclamation.Civilwarbrokeoutbetween theLittle-EndiansandtheBig-Endians,resultingintheBig-Endians takingrefugeonanearbyisland,thekingdomofBlefuscu.”

– DannyCohen, OnHolyWarsandAPleaForPeace,1980

IllustrationbyChrisBeatrice

Page 10: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

RepresentingIntegersDecimal: 15213

Binary: 0011 1011 0110 1101

Hex: 3 B 6 D

6D3B0000

IA32, x86-64

3B6D

0000

Sun

int A = 15213;

93C4FFFF

IA32, x86-64

C493

FFFF

Sun

Two’s complement representation(will be covered in BBM 231)

int B = -15213;

long int C = 15213;

00000000

6D3B0000

x86-64

3B6D

0000

Sun6D3B0000

IA32

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

BooleanAlgebra• Developed byGeorgeBoolein19thCentury– Algebraicrepresentationoflogic

• Encode“True”as1and“False”as0

Andn A&B=1whenbothA=1andB=1

Orn A|B=1wheneitherA=1orB=1

Notn ~A=1whenA=0

Exclusive-Or(Xor)n A^B=1wheneitherA=1orB=1,butnotboth

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

ApplicationofBooleanAlgebra

• AppliedtoDigitalSystemsbyClaudeShannon– 1937MITMaster’sThesis– Reasonaboutnetworksofrelayswitches• Encodeclosedswitchas1,openswitchas0

A

~A

~B

B

Connection whenA&~B | ~A&B

A&~B

~A&B= A^B

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

GeneralBooleanAlgebras• OperateonBitVectors– Operationsappliedbitwise

• AllofthePropertiesofBooleanAlgebraApply

01101001& 0101010101000001

01101001| 0101010101111101

01101001^ 0101010100111100

~ 010101011010101001000001 01111101 00111100 10101010

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

Page 11: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

Representing&ManipulatingSets• Representation

– Widthw bitvectorrepresents subsetsof{0,…,w–1}– aj =1ifj� A

• 01101001 {0,3,5,6}• 76543210

• 01010101 {0,2,4,6}• 76543210

• Operations– &Intersection 01000001 {0,6}– |Union 01111101 {0,2,3,4,5,6}– ^Symmetricdifference 00111100 {2,3,4,5}– ~Complement 10101010 {1,3,5,7}

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

Bit-LevelOperations• Operations&,|,~,^

• Examples (Chardatatype)– ~0x41 ➙ 0xBE

• ~010000012 ➙ 101111102

– ~0x00 ➙ 0xFF• ~000000002 ➙ 111111112

– 0x69 & 0x55 ➙ 0x41• 011010012 & 010101012 ➙ 010000012

– 0x69 | 0x55 ➙ 0x7D• 011010012 | 010101012 ➙ 011111012

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

ShiftOperations• LeftShift: x << y– Shiftbit-vectorx lefty positions

– Throwawayextrabitsonleft• Fillwith0’sonright

• RightShift: x >> y– Shiftbit-vectorx righty positions

• Throwawayextrabitsonright– Logicalshift

• Fillwith0’sonleft– Arithmeticshift

• Replicatemostsignificantbitonright

• UndefinedBehavior– Shiftamount<0or≥wordsize

01100010Argument x

00010000<< 3

00011000Log. >> 2

00011000Arith. >> 2

10100010Argument x

00010000<< 3

00101000Log. >> 2

11101000Arith. >> 2

0001000000010000

0001100000011000

0001100000011000

00010000

00101000

11101000

00010000

00101000

11101000

Adoptedfrom:R.E.Bryant,D.R.O’Hallaron,G.Kesden

Today• Storedprogramcomputers

– Components ofacomputer– VonNeumannarchitecture

• ProgramsandData– Binarydatarepresentations– Bitoperations

• Programming languages(PLs)– Syntaxandsemantics– DimensionsofaPL– Programmingparadigms– ApartialhistoryofPLs

Page 12: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

ProgrammingLanguages• Anartificiallanguagedesigned toexpresscomputations thatcanbeperformed byamachine,particularlyacomputer.

• Canbeusedtocreateprograms thatcontrolthebehaviorofamachine, toexpressalgorithmsprecisely,orasamodeofhumancommunication.

• e.g.,C,C++,Java,Python,Prolog,Haskell,Scala,etc..

CreatingComputerPrograms• Eachprogramming languageprovidesasetofprimitiveoperations.

• Eachprogramming languageprovidesmechanismsforcombiningprimitivestoformmorecomplex,butlegal,expressions.

• Eachprogramming languageprovidesmechanismsfordeducingmeaningsorvaluesassociatedwithcomputationsorexpressions.

Slidecredit:E.Grimson,J.Guttag andC.Terman

AspectsofLanguages• Primitiveconstructs

– Programming language– numbers,strings,simpleoperators

– English– words

• Syntax– whichstringsofcharacters andsymbols arewell-formed– Programminglanguage–we’llgettospecificsshortly,butfor example3.2+3.2isavalidCexpression

– English– “catdog boy”is notsyntacticallyvalid, asnotinformofacceptablesentence

Slidecredit:E.Grimson,J.Guttag andC.Terman

AspectsofLanguages• Staticsemantics– whichsyntacticallyvalidstringshave a meaning

– English– “Iarebig”hasform<noun><intransitiveverb><noun>, sosyntacticallyvalid,butisnotvalidEnglishbecause“I”issingular,“are”isplural

– Programminglanguage– forexample,<literal><operator><literal> isavalidsyntacticform,but2.3/’abc’isastaticsemanticerror

Slidecredit:E.Grimson,J.Guttag andC.Terman

Page 13: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

AspectsofLanguages• Semantics– whatisthemeaningassociatedwithasyntacticallycorrectstringofsymbolswithnostaticsemanticerrors

– English– canbeambiguous• “Theysawthemanwiththetelescope.”

– Programming languages – alwayshasexactlyonemeaning• Butmeaning(orvalue)maynotbewhatprogrammerintended

Slidecredit:E.Grimson,J.Guttag andC.Terman

WhereCanThingsGoWrong?• Syntacticerrors

– Commonbuteasilycaughtbycomputer

• Staticsemanticerrors– Somelanguagescheckcarefullybeforerunning,otherscheck

whileinterpretingtheprogram– Ifnotcaught,behaviorofprogramunpredictable

• Programsdon’thavesemanticerrors,butmeaningmaynotbewhatwasintended– Crashes(stopsrunning)– Runsforever– Producesananswer,butnotprogrammer’s intent

Slidecredit:E.Grimson,J.Guttag andC.Terman

OurGoal• Learnthesyntaxandsemanticsofaprogramminglanguage

• Learnhowtousethoseelements totranslate“recipes” forsolvingaproblemintoaform thatthecomputer canusetodo theworkforus

• Computationalmodesofthoughtenableustouseasuiteofmethods tosolveproblems

Slidecredit:E.Grimson,J.Guttag andC.Terman

DimensionsofaProgrammingLanguage

• Low-levelvs.High-level

– Distinctionaccording tothelevelofabstraction

– Inlow-level programming languages(e.g.Assembly),thesetofinstructionsusedincomputationsareverysimple(nearlyatmachinelevel)

– Ahigh-level programming language(e.g.Python,C,Java)hasamuchricherandmorecomplexsetofprimitives.

Page 14: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

DimensionsofaProgrammingLanguage

• Generalvs.Targeted

– Distinctionaccordingtotherangeofapplications

– Inageneralprogramminglanguage,thesetofprimitivessupportabroadrangeofapplications.

– Atargetedprogramminglanguage aimsataveryspecificsetofapplications.• e.g.,MATLAB(matrixlaboratory) isaprogramminglanguagespecificallydesignedfornumericalcomputing(matrixandvectoroperations)

DimensionsofaProgrammingLanguage

• Interpretedvs.Compiled

– Distinctionaccordingtohowthesourcecodeisexecuted

– Ininterpreted languages(e.g.LISP),thesourcecodeisexecuteddirectlyatruntime(bytheinterpreter).• Interpretercontroltheflowoftheprogrambygoingthrougheachoneoftheinstructions.

– Incompiledlanguages(e.g.C),thesourcecodefirstneedstobetranslatedtoanobjectcode(bythecompiler)beforetheexecution.

ProgrammingLanguageParadigms• Functional

• Treatscomputationastheevaluationofmathematicalfunctions(e.g.Lisp,Scheme,Haskell,etc.)

• Imperative• Describescomputationintermsofstatementsthatchangeaprogramstate(e.g.FORTRAN,BASIC,Pascal,C,etc.)

• Logical(declarative)• Expresses thelogicofacomputationwithoutdescribingitscontrolflow(e.g.Prolog)

• Objectoriented• Uses"objects"– datastructuresconsistingofdatafieldsandmethodstogetherwiththeirinteractions– todesignapplicationsandcomputerprograms(e.g.C++,Java,C#,Python,etc.)

ProgrammingtheENIAC

Slidecredit:Ras Bodik

Page 15: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

ProgrammingtheENIAC

ENIACprogramforexternalballisticequations:

Slidecredit:Ras Bodik

ProgrammingtheENIAC• Programmingdoneby

– rewiringthe interconnections– tosetupdesiredformulas,etc.

• Problem(what’sthetediouspart?)– programming=rewiring– slow,error-prone

• Solution:– storetheprograminmemory!– birthofvonNeumannparadigm

Slidecredit:Ras Bodik

TheFirstAssembler• Assembler - acomputerprogramfortranslatingassembly

languageintoexecutablemachinecode– Example:ADD R1, R2, R3 0110000100100011

• TheEDSACprogrammingsystemwasbasedonasubroutinelibrary– commonlyusedfunctionsthatcouldbeusedtobuildallsortsofmore

complexprograms– thefirstversion,InitialOrders1,wasdevisedbyDavidWheeler, thena

researchstudent,in1949

• Teampublished“ThePreparationofProgramsforanElectronicDigitalComputer”– theonlyprogrammingtextbookthenavailable– computerstodaystilluseCambridgemodelforsubroutines library

Slidecredit:ThomasJ.Cortina

TheFirstCompiler• Acompiler isacomputerprogramthattranslatesa

computerprogramwritten inonecomputer language(thesource language)intoaprogramwritteninanothercomputer language(thetarget language).

– Typically,thetargetlanguageisassembly language– Assemblermaythentranslateassemblylanguageintomachine

code

• A-0isaprogramming languagefortheUNIVACIorII,usingthree-address codeinstructions forsolvingmathematicalproblems.

• A-0wasthefirstlanguageforwhichacompilerwasdeveloped.

Slidecredit:ThomasJ.Cortina

Page 16: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

TheFirstCompiler• A-0wasproducedbyGraceHopper'steamat

RemingtonRandin1952– GraceHopperhadpreviouslybeenaprogrammerfortheHarvard

Markmachines– OneofU.S.’sfirstprogrammers– ShefoundamothintheMarkI,whichwascausingerrors,andcalledit

acomputer“bug”

Slidecredit:ThomasJ.Cortina

FORTRAN(1957)• Firstsuccessfulhigh-levelprogramminglanguage

– Codemorereadableandunderstandablebyhumans– DevelopedbyJohnBachus atIBM– Standsfor:FORmula TRANslation– Starteddevelopmentin1954

• AkeygoalofFORTRANwasefficiency, althoughportabilitywasalsoakeyissue– automaticprogrammingthatwouldbeasgoodashumanprogrammingof

assemblycode• Programsthattookweeks towritecouldnowtakehours• 1961– FirstFORTRANprogrammingtextbook

– Universitiesbeganteachingitinundergradprograms• Providedstandardexchangeofprogramsdespitedifferentcomputers• Becamethestandardforscientificapplications

Slidecredit:ThomasJ.Cortina

FORTRANREAL SUM6,SUM7,SUM8,DIF6,DIF7,DIF8,SUMINFOPEN(6,FILE='PRN’)SUM6=.9*(1.-0.1**6)/0.9

SUM7=.9*(1.-0.1**7)/0.9SUM8=.9*(1.-0.1**8)/0.9

******COMPUTER SUM OF INFINITE TERMSSUMINF=0.9/(1.0-0.1)******COMPUTE DIFFERENCES BETWEEN FINITE & INFINITE SUMS

DIF6 = SUMINF - SUM6DIF7 = SUMINF - SUM7DIF8 = SUMINF - SUM8

WRITE(6,*) 'INFINITE SUM = ', SUMINFWRITE(6,*) 'SUM6 = ', SUM6, ' INFINITE SUM - SUM6 = ', DIF6WRITE(6,*) 'SUM7 = ', SUM7, ' INFINITE SUM - SUM7 = ', DIF7

WRITE(6,*) 'SUM8 = ', SUM8, ' INFINITE SUM - SUM8 = ', DIF8STOP

63Slidecredit:ThomasJ.Cortina

COBOL(1960)• Standsfor:CommonBusiness-OrientedLanguage• COBOLwasinitiallycreatedin1959(andreleasedin1960as

Cobol60)byagroupofcomputermanufacturersandgovernmentagencies

• OnegoalofCOBOL’sdesignwasforittobereadablebymanagers,sothesyntaxhadverymuchofanEnglish-likeflavor.– ThespecificationsweretoagreatextentinspiredbytheFLOW-MATIC

languageinventedbyGraceHopper

• Becamethestandardforbusinessapplications– Stillusedinbusinessapplicationstoday.

• 90%ofapplicationsovernext20yearswerewrittenineitherCOBOLorFORTRAN– OldprogrammerscameoutofhidingforY2K

Slidecredit:ThomasJ.Cortina

Page 17: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

COBOL000100 ID DIVISION.000200 PROGRAM-ID. ACCEPT1.000300 DATA DIVISION.000400 WORKING-STORAGE SECTION.000500 01 WS-FIRST-NUMBER PIC 9(3).000600 01 WS-SECOND-NUMBER PIC 9(3).000700 01 WS-TOTAL PIC ZZZ9.000800*000900 PROCEDURE DIVISION.001000 0000-MAINLINE.001100 DISPLAY 'ENTER A NUMBER: ’.001200 ACCEPT WS-FIRST-NUMBER.001300*001400 DISPLAY 'ANOTHER NUMBER: ’.001500 ACCEPT WS-SECOND-NUMBER.001600*001700 COMPUTE WS-TOTAL = WS-FIRST-NUMBER + WS-SECOND-NUMBER.001800 DISPLAY 'THE TOTAL IS: ', WS-TOTAL.001900 STOP RUN.

Slidecredit:ThomasJ.Cortina

Living&DeadLanguages• Hundredsofprogramming languagespoppedupinthe

1960s,mostquickly disappeared

• Somedead:– JOVIAL,SNOBOL,Simula-67,RPG,ALGOL,PL/1,andmany,many

more

• Somestillkicking:– LISP(1957)– BASIC(1964)– Pascal(1970)– Prolog(1972)– Andofcourse,C(1973)

Slidecredit:ThomasJ.Cortina

ALGOL-60(1960)

• CreatedmainlyinEuropebyacommitteeofcomputerscientists– JohnBackusandPeterNaur bothservedonthecommitteewhichcreatedit– DesiredanIBM-independent standard

• Standsfor:ALGOrithmic Language• Primarilyintendedtoprovideamechanismforexpressing

algorithmsuniformlyregardlessofhardware• ThefirstreportonAlgol wasissuedin1958,• Thelanguageitselfwasnotasuccess,butitwasaninfluenceon

othersuccessfullanguages– AprimaryancestorofPascalandC.

• Itintroducedblockstructure,compoundstatements,recursiveprocedurecalls,nested ifstatements, loops,andarbitrarylengthidentifiers

Slidecredit:ThomasJ.Cortina

LISP(1958)• DevelopedbyJohnMcCarthyatMIT

• Standsfor:LISt Processing – Designedforsymbolicprocessing– Introducedsymboliccomputationandautomaticmemorymanagement

• UsedextensivelyforArtificialIntelligenceapplications

Slidecredit:ThomasJ.Cortina

Page 18: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

BASIC(1964)

• CreatedbyJohnKemeny andThomasKurtzatDartmouthCollege

• Standsfor:Beginner'sAll-purposeSymbolic InstructionCode– oneofthefirstlanguagesdesignedforuseonatime-sharingsystem

– oneofthefirstlanguagesdesignedforbeginners

• Variants likeVisualBASICstillusedtodaybyMicrosoft.

Slidecredit:ThomasJ.Cortina

Prolog(1972)• CreatedbyAlainColmerauer andPhillipe Roussel oftheUniversityofAix-MarseilleandRobertKowalskioftheUniversityofEdinburgh

• Standsfor:PROgramming inLOGic.

• Prologistheleadinglogical programming language.– usedinartificialintelligenceprograms,computerlinguistics,andtheoremproving.

70Slidecredit:ThomasJ.Cortina

Prologparents(william, diana, charles). parents(henry, diana, charles). parents(charles, elizabeth, philip). parents(diana, frances, edward). parents(anne, elizabeth, philip). parents(andrew, elizabeth, philip). parents(edwardW, elizabeth, philip). married(diana, charles). married(elizabeth, philip). married(frances, edward). married(anne, mark). parent(C,M) <= parents(C,M,D). parent(C,D) <= parents(C,M,D). sibling(X,Y) <= parents(X,M,D) and parents(Y,M,D).

Slidecredit:ThomasJ.Cortina

C(1973)• Developed byKenThompsonandDennisRitchie

atAT&TBellLabsforuseontheUNIXoperatingsystem.– nowusedonpracticallyeveryoperatingsystem– popularlanguageforwritingsystemsoftware

• Features: – Anextremely simplecorelanguage,withnon-essential

functionalityprovidedbyastandardizedsetoflibraryroutines.– Low-levelaccesstocomputermemory viatheuseofpointers.

• Cancestors:C++,C#,Java

72Slidecredit:ThomasJ.Cortina

Page 19: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

C++(CwithClasses)• BjarneStroustrup beganworkonCwithClasses in1979,renamedC++in1982.– Developed atAT&TBellLaboratories. – AddedfeaturesofSimula toC.– Containedbasicobject-oriented features:

• classes(withdataencapsulation),derivedclasses,virtualfunctionsandoperatoroverloading

• In1989,release2.0addedmorefeatures: – multipleinheritance,abstractclasses,staticmemberfunctions,andprotectedmembers

• StandardTemplateLibrary(STL)officialin199573

Slidecredit:ThomasJ.Cortina

Java• CreatedbyPatrickNaughton andJamesGoslingatSunMicrosystems

– Originallydesignedforsmallconsumerdevices– Originalprojectcodename:Green– Mainfeature:Codeisgeneratedforavirtualmachinethatcanrunonanycomputerwithanappropriateinterpreter

– Originalnameofthelanguage:Oak

74Slidecredit:ThomasJ.Cortina

Python• CreatedbyGuidovanRossuminthelate1980s

• Allowsprogramming inmultipleparadigms:object-oriented,structured, functional

• Usesdynamictypingandgarbagecollection

Slidecredit:ThomasJ.Cortina

Summary• Storedprogramcomputers

– Componentsofacomputer– VonNeumannarchitecture

• ProgramsandData– Binarydatarepresentations– Bitoperations

• Programming languages(PLs)– Syntaxandsemantics– DimensionsofaPL– Programmingparadigms– ApartialhistoryofPLs

Page 20: Von Neumann architecture Computers Programs …bbm101/fall16/lectures/...The Von Neumann architecture Motherboard Layout (Intel 486) Slide credit: D. Stotts Motherboard Layout (Intel

NextWeek• IntroductiontoProgramming

– BasicConcepts– DevelopingAlgorithms– CreatingFlowcharts

• ThePythonProgrammingLanguage– YourfirstPythonProgram– ProgrammingProcess– LexicalElementsofaPythonProgram

TheStrangeBirthandLongLifeofUnix

• http://spectrum.ieee.org/computing/software/the-strange-birth-and-long-life-of-unix

Photo:Alcatel-Lucent