Lec #8: Analysis of Algorithms (Part 2) + Assembly Language

Total Page:16

File Type:pdf, Size:1020Kb

Lec #8: Analysis of Algorithms (Part 2) + Assembly Language Lec #8: Analysis of Algorithms (part 2) + Assembly Language 1 Analysis of Algorithms (part 2) (45 min) ◮ Quick review from last time ◮ Generating best and worst case expressions for insertion sort. ◮ Take away message (for now) 2 Assembly Language (45 min) ◮ What is a computer? ◮ NIC and NAS ◮ Examples Quick review of Algorithms ◮ Computational problem/algorithms/instances ◮ Running examples: ◮ Finding a maximum element in an array of n integers ◮ Finding the index of string (if it exists) in a sorted array of n strings ◮ Sorting an array of n numbers from least to greatest. ◮ “Finding the visible buildings in a row” ◮ Correctness/efficiency ◮ general cost: T(n) ◮ best case cost: B(n) ◮ worst case cost: W(n) Analyzing Insertion Sort Let us look at the analysis of insertion sort in Cormen, et. al. Best and Worst Time Complexity for Insertion Sort B(n)= W(n)= Big-O Let T (n) and f (n) be positive functions. When we write T (n)= O(f (n)) we say that T (n) is ’ordo’ f (n). This means there exists the positive constants c and n0 such that T (n) ≤ c · f (n) for all n > n0. Let’s do an example: T (n)= .5(n2) + 200(n + 6) ◮ is T (n)= O(n)? (No!) ◮ is T (n)= O(n2)? (Yes!) ◮ is T (n)= O(n3)? (Yes!) Let’s show why exactly! Big-Ω Let T (n) and f (n) be positive functions. When we write T (n)=Ω(f (n)) we say that T (n) is ’omega’ f (n). This means there exists the positive constants c and n0 such that T (n) ≥ c · f (n) for all n > n0. Big-Θ When we write T (n)= θ(f (n)) we say that T (n) is ’theta’ f (n) which means T (n)= O(f (n)) and T (n)=Ω(f (n)) Monotonicity A function f (n) is monotonically increasing if n ≤ m implies f (n) ≤ f (m). We are almost always analyzing cost functions that are monotonically increasing. Take away message ◮ Can apply asymptotic analysis to closed formulas, best or worst case algorithm runs, any algorithm run and even problems. ◮ Doing actual cost calculation for algorithm can be tedious (but in certain cases pays off) ◮ Not all algorithms have a function f (n) where T (n)=Θ(f (n)) ◮ We have not seen algorithms where T (n) has log terms yet, but we will. (Time permitting, a discussion of Binary Search). What is a computer? ◮ the Analytic Engine (Babbage, 1837) ◮ Z3 (Zuse, 1941) ◮ Manchester Baby (1948) CPU + Memory NIC ◮ a simulator (nic) ◮ big endian ◮ 2-byte words, 4-bit bytes ◮ 16 2-byte registers ◮ a fixed 4-byte instruction format ◮ words align on 2-byte boundaries ◮ instructions align on 4-byte boundaries ◮ integers in two’s complement format ◮ an assembler (nas) Assembly Language Instruction Set for NIC Instr Code Operands Description halt 0 000 Halt execution. load 1 rxy Load register r with the bit pattern found in the memory cell whose address is xy. loadc 2 rxy Load register r with bit pattern xy. loadr 3 0st Load register s with the bit pattern found in the memory cell whose address is stored in register t. store 4 rxy Store the bit pattern found in register r in the memory cell whose address is xy. storer 5 0st Store the bit pattern found in register s in the memory cell whose address is stored in register t. move 6 0st Copies the bit pattern found in register s to register t. Instruction Set for NIC (part 2) add 7 rst Add the integers in registers s and t and place the result in register r. addc 8 rxy Add the integer xy to register r. mul 9 rst Multiply the integers in registers s and t and place the result in register r. sub a rst Subtract the integer in register t from the integer in register s and place the result in register r. shift b rst Shift the bit pattern in register s the number of positions given by the integer stored in t and place the result in register r. Positive integers shift to the right, negative to the left. and c rst Do a bit-wise logical and on the patterns in registers s and t and place the result in register r. or d rst Do a bit-wise logical or on the patterns in registers s and t and place the result in register r. xor e rst Do a bit-wise logical xor on the patterns in registers s and t and place the result in register r. Instruction Set for NIC (part 3) jump f 0xy Jump to the instruction in memory cell xy. jumpe f rxy Jump to the instruction in the memory cell at address xy if the bit pattern in register r is equal to the bit pattern in register r0. jumpn f rxy+01b Jump to the instruction in the memory cell at address xy if the bit pattern in register r is not equal to the bit pattern in register r0. jumpl f rxy+10b Jump to the instruction in the memory cell at address xy if the integer in register r is less than the integer in register r0. jumple f rxy+11b Jump to the instruction in the memory cell at address xy if the integer in register r is less than or equal to the integer in register r0. noop f 001 Do nothing. An Example Assembly code (in loop.as) // Writes ff, fe, ..., 2, 1, 0 to memory at address n. word n loadc r0 -1 loadc r1 -1 Loop: store r1 n // write r1 to memory address n addc r1 -1 // r1-- jumpn r1 Loop // if r1 != -1 goto Loop n is set to the address immediately at the end of address space of the program. Binary representation (in loop.bi) 1f1f1f1f20ff21ff411c81fff1090000f00000 Let’s grind this example! Contact (Sagan, 1996): Operating somewhere in the Vega System Assembly Code // beats out the primes on register 9 loadc r3 n loadc r0 0 word n loadr r1 r3 Oloop: noop repeat: loadc r2 2 Loop: addc r1 -1 // r1-- store r2 n loadc r9 0 loadc r2 3 loadc r9 -1 // Thump! store r2 n+2 loadc r9 0 loadc r2 5 jumpn r1 Loop // if r1 != -1 goto Loop store r2 n+4 loadc r2 7 noop store r2 n+6 noop loadc r2 11 noop store r2 n+8 noop loadc r2 13 noop store r2 n+10 noop loadc r2 17 store r2 n+12 addc r3 2 loadc r2 19 loadr r1 r3 store r2 n+14 jumpn r1 Oloop loadc r2 23 jump repeat store r2 n+16 ... Darn only the first 18 primes... we need the first 26. could we do better?.
Recommended publications
  • The Manchester University "Baby" Computer and Its Derivatives, 1948 – 1951”
    Expert Report on Proposed Milestone “The Manchester University "Baby" Computer and its Derivatives, 1948 – 1951” Thomas Haigh. University of Wisconsin—Milwaukee & Siegen University March 10, 2021 Version of citation being responded to: The Manchester University "Baby" Computer and its Derivatives, 1948 - 1951 At this site on 21 June 1948 the “Baby” became the first computer to execute a program stored in addressable read-write electronic memory. “Baby” validated the widely used Williams- Kilburn Tube random-access memories and led to the 1949 Manchester Mark I which pioneered index registers. In February 1951, Ferranti Ltd's commercial Mark I became the first electronic computer marketed as a standard product ever delivered to a customer. 1: Evaluation of Citation The final wording is the result of several rounds of back and forth exchange of proposed drafts with the proposers, mediated by Brian Berg. During this process the citation text became, from my viewpoint at least, far more precise and historically reliable. The current version identifies several distinct contributions made by three related machines: the 1948 “Baby” (known officially as the Small Scale Experimental Machine or SSEM), a minimal prototype computer which ran test programs to prove the viability of the Manchester Mark 1, a full‐scale computer completed in 1949 that was fully designed and approved only after the success of the “Baby” and in turn served as a prototype of the Ferranti Mark 1, a commercial refinement of the Manchester Mark 1 of which I believe 9 copies were sold. The 1951 date refers to the delivery of the first of these, to Manchester University as a replacement for its home‐built Mark 1.
    [Show full text]
  • 1. Types of Computers Contents
    1. Types of Computers Contents 1 Classes of computers 1 1.1 Classes by size ............................................. 1 1.1.1 Microcomputers (personal computers) ............................ 1 1.1.2 Minicomputers (midrange computers) ............................ 1 1.1.3 Mainframe computers ..................................... 1 1.1.4 Supercomputers ........................................ 1 1.2 Classes by function .......................................... 2 1.2.1 Servers ............................................ 2 1.2.2 Workstations ......................................... 2 1.2.3 Information appliances .................................... 2 1.2.4 Embedded computers ..................................... 2 1.3 See also ................................................ 2 1.4 References .............................................. 2 1.5 External links ............................................. 2 2 List of computer size categories 3 2.1 Supercomputers ............................................ 3 2.2 Mainframe computers ........................................ 3 2.3 Minicomputers ............................................ 3 2.4 Microcomputers ........................................... 3 2.5 Mobile computers ........................................... 3 2.6 Others ................................................. 4 2.7 Distinctive marks ........................................... 4 2.8 Categories ............................................... 4 2.9 See also ................................................ 4 2.10 References
    [Show full text]
  • CLUE Rock, Paper, Scissors Game Using Bluetooth Created by Kevin Walters
    CLUE Rock, Paper, Scissors Game using Bluetooth Created by Kevin Walters Last updated on 2021-07-28 03:42:04 PM EDT Guide Contents Guide Contents 2 Overview 4 Parts 4 CLUE 4 Circuit Playground Bluefruit with TFT Gizmo 5 Design 6 Rules 6 More than Two Players 6 Flow Diagram 7 User Interface 8 User Interface 8 Choice selection 8 Display on NeoPixels 9 Screens 9 Screen Transitions 10 Sprites 10 TFT Gizmo Detection 12 The Challenge of Detecting the TFT Gizmo 12 Exchanging Choices 14 Cheating 14 Simultaneous Exchange of Player Choices 15 First Idea 15 Third Idea 16 Fourth Idea 16 Fifth Idea 17 Identity and Authentication 18 Networking 19 Connection-oriented and Connection-less Communication 19 Custom Advertisement Packets using ManufacturerData 20 Simple Game 21 Advanced Game 22 Making the List of Players 22 Exchanging Data between Players 23 Scores 26 Multi-player Scoring 26 Score Table Presentation 26 CircuitPython on CLUE 27 Set up CircuitPython Quick Start! 27 CircuitPython on Circuit Playground Bluefruit 29 Install or Update CircuitPython 29 CircuitPython 31 Libraries 31 Libraries for Very Simple Game 31 Libraries for Simple Game 31 Libraries for Advanced Game for CLUE 31 Libraries for Advanced Game for Circuit Playground Bluefruit with TFT Gizmo 32 Libraries for Advanced Game for Circuit Playground Bluefruit only 32 Development Testing 33 Very Simple Game 34 Installation 34 Code 35 Code Discussion 36 Evolving the Game and some History 36 Simple Game 38 © Adafruit Industries https://learn.adafruit.com/rock-paper-scissors-circuitpython
    [Show full text]
  • De-Mythologising the Early History of Modern British Computing. David Anderson
    Contested Histories: De-Mythologising the Early History of Modern British Computing. David Anderson To cite this version: David Anderson. Contested Histories: De-Mythologising the Early History of Modern British Com- puting.. IFIP WG 9.7 International Conference on History of Computing (HC) / Held as Part of World Computer Congress (WCC), Sep 2010, Brisbane, Australia. pp.58-67, 10.1007/978-3-642-15199-6_7. hal-01059593 HAL Id: hal-01059593 https://hal.inria.fr/hal-01059593 Submitted on 1 Sep 2014 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Distributed under a Creative Commons Attribution| 4.0 International License Contested Histories: De-Mythologising the Early History of Modern British Computing. David Anderson University of Portsmouth, “The Newmanry”, 36-40 Middle Street, Portsmouth, Hants, United Kindom, PO5 4BT Abstract A challenge is presented to the usual account of the development of the Manchester Baby which focuses on the contribution made to the project by the topologist M.H.A. (Max) Newman and other members of the Dept. of Mathematics. Based on an extensive re-examination of the primary source material, it is suggested that a very much more significant role was played by mathematicians than is allowed for in the dominant discourse.
    [Show full text]
  • ALAN TURING: and the TUTORIAL MANCHESTER MARK I Program the Post-War Machine Used for Early Computer Music, JULIET KEMP Chess and Proto-Artificial Intelligence
    CODING MANCHESTER MARK I ALAN TURING: AND THE TUTORIAL MANCHESTER MARK I Program the post-war machine used for early computer music, JULIET KEMP chess and proto-artificial intelligence. lan Turing’s work at GCHQ with Colossus WHY DO THIS? during WWII is well-known, as of course is the • Take a trip back to the Turing Test, but those were far from his only 1940s A involvements with early computing developments. In • Search for large prime numbers (very slowly) the late 1940s he was working on designing a • Use the logic that first stored-program computer (Colossus couldn’t store inspired the Turing Test programs, and in any case was still very secret), and in 1948 moved to Manchester where the Manchester Baby and Manchester Mark I were being developed. The Manchester Baby (aka the Manchester Small Scale Experimental Machine) wasn’t a full general- purpose computer, but a small-scale test of Williams tube memory (cathode ray memory, using the charge well created by drawing a dot or dash on the tube). However, it is considered to be the world’s first stored-program computer, running its first program on 21 June 1948, when it found the highest proper divisor of 2^18 (262,144), and took 52 minutes to run. Only two more programs were written for it: an amended One of Turing’s projects while working on the Mark I was version of this, and a program written by Turing to to write code to investigate the Riemann hypothesis, carry out long division. which has to do with the distribution of prime numbers.
    [Show full text]
  • World War II and the Advent of Modern Computing Based on Slides Originally Published by Thomas J
    15-292 History of Computing World War II and the Advent of Modern Computing ! Based on slides originally published by Thomas J. Cortina in 2004 for a course at Stony Brook University. Revised in 2013 by Thomas J. Cortina for a computing history course at Carnegie Mellon University. WW II l At start of WW II (1939) l US Military was much smaller than Axis powers l German military had best technology l particularly by the time US entered war in 1941 l US had the great industrial potential l twice the steel production as any other nation, for example ! l A military and scientific war l Outcome was determined by technological developments l atomic bomb, advances in aircraft, radar, code-breaking computers, and many other technologies Konrad Zuse l German Engineer l Z1 – built prototype 1936-1938 in his parents living room l did binary arithmetic l had 64 word memory l Z2 computer had more advances, called by some first fully functioning electro-mechanical computer l convinced German government to fund Z3 l Z3 funded and used by German’s Aircraft Institute, completed 1941 l Z1 – Z3 were electromechanical computers destroyed in WWII, not rebuilt until years later l Z3 was a stored-program computer (like Von Neumann computer) l never could convince the Nazis to put his computer to good use l Zuse smuggled his Z4 to the safety of Switzerland in a military truck l The accelerated pace of Western technological advances and the destruction of German infrastructure left Zuse behind George Stibitz l Electrical Engineer at Bell Labs l In 1937, constructed
    [Show full text]
  • Was the Manchester Baby Conceived at Bletchley Park?
    Was the Manchester Baby conceived at Bletchley Park? David Anderson1 School of Computing, University of Portsmouth, Portsmouth, PO1 3HE, UK This paper is based on a talk given at the Turing 2004 conference held at the University of Manchester on the 5th June 2004. It is published by the British Computer Society on http://www.bcs.org/ewics. It was submitted in December 2005; final corrections were made and references added for publication in November 2007. Preamble In what follows, I look, in a very general way, at a particularly interesting half century, in the history of computation. The central purpose will be to throw light on how computing activity at the University of Manchester developed in the immediate post-war years and, in the context of this conference, to situate Alan Turing in the Manchester landscape. One of the main methodological premises on which I will depend is that the history of technology is, at heart, the history of people. No historically-sophisticated understanding of the development of the computer is possible in the absence of an appreciation of the background, motivation and aspirations of the principal actors. The life and work of Alan Turing is the central focus of this conference but, in the Manchester context, it is also important that attention be paid to F.C. Williams, T. Kilburn and M.H.A. Newman. The Origins of Computing in Pre-war Cambridge David Hilbert's talk at the Sorbonne on the morning of the 8th August 1900 in which he proposed twenty-three "future problems", effectively set the agenda for mathematics research in the 20th century.
    [Show full text]
  • Test Yourself (Quiz 1)
    Test Yourself (Quiz 1) 1. Explain the significance of the ABC computer. 2. Explain the main features of Agile including scrum and sprints. 3. Explain the significance of the Apple Macintosh. What are Apple’s key innovations? 4. Describe Gene Amdahl’s contributions to IBM and the Amdahl Corporation. 5. Describe the components of the Analytic Engine, and explain their function. 6. Explain why Lady Ada Lovelace is considered the world’s first programmer. 7. Discuss the significance of the Difference Engine. 8. Describe the Turing test. Is it an appropriate test of machine intelligence? 9. Describe Searle’s Chinese room thought experiment, and discuss whether it is an effective rebuttal of machine intelligence. 10. Discuss the significance of Atari in the history of computing. 11. Explain binary numbers and their importance in the computing field. 12. Explain why Shannon’s Master’s thesis is a key milestone in computing. 13. Describe how Boolean logic may be employed in the design of digital circuits. 14. Explain the importance of Boole’s equation x2 = x as a fundamental law of thought. 15. Discuss the similarities and differences between C and C++. 16. Explain cloud computing and distributed computing. 17. What is the CMMI? 18. Explain why Watt Humphrey is known as the father of software quality. 19. Describe Flower’s work on the Colossus computer at Bletchley Park and how the machine was used to crack the Lorenz codes. 20. Describe Grace Murray Hopper’s contribution to the COBOL programming language. 21. What is a compiler? Explain the various parts of a compiler.
    [Show full text]
  • At Grange Farm the COMPUTER – the 20Th Century’S Legacy to the Next Millennium
    Computer Commemoration At Grange Farm THE COMPUTER – the 20th century’s legacy to the next millennium. This monument commemorates the early pioneers responsible for the development of machines that led to, or indeed were, the first electronic digital computers. This spot was chosen because the COLOSSUS, the first effective, operational, automatic, electronic, digital computer, was constructed by the Post Office Research Station at Dollis Hill (now BT research), whose research and development later moved from that site to Martlesham, just east of here and the landowners thought this would be a suitable setting to commemorate this achievement. The story of these machines has nothing to do with the names and companies that we associate with computers today. Indeed the originators of the computer are largely unknown, and their achievement little recorded. All the more worth recording is that this first machine accomplished a task perhaps as important as that entrusted to any computer since. The electronic digital computer is one of the greatest legacies the 20th century leaves to the 21st. The History of Computing… The shape of the monument is designed to reflect a fundamental concept in mathematics. This is explained in the frame entitled “The Monument”. You will notice that some of the Stations are blue and some are orange. Blue stations talk about concepts and ideas pertinent to the development of the computer, and orange ones talk about actual machines and the events surrounding them. The monument was designed and funded by a grant making charity. FUNDAMENTAL FEATURES OF COMPUTERS The computer is now so sophisticated that attention is not normally drawn to its fundamental characteristics.
    [Show full text]
  • Computer Design
    Computer Design Computer Laboratory Part Ib in Computer Science Copyright c Simon Moore, University of Cambridge, Computer Laboratory, 2011 Contents: • 17 lectures of the Computer Design course • Paper on Chuck Thacker’s Tiny Computer 3 • White paper on networks-on-chip for FPGAs • Exercises for supervisions and personal study • SystemVerilog “cheat” sheet which briefly covers much of what was learnt using the Cam- bridge SystemVerilog web tutor Historic note: this course has had many guises. Until last year the course was in two parts: ECAD and Computer Design. Past paper questions on ECAD are still mostly relevant though there has been a steady move toward SystemVerilog rather than Verilog 2001. This year the ECAD+Arch labs have been completely rewritten for the new tPad hardware and making use of Chuck Thacker’s Tiny Computer 3 (TTC). The TTC is being used instead of our Tiger MIPS core since it is simple enough to be easily altered/upgraded as a lab. exercise. As a conse- quence some of the MIPS material has been removed in favour of a broader introduction to RISC processors; and the Manchester Baby Machine in SystemVerilog has been replaced by an introduction to the TTC and its SystemVerilog implementation. A new lecture on system’s design on FPGA using Altera’s Qsys tool has been added. Lecture 1— Introduction and Motivation 1 Computer Design — Lecture 1 Revising State Machinesy 5 Introduction and Motivationy 1 Then do Boolean minimisation, e.g. using K-maps Overview of the course How to build a computer: 4 × lectures introducing Electronic Computer Aided Design (ECAD) and the Verilog/SystemVerilog language Cambridge SystemVerilog web tutor (home work + 1 lab.
    [Show full text]
  • Manchester Baby Simulator User Guide
    Manchester Baby Simulator User Guide By David Sharp The University of Warwick 11th January 2001 Freddie Williams and Tom Kilburn in front of the Baby or one of it’s close descendants. Historical background The Manchester Baby (also known as the Small Scale Experimental Machine) was the first working stored-program computer. That is a computer which stores and executes its program from an electronic storage device rather than for example reading it from a punched tape. It was built at the University of Manchester by Tom Kilburn, Freddie Williams and Geoff Tootill, successfully running its first program on June 21st 1948. All three of the team had previously worked with radar technology at the Telecommunications Research Establishment (TRE) in Malvern and this had led the team to working with cathode ray tubes (CRT). Williams had visited the ENIAC project at the University of Pennsylvania in 1946 also reading the EDVAC report. He took away the stored-program concept as well as the need for a large high-speed electronic storage device, for which he saw CRTs as a prime candidate. The primary purpose of the Baby was to test the ideas of Williams and Kilburn of using a CRT as a data storage device for a computer. Although they could store data on a CRT for long periods of time, this wasn’t evidence of its suitability for a computer where the data was constantly changing at high speed and hence they had to build a computer to test it. To this end, Kilburn designed, “the smallest computer which was a true computer (that is a stored program computer) which [he] could devise”1.
    [Show full text]
  • History of Computers. Reload
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Kazan Federal University Digital Repository Н Н Н .Н. .. ..я HISTORY OF COMPUTERS. RELOAD. , 2017 1 811.111 81.2 15 Р - И ых , К ( № 2 29 2017 .) : . , Н .. , . .Н. 15 History of computers. Reload.: / .., .., .. – : - . -, 2017. – 117 . . Pre-Intermediate Intermediate , , cc . , . , . , . 811.111 81.2 © .Н., 2017 © , 2017 2 Content Introduction ............................................................................................................ 4 Introductory unit. Generations of computers ......................................................... 5 Introductory quiz .................................................................................................... 12 Module 1. Zero generation computers ................................................................... 15 Unit 1. Early computing machines ......................................................................... 15 Unit 2. First freely programmable computer .......................................................... 24 Unit 3. The Atanasoff-Berry computer – the first electronic computer ................. 32 Module 2. First generation computers .................................................................... 39 Unit 4. The Harvard MARK I computer ................................................................ 40 Unit 5. The ENIAC I computer
    [Show full text]