26
ICC Module 3 Lesson 1 – Computer Architecture 1 / 26 © 2015 Ph. Janson Information, Computing & Communication Computer Architecture Clip 1 – Assembler Language School of Computer Science & Communications P. Ienne (charts), Ph. Janson (commentary)

ICC Module 3 Lesson 1 – Computer Architecture 1 / 26 © 2015 Ph. Janson Information, Computing & Communication Computer Architecture Clip 1 – Assembler

Embed Size (px)

Citation preview

PowerPoint Presentation

Computer ArchitectureClip 1 Assembler LanguageSchool of Computer Science & CommunicationsP. Ienne (charts), Ph. Janson (commentary)

Information, Computing & CommunicationICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonThis video clip is part of the E.P.F.L. introductory course on Information, Computing, and Communication.It is the first in a set of video clips on computer architecture.

1OutlineClip 0 IntroductionClip 1 Software technology Assembler languageAlgorithmsRegistersData instructionsInstruction numberingControl instructionsClip 2 Hardware architecture Von Neumanns stored program computer architectureData storage and processingControl storage and processingClip 3 Hardware design Instruction encodingHarware implementation Transistor technologyClip 4 Computing circuitsClip 5 Memory circuitsHardware performanceClip 6 Logic parallelismClip 7 Architecture parallelismFirst clipPrevious clipNext clip

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonIt aims to explain the concept of a language called Assembler in which algorithms can be written so they can be understood by computers.2An algorithm Step 0An algorithm can be expressed in some intuitive language close to natural languagePeople can understand and even execute that but computers cannotSum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m s

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonThe algorithm depicted on this slide is expressed in an informal language that is intuitively understandable by people but not directly understandable by computers.It merely adds the first N integers and returns thir sum as the result.3Sum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m sSum of the n first integersInput : 3Output: ms 0as long as n > 0 s s + n n n 1m sExecution of this algorithm

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonA person can understand this algorithm at least well enough to be able to execute it or in other words simulate its behavior.We can for instance provide the integer 3 as input to the algorithm.4Sum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m sSum of the n first integersInput : 3Output: ms 0as long as 3 > 0 s 0 + 3 n 3 1m sExecution of this algorithm

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonIf we then execute (simulate) the algorithm, we see that it starts by comparing N (3) to 0, and since 3 is greater than 0, the algorithm first assigns the sum of S (0) and N (3) to S, which thus becomes 3, and second decrements N by one unit from 3 to 2.It then returns to the test comparing N to 0.5Sum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m sSum of the n first integersInput : 3Output: ms 0as long as 2 > 0 s 3 + 2 n 2 1m sExecution of this algorithm

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonThis time N equals 2, which is still greater than 0, so the algorithm executes again the same two operations, assigning to S the sum of itself (3) and N (2) and decrementing N by one more unit, from 2 to 1 before returning again to the initial test.6Sum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m sSum of the n first integersInput : 3Output: ms 0as long as 1 > 0 s 5 + 1 n 1 1m sExecution of this algorithm

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonThis time N equals 1, which is still greater than 0, so the algorithm executes once more the same two operations, assigning to S the sum of itself (5) and N (1) and decrementing N by one more unit, from 1 to 0 before returning to the initial test once more.

7Sum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m sSum of the n first integersInput : 3Output: ms 0as long as 0 > 0 s s + n n n 1m 6Execution of this algorithm

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonSince N is now null, the comparison to zero fails, so that the usual two operations are not executed once more.Instead the algorithm skips them and directly assigns the value of S (6) to M, the final result put out by the algorithm.8Sum of the n first integersInput : r1Output: r21: load r3, 02: cont_lte r1, 0, 63: add r3, r3, r14: add r1, r1, -15: cont 26: load r2, r3From algorithms to computers Step 1HardwareSoftware

Sum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m s

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonAs suggested earlier a computer is however unable to understand an algorithm in this intuitive but informal language.Computers need algorithms to be expressed in languages more formal and rigid to be able to understand them.9Sum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m sTo get to computers let us first rewrite the algorithmWe need to manipulatevalues such as s for instanceFor this purpose we restrict ourselves to variables such asr1, r2, r3,

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonSo let us try to be concrete and see what a computer would need to understand an algorithm.-First of all it would need to be able to manipulate the content of variables such as S and N.S and N are however meaningless names for a computer.Computers use so-called registers to record the values of variables as they evolve.And these registers are simply numbered r1, r2, r3, r4, etc.-So for computers to be able to understand algorithms, we write them so they use numbered registers instead of freely named variables.10Such variables are called registersThey are represented as r1, r2, r3,The names of all algorithm variables must be replaced by such register namesn r1m r2s r3Registers

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonFor computers, what people perceive as variables, are thus simply numbered registers.And to be executable on computers algorithms need to refer to such numbered registers rather than to any freely named variable.11Sum of the n first integersInput : r1Output: r2r3 0as long as r1 > 0 r3 r3 + r1 r1 r1 1r2 r3Sum of the n first integersInput : nOutput: ms 0as long as n > 0 s s + n n n 1m sStep 1.1

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonThis way, the rewritten algorithm now looks as the right side of this slide.12Sum of the n first integersInput : r1Output: r2r3 0as long as r1 > 0 r3 r3 + r1 r1 r1 1r2 r3Let us continue We need to assign values to these registersSo we write thatin a very regular way,for instance, load r3, 0to mean r3 0ouload r2, r3to mean r2 r3

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonThis is however not sufficient for a computer!-It must also be possible to tell a computer that it needs to assign to registers values of other registers or fixed values, called constants.-This is done by writing such assignment instructions in a very rigid way such as, for instance, load r3 with 0 or load r2 with the contents of r3.13Sum of the n first integersInput : r1Output: r2load r3, 0as long as r1 > 0 r3 r3 + r1 r1 r1 1load r2, r3Sum of the n first integersInput : r1Output: r2r3 0as long as r1 > 0 r3 r3 + r1 r1 r1 1r2 r3Step 1.2

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonGiven the previous conventional formalism, the original algorithm is rewritten as on the right side of this slide.14Sum of the n first integersInput : r1Output: r2r3 0as long as r1 > 0 r3 r3 + r1 r1 r1 1r2 r3Let us continue We need to perform arithmetic operations on these registersWe rewrite those also in a more regular way, for instance, add r3, r3, r1to mean r3 r3 + r1

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonBut again this is still not sufficient for a computer to be able to understand the whole algorithm.-The algorithm also includes arithmetic (or in general Boolean logic or other) operations that compute results based on the content of registers.- Such operations also need to be rewritten in a more rigid formalism similar to the previous load instructions.For instance add r3, r3, r1 can be used to mean recording into r3 the sum of r3 and r1.Similarly add r1, r1, -1 can be used to mean recording into r1 the sum of r1 and -1.(We could also have written sub r1, r1, 1 to mean subtracting 1 from r1 and recording the result into r1.)15Sum of the n first integersInput : r1Output: r2load r3, 0as long as r1 > 0 add r3, r3, r1 add r1, r1, -1load r2, r3Sum of the n first integersInput : r1Output: r2r3 0as long as r1 > 0 r3 r3 + r1 r1 r1 1r2 r3Step 1.3

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonWith this new conventional formalism, the original algorithm is rewritten as on the right side of this slide.16Sum of the n first integersInput : r1Output: r2r3 0as long as r1 > 0 r3 r3 + r1 r1 r1 1r2 r3Let us continue

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonSo now we know how to instruct a computer to assign or compute values for registers.However we still do not have a formalism to tell a computer that it needs to react to certain logical tests.17Sum of the n first integersInput : r1Output: r2load r3, 0if r1 0 r3 r3 + r1 r1 r1 1r2 r3Watch out: a somewhat contorted transformation!

ICC Module 3 Lesson 1 Computer Architecture# / 26 2015 Ph. JansonOn the way to enriching our language to express such condition testing we first need to rewrite our algorithm in a somewhat contorted way.In effect our condition testing means that if the condition is not met, the computer should skip straight to the final load instruction.Otherwise it should execute the two arithmetic additions and then retest the condition as long as it holds.18To enable that let us introduce line numbersWe need to be able to specify targets for thesecontinue thereInstead of arrows we use line numbers, for instance, 1:, 2:, 3:Sum of the n first integersInput : r1Output: r2load r3, 0if r1