CSE 305 Introduc0on to Programming Languages Lecture 3 CSE @ SUNY-­‐Buffalo Zhi Yang Courtesy of Google Subtrac0on • The Sumerians lived in Mesopotamia. This region of fer0le plains between the Tigris and the Euphrates is now mostly in modern Iraq. Here the Sumerians built the first advanced civilisa0on in great ci0es with administra0ons, legal systems and irriga0on. They developed methods of wri0ng and coun0ng -­‐ in base 60(Courtesy of . Wikipedia) • In around 2300 BC, the Sumerians were invaded by the Akkadians. Between them, they invented theabacus and a basic arithme0c with addi0on, subtrac0on and versions of mul0plica0on and division. The Sumerians were displaced by the Babylonians in around 2000 BC. But they passed on their systems of coun0ng and arithme0c. Nega0ve Number and Concept of Merging Among the earliest people to use nega0ve numbers in calcula0ons were the ancient Chinese. They used coun0ng rods to perform calcula0ons, with red rods for posi0ve numbers and black rods for nega0ve numbers. The example below shows some Chinese numerals represented by rods, and the diagram on the right shows which numbers these symbols represent. (Courtesy of Jill Howard) Merging a posi0ve number and a nega0ve number gives you the remainder at each unit in posi0onal system. Sorry, I am lazy again~~~ • 1) We can do subtrac0on using tradi0onal ripple borrowing way ~~~ • 2) But we could do it faster ~~~ 2-­‐base One s Complement Number • Defini0on: The ones' complement of a binary number is defined as the value obtained by inver0ng all the bits in the binary representa0on of the number (swapping 0's for 1's and vice-­‐versa). • Theory behind it: in binary format, a number posi0ve number A has n bits, invert(A) + A + 1 = 1(0….0) = C n • So A’s one’s-­‐complement = invert(A), then: – A = invert(A) + 1 -­‐ C = one’s-­‐complement(A) – C + 1 and B – A = B +one’s-­‐complement(A) + 1 – C (* formula 1) 2-­‐Base Two s Complement Number • In two's-­‐complement representa0on, nega0ve numbers are represented by the two's complement of their absolute value. • Recall A’s one’s-­‐complement = invert(A), then: – A = invert(A) + 1 -­‐ C = one’s-­‐complement(A) – C + 1 and B – A = B+ one’s-­‐complement(A) + 1 – C (* formula 1) • Now we have: A’s two’s-­‐complement=invert(A)+1 So: – A = invert(A)+1-­‐C = two’s-­‐complement(A) – C B – A = B+ two’s-­‐complement(A) – C (* formula 2) Can we generalize this idea? • Yes, we can generalize to the idea to any posi0ve integer based radix number easily ~~~ One’s Complement Computer UNIVAC 1100/80 IBM 7090 CDC 6000 Two s Complement Computer Sumsung Chrome book IBM mainframe Apple iphone Microson Xbox Mul0plica0on Division We have every thing at hand, except that ~~~ Well, how should we input and store data? Punch Card(Hollerith Card) Punch Card(BCD) Reading Cards Wait, what is the rela0on between a punch card and current computer system • Yes, You are right, punch card itself is a media used as input and also output of compu0ng system. In this sense, it can be reused by the compu0ng device ~~~ (if you know how to find the punch card you just output ~~~) • So it is to be used: To tell computer what result need to output ~~~ Ques0on: what if it is used to tell computer where to find the card and input again? ~~~ Can we generalize the idea Chapter 5 The Processor: Datapath and Control • An example from MIPS Field Bit positions a. Bit positions rt rd shamt funct 31:26 25:21 20:16 15:11 10:6 5:0 35 or 43 rs rt address 31:26 25:21 20:16 15:0 Load or store instruction Field Bit positions c. rs R-type instruction Field b. 0 4 rs rt address 31:26 25:21 20:16 15:0 Branch instruction FIGURE 5.14 The three instruction classes (R-type, load and store, and branch) use two different instruction formats. The jump instructions use another format, which we will discuss shortly. (a) Instruction format for R-format instructions, which all have an opcode of 0. These instructions have three register operands: rs, rt, and rd. Fields rs and rt are sources, and rd is the destination. The ALU function is in the funct field and is decoded by the ALU control design in the previous section. The R-type instructions that we implement are add, sub, and, or, and slt. The shamt field is used only for shifts; we will ignore it in this chapter. (b) Instruction format for load (opcode = 35ten) and store (opcode = 43ten) instructions. The register rs is the base register that is added to the 16-bit address field to form the memory address. For loads, rt is the destination register for the loaded value. For stores, rt is the source register whose value should be stored into memory. (c) Instruction format for branch equal (opcode = 4). The registers rs and rt are the source registers that are compared for equality. The 16-bit address field is signextended, shifted, and added to the PC to compute the branch target address. Why MIPS instruc0on tell computer to find data outside current Central Processing Unit(CPU) ? • The reasons for that, are usually not technical concerns ~~~ Speak of Storage System, except for punch card, what else ? ~~~ Record Format FIGURE 12.1 (a) Illustration of the recording and reproducing process. (b) Schematic of cro showing the magnetic field at the gap. disk) against a stationary or rotatory read/write head. The one track example is given The medium is in the form of a magnetic layer supported on a nonmagnetic substrate or the reproducing head is a ring-shaped electromagnet with a gap at the surface facin When the head is fed with a current representing the signal to be recorded, the fringin gap magnetizes the medium as shown in Figure 12.1b. For a constant medium velo variations in remanent magnetization along the length of the medium reflect the tempo the head current, and constitute a recording of the signal. The recording magnetization creates a pattern of external and internal fields, in the s a series of contiguous bar magnets. When the recorded medium is passed over the s reproducing head of similar construction, the flux emanating from the medium surfac by the head core, and a voltage is induced in the coil proportional to the rate of change Tape Transpor0ng Mechanism Floopy Disk In 1971, IBM introduced the 8-­‐inch floppy disk, ini0al capacity was about 100K bytes (100,000 characters) In 1976, Shugart introduced the 5 1/4-­‐ inch floppy disk. Ini0al capacity was about 100K, eventually reaching 1.2M bytes per disk. In 1980, Sony introduced the 3 1/2-­‐inch floppy disk. Ini0ally holding about 400K, current capacity is 1.4Meg per disk. Various Format of Floopy Disk IBM 8-­‐inch single side 128 bytes/sector 26 sectors/track 74 tracks/side Apple II 5¼ inch floppy disk, 35 tracks, 16 sectors per track 2 sides, 256 bytes per sector Apple Macintosh 3.5-­‐inch floppy disk, there are 80 tracks 18 sectors per track 512 bytes per sector Hard Disks 3148 cylinders 8 heads 63 sectors/track 512 bytes/sector Western Digital AC31600 EIDE hard disk Figure 1. Disk structures: (A) Track (B) Geometrical sector (C) Track sector (D) Cluster (BTW) really works? • hwps://www.youtube.com/watch?v=oaVwzYN6BP4 Why Punch Cards? ~~~ • hwps://www.youtube.com/watch?v=-­‐ReL9JnWA1A • hwps://www.youtube.com/watch?v=1APZ5-­‐cjWfw