Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng

Size: px
Start display at page:

Download "Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng"

Transcription

1 Slide Set 5 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014

2 ENCM 369 W14 Section 01 Slide Set 5 slide 2/68 Contents A Few Remarks about Chapter 6 Material Bit Patterns and Integers Addition of Unsigned and Signed Integers Subtraction of Unsigned and Signed Integers Instructions used by C and C++ compilers for integer addition and subtraction

3 ENCM 369 W14 Section 01 Slide Set 5 slide 3/68 Outline of Slide Set 5 A Few Remarks about Chapter 6 Material Bit Patterns and Integers Addition of Unsigned and Signed Integers Subtraction of Unsigned and Signed Integers Instructions used by C and C++ compilers for integer addition and subtraction

4 ENCM 369 W14 Section 01 Slide Set 5 slide 4/68 A Few Remarks about Chapter 6 Material remarks on assembly language programming remarks on Sections 6.7 and 6.8

5 ENCM 369 W14 Section 01 Slide Set 5 slide 5/68 Concluding remarks about assembly language programming Humans are usually much more productive writing code in high-level languages. (But some people thinking writing A.L. code is fun. Really.) Today the main use of A.L. is as an intermediate format in automatic translation of high-level language code A.L. is the output of a compiler and the input to an assembler. Students learn A.L. because it helps them learn how computer systems work.

6 ENCM 369 W14 Section 01 Slide Set 5 slide 6/68 Textbook Sections 6.7 and : Pseudoinstructions. We ve already covered this : Exceptions. We ll look at this topic in detail later in the course : Signed and unsigned instructions. We ll learn about these as we progress through this slide set : Floating-point instructions. We ll look at MIPS floating-point instructions near the end of the course, after we cover floating-point number formats. 6.8: x86 architecture. This is interesting but not ENCM 369 material.

7 ENCM 369 W14 Section 01 Slide Set 5 slide 7/68 Outline of Slide Set 5 A Few Remarks about Chapter 6 Material Bit Patterns and Integers Addition of Unsigned and Signed Integers Subtraction of Unsigned and Signed Integers Instructions used by C and C++ compilers for integer addition and subtraction

8 ENCM 369 W14 Section 01 Slide Set 5 slide 8/68 Bit Patterns, Signed and Unsigned Integers Really important definitions: signed and unsigned integer types. Signed: a type with negative, zero, and positive values. Signed does NOT mean negative, it means might be negative. Do NOT say 5 is signed but +5 is unsigned. Both can be numbers in a signed number system. Unsigned: a type with zero and positive values only.

9 ENCM 369 W14 Section 01 Slide Set 5 slide 9/68 Questions about an example 32-bit pattern Question 1: Is this bit pattern signed or unsigned? Question 2: Why does it not make sense to ask Question 1?

10 ENCM 369 W14 Section 01 Slide Set 5 slide 10/68 n-bit patterns Let s use b n 1, b n 2,..., b 2, b 1, b 0 as names for the bits in an n-bit pattern... bit number: b n 1 n 1 b n 2 b 2 b 1 b 0 n The bits at the ends, b n 1 and b 0, have special names. What are those names? If n-bit patterns are used to encode numbers, how many different numbers can be encoded?

11 ENCM 369 W14 Section 01 Slide Set 5 slide 11/68 Two s complement systems Some of this material is review from ENEL 353 please make sure you know all the two s complement stuff from that course. Some of this material was not taught in ENEL 353. Two s complement is by far the most common system used in computers for signed integer representation. Other systems, such as sign-and-magnitude and one s complement are extremely rarely used in modern equipment.

12 ENCM 369 W14 Section 01 Slide Set 5 slide 12/68 n-bit two s complement systems In an n-bit two s complement number system, the number represented by an n-bit pattern is b n 1 2 n 1 + b n 2 2 n 2 + b n 3 2 n b b b The above two s-complement representation formula was not taught in ENEL 353, but it is very handy to know. Example with n = 8: What number does the bit pattern 1100_0011 represent as a two s complement integer?

13 ENCM 369 W14 Section 01 Slide Set 5 slide 13/68 Two s complement in MIPS n = 32: 32-bit two s complement is used for the C int type we have used that a lot in Labs 2 4. n = 16: 16-bit two s complement is important it s used in offsets in machine code for lw, sw, beq, bne, and other instructions, and used for constants in machine code for addi and slti. n = 8: Arrays of 8-bit two s-complement integers are supported by the lb instruction more about that later.

14 ENCM 369 W14 Section 01 Slide Set 5 slide 14/68 n-bit unsigned integer systems Review: Two s complement representation formula... b n 1 2 n 1 + b n 2 2 n 2 + b n 3 2 n b b b In an n-bit unsigned integer system, the number represented by an n-bit pattern is b n 1 2 n 1 + b n 2 2 n 2 + b n 3 2 n b b b The difference between formulas is just a single sign. Example: What number does the bit pattern 1100_0011 represent as an unsigned integer?

15 ENCM 369 W14 Section 01 Slide Set 5 slide 15/68 The sum of some powers of two Formula for a finite series where terms are 2 i... Proof: k 1 2 i = 2 k 1 i=0 k 1 2 i = k k 1 i=0 = (2 1)( k k 1 ) = ( k k ) ( k k 1 ) = 2 k 1

16 ENCM 369 W14 Section 01 Slide Set 5 slide 16/68 The sum of some powers of two, continued Formula from previous slide: k 1 2 i = 2 k 1 i=0 Another way to understand this: a = k 1 i=0 2i is one less than b, where unsigned binary representations of a and b are a = k 1 s and b = k +1 bits k 0 s So what does the n-bit pattern represent in an n-bit two s-complement system?

17 ENCM 369 W14 Section 01 Slide Set 5 slide 17/68 Ranges of two s complement and unsigned integer types What is the greatest value in an n-bit two s complement system? What is the least value in an n-bit two s complement system? What is the smallest value in an n-bit unsigned system? (Not a hard question, I hope!) What is the largest value in an n-bit unsigned system?

18 ENCM 369 W14 Section 01 Slide Set 5 slide 18/68 32-bit patterns, interpreted as unsigned and signed integers 32-bit hexadecimal unsigned signed pattern rep. interpretation interp x x x7ffffffe = 2, 147, 483, x7fffffff = 2, 147, 483, x = 2, 147, 483, x = 2, 147, 483, xfffffffe = 4, 294, 967, xffffffff = 4, 294, 967, 295 1

19 ENCM 369 W14 Section 01 Slide Set 5 slide 19/68 Example of MIPS instruction support for unsigned integers: sltu Suppose $s0 contains 0xffff_ffff and $s1 contains 0x0000_0001, and these two instructions are run: slt $t0, $s0, $s1 sltu $t1, $s0, $s1 What values do $t0 and $t1 get? ATTENTION: Later on we ll see that the differences between add/addu, addi/addiu, and sub/subu are not so simple and obvious!

20 ENCM 369 W14 Section 01 Slide Set 5 slide 20/68 4 Key Facts About Two s Complement Fact 1 is about the sign bit. Fact 2 is about how to negate a number. Fact 3 has to do with sign extension. Fact 4 is about digital circuits for integer addition and subtraction.

21 ENCM 369 W14 Section 01 Slide Set 5 slide 21/68 Two s Complement Fact 1: The MSB is the Sign Bit It s easy to test whether a two s complement integer is negative. If the MSB is 0, the number is 0, so, zero or positive. If the MSB is 1, the number is < 0, so, negative.

22 ENCM 369 W14 Section 01 Slide Set 5 slide 22/68 Two s Complement Fact 2: How to Negate a Number Given the bit pattern for a number X, what is the bit pattern for X? The rule is: Invert the bits of X, then do what? (This is review from ENEL 353.) This works for all values of X, positive, zero, or negative, in an n-bit two s complement system, except for one X which X? Let s do some examples with n = 8... Suppose x is an int in $s0 and y is an int in $s1, and we need MIPS A.L. for y = -x; Let s solve this two different ways, with nor and with sub.

23 ENCM 369 W14 Section 01 Slide Set 5 slide 23/68 Two s Complement Fact 3: Sign Extension Sign extension means converting a relatively narrow representation of a number to a relatively wide representation of that same number. Suppose m > n. Given an n-bit two s complement representation of an integer, what is the m-bit representation of that integer? Let s do examples with n = 8 and m = 16. Proof that the method always works: It s obvious if the MSB of the n-bit number is 0 we re just inserting m n leading zeros. If the MSB of the n-bit number is 1, see the algebra on the next slide.

24 ENCM 369 W14 Section 01 Slide Set 5 slide 24/68 Sign extension works when b n 1, the MSB, is 1 All we need to show is that the formula is correct for widening by one bit (for example from 1101_0110 to 1_1101_0110); if that works we can get from n bits to m bits by repeatedly widening by one bit. Let our n-bit negative number be 1 2 n 1 + b n 2 2 n 2 + b n 3 2 n b Then the (n+1)-bit number we get from the sign-extension formula is 1 2 n n 1 + b n 2 2 n 2 + b n 3 2 n b Subtract the (n+1)-bit number from the n-bit number; all the terms with b i cancel, so the difference is 1 2 n 1 ( 1 2 n n 1 ) = 2 n 2 2 n 1 = 0.

25 ENCM 369 W14 Section 01 Slide Set 5 slide 25/68 Remarks on the proof that sign extension works You won t be tested on this proof, but I hope you agree that it s nice to know that the proof exists. Algebra can be used to carefully prove all of the other important facts about two s-complement representation and arithmetic, but to go through all the proofs would really delay this course.

26 ENCM 369 W14 Section 01 Slide Set 5 slide 26/68 Example of sign-extension with lb /* Add up values from an array * of signed bytes... */ int sum(signed char *a, int n) { int i, sum; sum = 0; for (i = 0; i < n; i++) sum += a[i]; return sum; } What is the MIPS assembly language for sum += a[i];? (Assume that i is $t8, sum is $t9.)

27 ENCM 369 W14 Section 01 Slide Set 5 slide 27/68 Outline of Slide Set 5 A Few Remarks about Chapter 6 Material Bit Patterns and Integers Addition of Unsigned and Signed Integers Subtraction of Unsigned and Signed Integers Instructions used by C and C++ compilers for integer addition and subtraction

28 ENCM 369 W14 Section 01 Slide Set 5 slide 28/68 Addition of Unsigned and Signed Integers Section in the textbook is very good on the organization of adder circuits. Let s start with the 1-bit full adder. (Note: A half adder is a full adder without a carry-in input.) a b carry out + carry in sum The 1-bit full adder is a combinational logic circuit let s write out its truth table.

29 ENCM 369 W14 Section 01 Slide Set 5 slide 29/68 Combining n 1-bit adders to make an n-bit adder Let s sketch out how to put together some 1-bit adders to make an adder that can add two n-bit numbers. The circuit we ve just sketched is called a ripple-carry adder, because carry signals ripple from right to left. A ripple-carry adder is simple but is slower than some more sophisticated adder designs. If time permits later in ENCM 369, we might look at faster adder designs, such as carry-lookahead adders and prefix adders.

30 ENCM 369 W14 Section 01 Slide Set 5 slide 30/68 n-bit addition example Let s do an example with an 8-bit adder: Add a = two (which is 17 ten ) and b = two (which is 18 ten ). bit number carry in a b sum

31 ENCM 369 W14 Section 01 Slide Set 5 slide 31/68 Two s Complement Fact 4: About integer addition hardware An n-bit adder, which seems to be designed to add unsigned integers, will also generate correct results when bit patterns are interpreted as two s-complement signed integers. We re not going to prove this fact mathematically, just demonstrate it a couple of ways. First, let s add two example 8-bit patterns. Then, let s show how a MIPS addi instruction works when its constant operand is negative.

32 ENCM 369 W14 Section 01 Slide Set 5 slide 32/68 Two s Complement Fact 4: An integer adder is just an adder This circuit is NOT specialized for signed or unsigned arithmetic: a n 1 b n 1 a n 2 b n 2 a 1 b 1 a 0 b 0 n-bit integer adder carry in to LSB carry out from MSB sum n 1 sum n 2 sum 1 sum 0 There is NO control input to tell the circuit what the types of the input and output n-bit patterms are!

33 ENCM 369 W14 Section 01 Slide Set 5 slide 33/68 Remarks related to Fact 4 Fact 4 is an important reason why two s-complement systems are used so widely for signed integers one simple piece of hardware can do both signed and unsigned addition. (That s NOT true for other kinds of signed number systems, such as sign-and-magnitude.) We ll see later on that a small enhancement to an n-bit adder will allow it to do both signed and unsigned subtraction.

34 ENCM 369 W14 Section 01 Slide Set 5 slide 34/68 Out-of-range results in signed addition Any n-bit number system has a finite set of values. Within this set there are many pairs of numbers whose sums are NOT in the set. For example, in an 8-bit signed integer system the set of values is { 128, 127,..., +126, +127}. Think about adding 66 and 80. The sum, in ordinary math, is 146, which is not part of the 8-bit signed integer system. What will an 8-bit adder do with 66 and 80 as inputs?

35 ENCM 369 W14 Section 01 Slide Set 5 slide 35/68 More examples of signed overflow in addition Let s look at trying to add 126 and 127 with an 8-bit adder. Let s build an executable for this C code on a typical system with a 32-bit int type: #include <stdio.h> int main(void) { int x = ; /* 1 billion */ int y = ; /* 2 billion */ printf("sum is %d.\n", x + y); return 0; } What will the output be?

36 ENCM 369 W14 Section 01 Slide Set 5 slide 36/68 Two ways to detect signed overflow in addition Method One: Signed overflow in a + b has happened if and only if the sign bits of a and b are the same but are different from the sign bit of the sum. Let s put this in tabular form. Method One, stated another way: Signed overflow has happened if and only if the sign bit of the sum is obviously wrong. Method Two: Signed overflow has happened if and only if the carry in to the MSB of the adder is different from the carry out of the MSB.

37 ENCM 369 W14 Section 01 Slide Set 5 slide 37/68 MIPS add and addu instructions Both instructions add two GPR values and use a 32-bit adder to produce a 32-bit result. The adder DOES NOT do different things depending on whether the instruction is add or addu! a n 1 b n 1 a n 2 b n 2 a 1 b 1 a 0 b 0 n-bit integer adder carry in to LSB carry out from MSB sum n 1 sum n 2 sum 1 sum 0 So the difference is NOT LIKE the difference between slt, which always works for signed integers, and sltu, which always works for unsigned integers.

38 ENCM 369 W14 Section 01 Slide Set 5 slide 38/68 add and addu: What s the difference? addu always copies the 32-bit result to the destination GPR, even if the result is wrong according to normal, everyday math. add checks for signed overflow wrong result, interpreting both source GPRs and the result as signed. If add detects signed overflow, there is no update to the destination GPR. Instead, there is an exception the program that tried the add is suspended, and the operating system kernel takes over. If signed overflow is not detected in add, the destination GPR gets exactly the same value it would have been given by addu!

39 ENCM 369 W14 Section 01 Slide Set 5 slide 39/68 MIPS addi and addiu instructions In both cases, the constant built in to the instruction is assumed to be signed, and is widened to 32 bits using sign extension. That 32-bit value is added to the source GPR value. After that, addiu is like addu, and addi is like add. Example: $s0 and $s1 both start with 0x8000_0000, and then the processor runs addiu $s0, $s0, -1 addi $s1, $s1, -1 What are the effects of these instructions?

40 ENCM 369 W14 Section 01 Slide Set 5 slide 40/68 What does u mean at the end of a MIPS instruction mnemonic? It s a mistake to think that it always means unsigned. trailing u means interpret bit patterns as unsigned integers sltu sltiu lbu lhu multu divu (and various others... ) trailing u means DON T cause exceptions when signed overflow is detected addu addiu subu

41 ENCM 369 W14 Section 01 Slide Set 5 slide 41/68 Out-of-range results in unsigned addition From several slides back: Any n-bit number system has a finite set of values. Within this set there are many pairs of numbers whose sums are NOT in the set. Let s do an example with an 8-bit unsigned integer system, for which the set of values is {0, 1, 2,..., 254, 255}.

42 ENCM 369 W14 Section 01 Slide Set 5 slide 42/68 Unsigned overflow and signed overflow are NOT the same thing! Unsigned overflow in addition is an event in which an n-bit adder produces a wrong result (in the sense of ordinary math), when all three numbers two inputs and the sum are interpreted as unsigned. This is NOT the same as signed overflow in addition is an event in which an n-bit adder produces a wrong result (in the sense of ordinary math), when all three numbers two inputs and the sum are interpreted as signed.

43 ENCM 369 W14 Section 01 Slide Set 5 slide 43/68 Two ways to detect unsigned overflow in addition Suppose that sum is the result of adding a and b with an n-bit adder. 1. Unsigned overflow has occurred if and only if, interpreting numbers as unsigned, sum < a. (If this is true, sum < b will also be true.) 2. Unsigned overflow has occurred if and only if the carry out from the MSB of the adder is 1. (Note that this method can t be used if that carry bit is not available!)

44 ENCM 369 W14 Section 01 Slide Set 5 slide 44/68 Unsigned overflow and MIPS instructions Remember, add and addi cause exceptions in the case of signed overflow. Are there instructions that cause exceptions in the case of unsigned overflow in addition? No, there are not. Why was MIPS designed that way? I don t know, but here s a guess: At the time the MIPS instruction set was designed, perhaps there was a market advantage for processors which would check all integer additions (and subtractions) for signed overflow.

45 ENCM 369 W14 Section 01 Slide Set 5 slide 45/68 Warnings about overflow terminology (1) We ve changed terminology this year relative to past versions of ENCM 369. Here are the translations, which are important to know about when you re looking at old midterms and final exams and beyond 2013 and earlier signed overflow overflow unsigned overflow wraparound Note that Winter 2014 ENCM 369 terminology is the same as Fall 2013 ENEL 353 terminology. The word wraparound is related the idea of an odometer wrapping around from 999,999 km to 000,000 km, or a 24-hour clock wrapping around from 23:59 to 00:00.

46 ENCM 369 W14 Section 01 Slide Set 5 slide 46/68 Warnings about overflow terminology (2) Unfortunately, literature on computer systems is not always very precise with the use of the word overflow. It s sometimes suggested that overflow is a single, simple concept, but that s just not true. Here are some things to watch out for: Often the word overflow by itself is used to mean signed overflow. Details of overflow in floating-point computation we ll cover floating-point later in the course are quite different from details of overflow in integer computation.

47 ENCM 369 W14 Section 01 Slide Set 5 slide 47/68 Outline of Slide Set 5 A Few Remarks about Chapter 6 Material Bit Patterns and Integers Addition of Unsigned and Signed Integers Subtraction of Unsigned and Signed Integers Instructions used by C and C++ compilers for integer addition and subtraction

48 ENCM 369 W14 Section 01 Slide Set 5 slide 48/68 Subtraction of Unsigned and Signed Integers a b = a + ( b). Can we use this simple idea to turn an adder into a subtractor? b can be generated by inverting all bits of b and adding 1 (Fact 2 about two s complement). We can get the bit inversion with inverters, and add 1 by setting the carry in to the LSB to 1. Note: We would like the adder to remain capable of computing a + b; to do this we will use multiplexers.

49 ENCM 369 W14 Section 01 Slide Set 5 slide 49/68 The 2:1 multiplexer As we saw in ENEL 353, a 2:1 multiplexer ( mux for short) has two data inputs and a third select input: A B 0 1 S Y Y = { A if S = 0 B if S = 1 The mux can be thought of as a switch controlled by S: A B S =0 S =1 Y But of course electronic circuits don t really have moving parts! See textbook Section to see how to make muxes out of logic gates.

50 ENCM 369 W14 Section 01 Slide Set 5 slide 50/68 The 2:1 multiplexer, continued Usual symbol for a 2:1 mux, used in this year s textbook: A B 0 1 S Symbol used for a 2:1 mux in last year s ENCM 369 textbook: Y 2:1 mux truth table: S A B Y A 0 B 1 S Y Muxes of various dimensions are important components of processor designs in textbook Chapter 7.

51 ENCM 369 W14 Section 01 Slide Set 5 slide 51/68 n-bit integer adder, enhanced to support subtraction a n 1 b n 1 a n 2 b n 2 a 1 b 1 a 0 b result n result n 2 result 1 result 0 mux select input: 0 for addition, 1 for subtraction carry in to LSB: 0 for addition, 1 for subtraction The above circuit uses a ripple-carry adder, but other kinds of integer adder can also be used to make a subtractor. See Sections and for the textbook for more details.

52 ENCM 369 W14 Section 01 Slide Set 5 slide 52/68 More about the n-bit integer adder/subtractor It s a fact although we won t prove it that this circuit subtracts correctly both when a, b, and the result are all interpreted as signed, and also when they re all interpreted as unsigned. Let s demonstrate this by computing a b, with n = 8, a = 1111_0000 two, and b = 0000_0101 two. So, like integer adders, integer subtractors are not specialized for signed or unsigned computation.

53 ENCM 369 W14 Section 01 Slide Set 5 slide 53/68 Signed overflow and unsigned overflow in integer subtraction These terms have already been defined for addition... signed overflow: an event in which an n-bit adder produces a wrong result (in the sense of ordinary math), when all three numbers two inputs and the sum are interpreted as signed. unsigned overflow: an event in which an n-bit adder produces a wrong result (in the sense of ordinary math), when all three numbers two inputs and the sum are interpreted as unsigned. These definitions make sense for subtraction as well.

54 ENCM 369 W14 Section 01 Slide Set 5 slide 54/68 Signed overflow in subtraction Example: With 8-bit signed integers, let s try to compute 120 ten 10 ten... Signed overflow in integer subtraction can happen in only two situations: negative number positive number appears to be 0 positive or zero negative number appears to be < 0 In both cases, the sign bit of the result is obviously wrong.

55 ENCM 369 W14 Section 01 Slide Set 5 slide 55/68 Unsigned overflow in subtraction Example: With 8-bit unsigned integers, let s try to compute 17 ten 22 ten... Detection of unsigned overflow: When a b is computed and a, b and the result are all interpreted as unsigned, overflow has occurred if and only if the result appears to be > a. Another way to detect unsigned overflow: In an adder/subtractor circuit like that on slide 51, unsigned overflow has occurred if and only if the carry out of the most significant bit of the adders is 0. (That may be surprising, but it s true.)

56 ENCM 369 W14 Section 01 Slide Set 5 slide 56/68 MIPS sub and subu instructions subu: Generate 32-bit subtraction result, copy it to destination GPR even if result is wrong. sub: Generate 32-bit subtraction result, and check for signed overflow (not unsigned overflow). If there was no signed overflow, copy result to destination GPR; on signed overflow, do not update destination GPR and instead cause an exception. This behaviour matches the behaviour of addu vs. add and addiu vs. addi.

57 ENCM 369 W14 Section 01 Slide Set 5 slide 57/68 Subtle, confusing, but important details about MIPS instruction names It is best to think of the u at the end of addu, addiu, and subu as standing for unchecked, NOT unsigned. On the other hand, the u really does mean unsigned in sltu, sltiu, lbu, multu, divu, and just about any other MIPS instruction with a name ending in u.

58 ENCM 369 W14 Section 01 Slide Set 5 slide 58/68 Review: What does u mean at the end of a MIPS instruction mnemonic? It s a mistake to think that it always means unsigned. trailing u means interpret bit patterns as unsigned integers sltu sltiu lbu lhu multu divu (and various others... ) trailing u means DON T cause exceptions when signed overflow is detected addu addiu subu

59 ENCM 369 W14 Section 01 Slide Set 5 slide 59/68 Review of MIPS integer addition and subtraction instructions: examples $s0 = 0xd800_0000, $s1 = 0xe000_0000. What is the effect of addu $t0, $s0, $s1? Is there any difference if the instruction is changed from addu to add? $s2 = 0x9000_0000, $s3 = 0x2fff_ffff. What is the effect of subu $t1, $s2, $s3? Is there any difference if the instruction is changed from subu to sub?

60 ENCM 369 W14 Section 01 Slide Set 5 slide 60/68 Outline of Slide Set 5 A Few Remarks about Chapter 6 Material Bit Patterns and Integers Addition of Unsigned and Signed Integers Subtraction of Unsigned and Signed Integers Instructions used by C and C++ compilers for integer addition and subtraction

61 ENCM 369 W14 Section 01 Slide Set 5 slide 61/68 Instructions used by C and C++ compilers for integer addition and subtraction First, notes about name of C and C++ integer types... unsigned by itself means exactly the same thing as unsigned int: unsigned w; unsigned int x; // x has the same type as w. Plain int and signed int mean exactly the same thing: int y; signed int z; // z has the same type as y. (But you won t often see code that spells out the type as signed int.)

62 ENCM 369 W14 Section 01 Slide Set 5 slide 62/68 Addition and subtraction instructions for signed and unsigned arithmetic in C and C++ unsigned u_foo(unsigned a, unsigned b) { return a + 127u - b; } int s_foo(int c, int d) { return c d; } What instructions will a MIPS C compiler choose for the above two functions?

63 ENCM 369 W14 Section 01 Slide Set 5 slide 63/68 In fact, C and C++ compilers for MIPS never use add, addi, or sub! For all addition and subtraction with plain int and unsigned int types, a compiler will choose addu, addiu, or subu. For addition and subtraction with pointers, a compiler will use addu, addiu, or subu, along with appropriate adjustments for array element size. (Example: If $s0 is allocated for p, of type int*, the compiler translates p-- as addiu $s0, $s0, -4.)

64 ENCM 369 W14 Section 01 Slide Set 5 slide 64/68 So why has ENCM 369 used add, addi, and sub in lectures, tutorials, and Labs 2 5? We have followed what Chapter 6 of your textbook does. The big picture questions in Chapter 6 are What s an instruction? and How can instructions be organized to create procedures? Exact details of addition and subtraction with numbers of large magnitudes would draw attention away from the big picture questions.

65 ENCM 369 W14 Section 01 Slide Set 5 slide 65/68 Why don t C and C++ compilers use add, addi, or sub, or equivalents? For arithmetic with unsigned ints and pointers, it would simply be wrong. For signed arithmetic, instructions like MIPS add, addi, and sub don t exist in most ISA s. (For example, ARM, x86 and x86-64 all have integer add and subtract instructions that work like MIPS addu, not like MIPS add.) Checking for signed overflow after each int addition or subtraction would make programs larger and slower. MIPS compilers give coders the program behaviour they have come to expect from compilers for other platforms.

66 ENCM 369 W14 Section 01 Slide Set 5 slide 66/68 x86-64 instructions for u_foo and s_foo Code from an earlier slide: unsigned u_foo(unsigned a, unsigned b) { return a + 127u - b; } int s_foo(int c, int d) { return c d; } Let s see what gcc does with this for the x86-64 architecture.

67 ENCM 369 W14 Section 01 Slide Set 5 slide 67/68 x86-64 instructions for u_foo and s_foo MACHINE CODE (HEX BYTES) EXPLANATION u_foo: 8d 47 7f r.v. = arg f0 r.v. = r.v. - arg2 c3 return s_foo: 8d 47 7f r.v. = arg f0 r.v. = r.v. - arg2 c3 return The result is two identical three-instruction sequences just what saw for MIPS! (gcc version 4.4 used with -O2 optimization selected.)

68 ENCM 369 W14 Section 01 Slide Set 5 slide 68/68 Attention! C and C++ do NOT help coders or users know when values of integers get out of hand! (This is also true for Java.) #include <stdio.h> int main(void) { int balance = ; // $20M in cents int deposit = ; // $10M in cents balance += deposit; printf("updated balance: %d cents.\n", balance); return 0; } Output produced on a typical platform with a 32-bit int type... Updated balance: cents.

Slide Set 5. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 5. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 5 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary February 2018 ENCM 369 Winter 2018 Section

More information

Integer Multiplication and Division

Integer Multiplication and Division Integer Multiplication and Division for ENCM 369: Computer Organization Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 208 Integer

More information

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

ENCM 369 Winter 2019 Lab 6 for the Week of February 25 page of ENCM 369 Winter 29 Lab 6 for the Week of February 25 Steve Norman Department of Electrical & Computer Engineering University of Calgary February 29 Lab instructions and other documents for ENCM

More information

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng Slide Set 1 for ENEL 339 Fall 2014 Lecture Section 02 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2014 ENEL 353 F14 Section

More information

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides Slide Set 1 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Slide Set 1 (corrected)

Slide Set 1 (corrected) Slide Set 1 (corrected) for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018

More information

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 3 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

More information

ENCM 369 Winter 2015 Lab 6 for the Week of March 2

ENCM 369 Winter 2015 Lab 6 for the Week of March 2 page of 2 ENCM 369 Winter 25 Lab 6 for the Week of March 2 Steve Norman Department of Electrical & Computer Engineering University of Calgary February 25 Lab instructions and other documents for ENCM 369

More information

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENEL 353 Fall 2017 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2017 SN s ENEL 353 Fall 2017 Slide Set 1 slide

More information

Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng

Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng Slide Set 11 for ENCM 369 Winter 2015 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2015 ENCM 369 W15 Section

More information

Arithmetic for Computers

Arithmetic for Computers MIPS Arithmetic Instructions Cptr280 Dr Curtis Nelson Arithmetic for Computers Operations on integers Addition and subtraction; Multiplication and division; Dealing with overflow; Signed vs. unsigned numbers.

More information

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide

More information

Number Systems and Their Representations

Number Systems and Their Representations Number Representations Cptr280 Dr Curtis Nelson Number Systems and Their Representations In this presentation you will learn about: Representation of numbers in computers; Signed vs. unsigned numbers;

More information

Chapter 3 Arithmetic for Computers

Chapter 3 Arithmetic for Computers Chapter 3 Arithmetic for Computers 1 Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing the Architecture operation

More information

CPE 335 Computer Organization. MIPS Arithmetic Part I. Content from Chapter 3 and Appendix B

CPE 335 Computer Organization. MIPS Arithmetic Part I. Content from Chapter 3 and Appendix B CPE 335 Computer Organization MIPS Arithmetic Part I Content from Chapter 3 and Appendix B Dr. Iyad Jafar Adatped from Dr. Gheith Abandah Slides http://www.abandah.com/gheith/courses/cpe335_s08/index.html

More information

#1 #2 with corrections Monday, March 12 7:00pm to 8:30pm. Please do not write your U of C ID number on this cover page.

#1 #2 with corrections Monday, March 12 7:00pm to 8:30pm. Please do not write your U of C ID number on this cover page. page 1 of 6 University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Lecture Instructors: Steve Norman and Norm Bartley Winter 2018 MIDTERM TEST #1 #2 with

More information

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs Slide Set 2 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures $2M 3D camera Lecture 8 MIPS Instruction Representation I Instructor: Miki Lustig 2014-09-17 August 25: The final ISA showdown: Is ARM, x86, or

More information

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture EEM 486: Computer Architecture Lecture 2 MIPS Instruction Set Architecture EEM 486 Overview Instruction Representation Big idea: stored program consequences of stored program Instructions as numbers Instruction

More information

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

More information

Slide Set 7. for ENCM 501 in Winter Term, Steve Norman, PhD, PEng

Slide Set 7. for ENCM 501 in Winter Term, Steve Norman, PhD, PEng Slide Set 7 for ENCM 501 in Winter Term, 2017 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2017 ENCM 501 W17 Lectures: Slide

More information

Computer Architecture Set Four. Arithmetic

Computer Architecture Set Four. Arithmetic Computer Architecture Set Four Arithmetic Arithmetic Where we ve been: Performance (seconds, cycles, instructions) Abstractions: Instruction Set Architecture Assembly Language and Machine Language What

More information

COMP MIPS instructions 2 Feb. 8, f = g + h i;

COMP MIPS instructions 2 Feb. 8, f = g + h i; Register names (save, temporary, zero) From what I have said up to now, you will have the impression that you are free to use any of the 32 registers ($0,..., $31) in any instruction. This is not so, however.

More information

T02 Tutorial Slides for Week 2

T02 Tutorial Slides for Week 2 T02 Tutorial Slides for Week 2 ENEL 353: Digital Circuits Fall 2017 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 19 September, 2017

More information

ENCM 369 Winter 2017 Lab 3 for the Week of January 30

ENCM 369 Winter 2017 Lab 3 for the Week of January 30 page 1 of 11 ENCM 369 Winter 2017 Lab 3 for the Week of January 30 Steve Norman Department of Electrical & Computer Engineering University of Calgary January 2017 Lab instructions and other documents for

More information

UCB CS61C : Machine Structures

UCB CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Guest Lecturer Alan Christopher Lecture 08 MIPS Instruction Representation I 2014-02-07 BOINC MORE THAN JUST SETI@HOME BOINC (developed here

More information

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 4 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 4 slide

More information

ENCM 369 Winter 2018 Lab 9 for the Week of March 19

ENCM 369 Winter 2018 Lab 9 for the Week of March 19 page 1 of 9 ENCM 369 Winter 2018 Lab 9 for the Week of March 19 Steve Norman Department of Electrical & Computer Engineering University of Calgary March 2018 Lab instructions and other documents for ENCM

More information

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions Outline EEL-4713 Computer Architecture Multipliers and shifters Multiplication and shift registers Chapter 3, section 3.4 Next lecture Division, floating-point 3.5 3.6 EEL-4713 Ann Gordon-Ross.1 EEL-4713

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #8: MIPS Memory & Decisions 2006-07-10 CS 61C L08 MIPS Memory (1) Andy Carle Review In MIPS Assembly Language: Registers replace C

More information

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01

More information

Chapter Three. Arithmetic

Chapter Three. Arithmetic Chapter Three 1 Arithmetic Where we've been: Performance (seconds, cycles, instructions) Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing

More information

Slides for Lecture 15

Slides for Lecture 15 Slides for Lecture 15 ENCM 501: Principles of Computer Architecture Winter 2014 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 6 March,

More information

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 9 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 369 Winter 2018 Section 01

More information

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5 ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5 MIPS/SPIM General Purpose Registers Powers of Two 0 $zero all bits are zero 16 $s0 local variable 1 $at assembler temporary 17 $s1 local

More information

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J. CS61C Negative Numbers and Logical Operations cs 61C L7 Number.1 Lecture 7 February 10, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html Review 1/2

More information

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 3 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01

More information

Slides for Lecture 6

Slides for Lecture 6 Slides for Lecture 6 ENCM 501: Principles of Computer Architecture Winter 2014 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 28 January,

More information

Review: MIPS Organization

Review: MIPS Organization 1 MIPS Arithmetic Review: MIPS Organization Processor Memory src1 addr 5 src2 addr 5 dst addr 5 write data Register File registers ($zero - $ra) bits src1 data src2 data read/write addr 1 1100 2 30 words

More information

Winter 2003 MID-SESSION TEST Monday, March 10 6:30 to 8:00pm

Winter 2003 MID-SESSION TEST Monday, March 10 6:30 to 8:00pm University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Instructors: Dr. S. A. Norman (L01) and Dr. S. Yanushkevich (L02) Winter 2003 MID-SESSION TEST Monday,

More information

We are quite familiar with adding two numbers in decimal

We are quite familiar with adding two numbers in decimal Addition We are quite familiar with adding two numbers in decimal What about adding two binary numbers? If we use the two s complement method to represent binary numbers, addition can be done in a straightforward

More information

Winter 2009 FINAL EXAMINATION Location: Engineering A Block, Room 201 Saturday, April 25 noon to 3:00pm

Winter 2009 FINAL EXAMINATION Location: Engineering A Block, Room 201 Saturday, April 25 noon to 3:00pm University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Lecture Instructors: S. A. Norman (L01), N. R. Bartley (L02) Winter 2009 FINAL EXAMINATION Location:

More information

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 3 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 3 slide 2/46

More information

Number Systems and Computer Arithmetic

Number Systems and Computer Arithmetic Number Systems and Computer Arithmetic Counting to four billion two fingers at a time What do all those bits mean now? bits (011011011100010...01) instruction R-format I-format... integer data number text

More information

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9 slide 2/41 Contents Slide Set 9 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014

More information

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro 1 Levels of Representation/Interpretation Machine Interpretation High Level Language Program (e.g., C) Compiler Assembly

More information

CPS311 - COMPUTER ORGANIZATION. A bit of history

CPS311 - COMPUTER ORGANIZATION. A bit of history CPS311 - COMPUTER ORGANIZATION A Brief Introduction to the MIPS Architecture A bit of history The MIPS architecture grows out of an early 1980's research project at Stanford University. In 1984, MIPS computer

More information

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Machine Interpretation

More information

UCB CS61C : Machine Structures

UCB CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 07 Introduction to MIPS : Decisions II Lecturer SOE Dan Garcia 2011-09-12 Hello to Dr Mauro Sgarzi from Italy!! Researchers at Microsoft

More information

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 8 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 369 Winter 2018 Section 01

More information

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah NUMBER OPERATIONS Mahdi Nazm Bojnordi Assistant Professor School of Computing University of Utah CS/ECE 3810: Computer Organization Overview Homework 4 is due tonight Verify your uploaded file before the

More information

Lecture 8: Addition, Multiplication & Division

Lecture 8: Addition, Multiplication & Division Lecture 8: Addition, Multiplication & Division Today s topics: Signed/Unsigned Addition Multiplication Division 1 Signed / Unsigned The hardware recognizes two formats: unsigned (corresponding to the C

More information

UCB CS61C : Machine Structures

UCB CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 Introduction to MIPS Decisions II Lecturer SOE Dan Garcia Obama sweeps 8 th state in a row; it s getting tight! 2008 02 13 In what

More information

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson. CS61C - Machine Structures Lecture 6 - Instruction Representation September 15, 2000 David Patterson http://www-inst.eecs.berkeley.edu/~cs61c/ 1 Review Instructions: add, addi, sub, lw, sw beq, bne, j

More information

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture MIPS Instruction Formats July 2, 2014 Review New registers: $a0-$a3, $v0-$v1, $ra, $sp New instructions: slt, la, li, jal, jr Saved registers: $s0-$s7, $sp, $ra Volatile registers: $t0-$t9, $v0-$v1, $a0-$a3

More information

CS61C Machine Structures. Lecture 10 - MIPS Branch Instructions II. 2/8/2006 John Wawrzynek. (www.cs.berkeley.edu/~johnw)

CS61C Machine Structures. Lecture 10 - MIPS Branch Instructions II. 2/8/2006 John Wawrzynek. (www.cs.berkeley.edu/~johnw) CS61C Machine Structures Lecture 10 - MIPS Branch Instructions II 2/8/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L10 MIPS Branch II (1) Compiling C if into

More information

ECE331: Hardware Organization and Design

ECE331: Hardware Organization and Design ECE331: Hardware Organization and Design Lecture 15: Midterm 1 Review Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Basics Midterm to cover Book Sections (inclusive) 1.1 1.5

More information

Computer Architecture I Midterm I

Computer Architecture I Midterm I Computer Architecture I Midterm I April 11 2017 Computer Architecture I Midterm I Chinese Name: Pinyin Name: E-Mail... @shanghaitech.edu.cn: Question Points Score 1 1 2 12 3 16 4 14 5 18 6 17 7 22 Total:

More information

Part I: Translating & Starting a Program: Compiler, Linker, Assembler, Loader. Lecture 4

Part I: Translating & Starting a Program: Compiler, Linker, Assembler, Loader. Lecture 4 Part I: a Program: Compiler, Linker, Assembler, Loader Lecture 4 Program Translation Hierarchy C program Com piler Assem bly language program Assem bler Object: Machine language module Object: Library

More information

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture MIPS Functions July 1, 2014 Review I RISC Design Principles Smaller is faster: 32 registers, fewer instructions Keep it simple: rigid syntax, fixed instruction length MIPS Registers: $s0-$s7,$t0-$t9, $0

More information

RISC-V Assembly and Binary Notation

RISC-V Assembly and Binary Notation RISC-V Assembly and Binary Notation L02-1 Course Mechanics Reminders Course website: http://6004.mit.edu All lectures, videos, tutorials, and exam material can be found under Information/Resources tab.

More information

The MIPS Instruction Set Architecture

The MIPS Instruction Set Architecture The MIPS Set Architecture CPS 14 Lecture 5 Today s Lecture Admin HW #1 is due HW #2 assigned Outline Review A specific ISA, we ll use it throughout semester, very similar to the NiosII ISA (we will use

More information

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Introduction to the MIPS Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Introduction to the MIPS The Microprocessor without Interlocked Pipeline Stages

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #7 MIPS Decisions 2007-7-5 Scott Beamer, Instructor takes on with www.sfgate.com CS61C L7 MIPS Decisions (1) Review In MIPS Assembly Language:

More information

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the ISA. RISC Goals RISC: Simplify ISA Simplify CPU Design Better CPU Performance Motivated by simplifying

More information

Q1: /30 Q2: /25 Q3: /45. Total: /100

Q1: /30 Q2: /25 Q3: /45. Total: /100 ECE 2035(A) Programming for Hardware/Software Systems Fall 2013 Exam One September 19 th 2013 This is a closed book, closed note texam. Calculators are not permitted. Please work the exam in pencil and

More information

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support Components of an ISA EE 357 Unit 11 MIPS ISA 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support SUBtract instruc. vs. NEGate + ADD instrucs. 3. Registers accessible

More information

Review. Lecture #7 MIPS Decisions So Far...

Review. Lecture #7 MIPS Decisions So Far... CS61C L7 MIPS Decisions (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #7 MIPS Decisions 2005-09-21 There is one handout today at the front and back of the room! Lecturer PSOE, new

More information

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

Operations, Operands, and Instructions

Operations, Operands, and Instructions Operations, Operands, and Instructions Tom Kelliher, CS 220 Sept. 12, 2011 1 Administrivia Announcements Assignment Read 2.6 2.7. From Last Time Macro-architectural trends; IC fab. Outline 1. Introduction.

More information

Instructions: Language of the Computer

Instructions: Language of the Computer Instructions: Language of the Computer Tuesday 22 September 15 Many slides adapted from: and Design, Patterson & Hennessy 5th Edition, 2014, MK and from Prof. Mary Jane Irwin, PSU Summary Previous Class

More information

ENCM 369 Winter 2016 Lab 11 for the Week of April 4

ENCM 369 Winter 2016 Lab 11 for the Week of April 4 page 1 of 13 ENCM 369 Winter 2016 Lab 11 for the Week of April 4 Steve Norman Department of Electrical & Computer Engineering University of Calgary April 2016 Lab instructions and other documents for ENCM

More information

Assembly Programming

Assembly Programming Designing Computer Systems Assembly Programming 08:34:48 PM 23 August 2016 AP-1 Scott & Linda Wills Designing Computer Systems Assembly Programming In the early days of computers, assembly programming

More information

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 1 slide 2/43

More information

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook) Lecture 2 Instructions: Language of the Computer (Chapter 2 of the textbook) Instructions: tell computers what to do Chapter 2 Instructions: Language of the Computer 2 Introduction Chapter 2.1 Chapter

More information

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA CISC 662 Graduate Computer Architecture Lecture 4 - ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,

More information

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley. CS61C Machine Structures Lecture 13 - MIPS Instruction Representation I 9/26/2007 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L13 MIPS Instruction Representation

More information

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations CS6C L9 MIPS Logical & Shift Ops, and Instruction Representation I () inst.eecs.berkeley.edu/~cs6c CS6C : Machine Structures Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I 25-9-28

More information

Chapter 3 Arithmetic for Computers. ELEC 5200/ From P-H slides

Chapter 3 Arithmetic for Computers. ELEC 5200/ From P-H slides Chapter 3 Arithmetic for Computers 1 Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

More information

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization CISC 662 Graduate Computer Architecture Lecture 4 - ISA MIPS ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,

More information

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization Five classic components CS/COE0447: Computer Organization and Assembly Language I am like a control tower I am like a pack of file folders Chapter 3 I am like a conveyor belt + service stations I exchange

More information

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization CS/COE0447: Computer Organization and Assembly Language Chapter 3 Sangyeun Cho Dept. of Computer Science Five classic components I am like a control tower I am like a pack of file folders I am like a conveyor

More information

ECE 154A Introduction to. Fall 2012

ECE 154A Introduction to. Fall 2012 ECE 154A Introduction to Computer Architecture Fall 2012 Dmitri Strukov Lecture 4: Arithmetic and Data Transfer Instructions Agenda Review of last lecture Logic and shift instructions Load/store instructionsi

More information

Topic Notes: Bits and Bytes and Numbers

Topic Notes: Bits and Bytes and Numbers Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for

More information

Winter 2012 MID-SESSION TEST Tuesday, March 6 6:30pm to 8:15pm. Please do not write your U of C ID number on this cover page.

Winter 2012 MID-SESSION TEST Tuesday, March 6 6:30pm to 8:15pm. Please do not write your U of C ID number on this cover page. University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Lecture Instructors: S. A. Norman and N. R. Bartley Winter 2012 MID-SESSION TEST Tuesday, March 6

More information

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1 Instructions: MIPS ISA Chapter 2 Instructions: Language of the Computer 1 PH Chapter 2 Pt A Instructions: MIPS ISA Based on Text: Patterson Henessey Publisher: Morgan Kaufmann Edited by Y.K. Malaiya for

More information

Number Representations

Number Representations Simple Arithmetic [Arithm Notes] Number representations Signed numbers Sign-magnitude, ones and twos complement Arithmetic Addition, subtraction, negation, overflow MIPS instructions Logic operations MIPS

More information

Chapter 3: part 3 Binary Subtraction

Chapter 3: part 3 Binary Subtraction Chapter 3: part 3 Binary Subtraction Iterative combinational circuits Binary adders Half and full adders Ripple carry and carry lookahead adders Binary subtraction Binary adder-subtractors Signed binary

More information

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits CS61C L10 MIPS Instruction Representation II (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #10 Instruction Representation II 2007-7-8 Review There are register calling conventions!

More information

Slide Set 6. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 6. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 6 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2017 ENCM 339 Fall 2017 Section 01 Slide

More information

Instruction Set Architectures. CS301 Prof. Szajda

Instruction Set Architectures. CS301 Prof. Szajda Instruction Set Architectures CS301 Prof. Szajda Instruction Categories Arithmetic w x = x + 1 Memory w mem[addr] = x; Control w for(int i = 0; i < 10 ; i++) Arguments to Arithmetic Operations Constant:

More information

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes Chapter 2 Instructions: Language of the Computer Adapted by Paulo Lopes Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects

More information

Winter 2006 FINAL EXAMINATION Auxiliary Gymnasium Tuesday, April 18 7:00pm to 10:00pm

Winter 2006 FINAL EXAMINATION Auxiliary Gymnasium Tuesday, April 18 7:00pm to 10:00pm University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Lecture Instructor for L01 and L02: Dr. S. A. Norman Winter 2006 FINAL EXAMINATION Auxiliary Gymnasium

More information

Programming the processor

Programming the processor CSC258 Week 9 Logistics This week: Lab 7 is the last Logisim DE2 lab. Next week: Lab 8 will be assembly. For assembly labs you can work individually or in pairs. No matter how you do it, the important

More information

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal. Page < 1 > Math in MIPS Adding and Subtracting Numbers Adding two binary numbers together is very similar to the method used with decimal numbers, except simpler. When you add two binary numbers together,

More information

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA EE 357 Unit 11 MIPS ISA Components of an ISA 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support SUBtract instruc. vs. NEGate + ADD instrucs. 3. Registers accessible

More information

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the machine. Reduced number of cycles needed per instruction.

More information

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls Announcements HW1 is due on this Friday (Sept 12 th ) Appendix A is very helpful to HW1. Check out system calls on Page A-48. Ask TA (Liquan chen: liquan@ece.rutgers.edu) about homework related questions.

More information

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: Bits and Bytes and Numbers Number Systems Much of this is review, given the 221 prerequisite Question: how high can

More information

CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and MIPS Instruction Set Architecture

CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and MIPS Instruction Set Architecture CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and MIPS Instruction Set Architecture Instructors: Bernhard Boser & Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa16

More information