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

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

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

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

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

#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.

Integer Multiplication and Division

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

ENCM 335 Fall 2018 Lab 2 for the Week of September 24

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

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

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.

Slide Set 1 (corrected)

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

ENCM 501 Winter 2018 Assignment 2 for the Week of January 22 (with corrections)

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

ENCM 501 Winter 2016 Assignment 1 for the Week of January 25

ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20

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

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

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

ENCM 501 Winter 2017 Assignment 3 for the Week of January 30

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

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

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

ENCM 501 Winter 2015 Assignment 3 for the Week of February 2

CS61c MIDTERM EXAM: 3/17/99

ENCM 335 Fall 2018 Lab 6 for the Week of October 22 Complete Instructions

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Format. 10 multiple choice 8 points each. 1 short answer 20 points. Same basic principals as the midterm

We are quite familiar with adding two numbers in decimal

ECE 341 Midterm Exam

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 Instructor: Steve Norman

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

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

Winter 2017 MIDTERM TEST #1 Wednesday, February 8 7:00pm to 8:30pm. Please do not write your U of C ID number on this cover page.

4. Write a sum-of-products representation of the following circuit. Y = (A + B + C) (A + B + C)

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

CSC258: Computer Organization. Memory Systems

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

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

McGill University Faculty of Engineering FINAL EXAMINATION Fall 2007 (DEC 2007)

378: Machine Organization and Assembly Language

Computer Architecture I Midterm I

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

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

MIPS PROJECT INSTRUCTION SET and FORMAT

Winter 2002 FINAL EXAMINATION

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

ENCM 339 Fall 2017 Lecture Section 01 Lab 5 for the Week of October 16

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

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

Final Exam Solution Sunday, December 15, 10:05-12:05 PM

University of Toronto Mississauga. Flip to the back cover and write down your name and student number.

11/22/1999 7pm - 9pm. Name: Login Name: Preceptor Name: Precept Number:

CS61C : Machine Structures

CS2630: Computer Organization Homework 1 Bits, bytes, and memory organization Due January 25, 2017, 11:59pm

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

Name: University of Michigan uniqname: (NOT your student ID number!)

T02 Tutorial Slides for Week 2

Instructions: Language of the Computer

(Refer Slide Time: 1:40)

IA Digital Electronics - Supervision I

ENCM 501 Winter 2017 Assignment 6 for the Week of February 27

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

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

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 Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

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

ECE550 PRACTICE Midterm

Binary Adders: Half Adders and Full Adders

CENG 3420 Computer Organization and Design. Lecture 06: MIPS Processor - I. Bei Yu

COMP12111 Fundamentals of Computer Engineering Paul Nutter Vasilis Pavlidis Comments

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

Microcomputers. Outline. Number Systems and Digital Logic Review

Parallel logic circuits

ENCM 501 Winter 2019 Assignment 6 for the Week of March 11

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

CARLETON UNIVERSITY. Laboratory 2.0

COMP2611: Computer Organization. Data Representation

CS 351 Exam 2 Mon. 11/2/2015

2.1 DOWNLOAD AND INSTALL MARS

COMP 303 MIPS Processor Design Project 3: Simple Execution Loop

Floating Point. What can be represented in N bits? 0 to 2N-1. 9,349,398,989,787,762,244,859,087, x 1067

CIT 593: Intro to Computer Systems Homework #4: Assembly Language Due October 18, 2012, 4:30pm. Name

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

COS 471A,COS 471B/ELE 375 Midterm

CS 261 Fall Mike Lam, Professor Integer Encodings

2. Define Instruction Set Architecture. What are its two main characteristics? Be precise!

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Text Input and Conditionals

MIPS Assembly Programming

Basic Von Neumann Designs

Slides for Lecture 15

Number Representations

Integer Multiplication and Division

Fast Arithmetic. Philipp Koehn. 19 October 2016

Digital Fundamentals. Lab 6 2 s Complement / Digital Calculator

Slides for Lecture 6

Transcription:

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 369 can be found at people.ucalgary.ca/~norman/encm369winter29/ dministrative details You may work in pairs on this assignment You may complete this assignment individually or with one partner. Students working in pairs must make sure both partners understand all of the exercises being handed in. The point is to help each other learn all of the lab material, not to allow each partner to learn only half of it! Please keep in mind that you will not be able to rely on a partner to do work for you on midterm #2 or the final exam. Two students working together should hand in a single assignment with names and lab section numbers for both students on the cover page. Names should be complete and spelled correctly. If you as an individual are making the cover page, please get the information you need from your partner. For partners who are not both in the same lab section, please hand in the assignment to the collection box for the student whose last name comes first in alphabetical order. Due Dates The Due Date for this assignment is 3:3pm Friday, March. The Late Due Date is 3:3pm Monday, March 4. The penalty for handing in an assignment after the Due Date but before the Late Due Date is 3 marks. In other words, X/Y becomes (X 3)/Y if the assignment is late. There will be no credit for assignments turned in after the Late Due Date; they will be returned unmarked. Marking scheme B E F total 4 marks 4 marks 4 marks 4 marks 6 marks How to package and hand in your assignments Please see the Lab instructions.

ENCM 369 Winter 29 Lab 6 page 2 of Exercise : 6-bit two s complement and MIPS instructions Part I Here is a MIPS assembly language instruction to allocate 24 words on the stack: addiu $sp, $sp, -96 nswer the following questions:. What is the machine code for the instruction? Show how you obtained your answer, and express your answer in base two. 2. Suppose that before the instruction is run, $sp = x7fff_df4. 32-bit adder will compute the new value for $sp. What are the two 32-bit inputs to the adder, and what is the 32-bit output of the adder? Show how you obtained your answers, and express all your answers in base two. What to Hand In for Part I Hand in typed or neatly handwritten answers to questions and 2. Part II In Lab 5 Exercise B you saw that store and load instruction mnemonics like sw and sb could be used to make pseudoinstructions with labels as operands, such as sw $t, foo and sb $t8, str99 where foo and str99 were labels for data items in.data sections. Now let s consider a similar pseudoinstruction for a load operation: lw $s, bar Suppose that the address of bar is x3_9. It would be tempting to conclude that the pseudoinstruction could be turned into the following two real instructions, in a way similar to what was done in Lab 5 Exercise B: lui $at, x3 lw $s, some offset ($at). Explain why it is impossible to load from address x3_9 using the above two instructions, regardless of the value of some offset. (Hint: Remember that the offset in a load or store instruction is a signed 6-bit constant.) 2. Show how the pseudoinstruction can be implemented using an lui instruction followed by a real lw instruction. Express your answer in assembly language using a base ten offset in the lw instruction. (Hint: Use a negative offset.) What to Hand In for Part II Hand in typed or neatly handwritten answers to questions and 2.

ENCM 369 Winter 29 Lab 6 page 3 of Exercise B: Integer addition examples Read This First This is a pencil and paper exercise. Don t use a computer or a calculator. In this exercise, you get to add bit patterns as if you were an 8-bit processor, millions of times slower than electronic hardware. What to Do For each of the following pairs of hexadecimal patterns, write 8-bit binary patterns, and find the sum that would be generated by adding the patterns with an 8-bit adder. part a b part a b I x28 x64 III x28 x54 II xcc xa8 IV xf7 x For each part, do the following after calculating the sum: First interpret the numbers as two s-complement signed values. Decide if the addition resulted in signed overflow. Then interpret the numbers as unsigned values. Decide if the addition resulted in unsigned overflow. Show the work you did to generate the addition results and explain in each case how you decided whether overflow occurred. Exercise C: Scary facts about real-world C integer types Read This First key fact, emphasized in ENCM 369 lectures: Two s complement is by far the most common system for representing signed integers in computers. (This fact is not scary, but the next two are.) nother key fact, also emphasized in ENCM 369 lectures: Typical implementations of C and C++ will allow integer arithmetic to generate results that do not make sense according to normal, everyday mathematics; these implementations will not do anything special to alert programmers or users that results probably do not make sense. For example, it is quite easy to get a C program to add two int variables with positive values and generate a sum that is apparently negative. Here is a third key fact: C and C++ programming language standards do not exactly specify the numbers of bits that should be used for numerical types! Back in the early days of C, there were three signed integer types: short int, int, and long int. (There were also various unsigned types, and char, which was usually an 8-bit type, but which was signed on some systems and unsigned on others.) It may seem weird, but for a given platform, typically one of the following was true: short int and int were the same size, while long int was wider than int; short int was narrower than int, while long int and int were the same size.

ENCM 369 Winter 29 Lab 6 page 4 of Figure : Sizes for signed integer types on various platforms. long short long long Platform int int int int Typical Unix minicomputer or 6 bits 32 bits 32 bits n/a workstation, starting in early 98 s PC with MS-DOS and typical C 6 bits 6 bits 32 bits n/a compiler, starting in early 98 s Linux system with x86 6 bits 32 bits 32 bits 64 bits architecture Linux system with x86-64 6 bits 32 bits 64 bits 64 bits architecture Current and recent macos 6 bits 32 bits 64 bits 64 bits (64-bit) Current and recent Microsoft 6 bits 32 bits 32 bits 64 bits Windows (both 32- and 64-bit), with Microsoft compilers Cygwin64 running on top of Microsoft Windows 6 bits 32 bits 64 bits 64 bits Later a type called long long int became available; this type was usually 64 bits wide. Figure gives some size information for some C types on some important platforms. Now consider software development in the early 98 s. It would not have been uncommon for a programmer to write C code for an expensive Unix workstation, get an executable built and tested, then later copy the C source code to a cheaper PC running MS-DOS and try to build an executable for the PC. If values of ints could be expected to go beyond the range of a 6-bit type, the PC version of the program could fail in ways that were never seen on Unix, and that were either mysterious or just annoying, depending on how much the programmer knew about how int values were represented on the two different platforms. In 29, a similar problem can occur if programmers move code from one platform to another and are not careful to check on the width of the long int type the width is 64 bits for many current platforms, but only 32 bits for others. (By the way, the designers of the Java programming language had experience with the problems of a given C or C++ type having different sizes on different platforms. For Java there are strict rules such as, an int must be represented using 32-bit two s-complement, and a long must be represented using 64-bit two s-complement. ) What to Do Copy the directory encm369w9lab6/exc Do not yet make an executable and run it. Instead, carefully read the code in long_ints.c and develop predictions for the program output for the following cases: first, a platform on which long int is a 32-bit type; second, a platform on which long int is a 64-bit type. Here are a few facts which may be helpful: 2 3 =, 73, 74, 824 2 3 + 2 28 =, 342, 77, 28

ENCM 369 Winter 29 Lab 6 page 5 of 2 3 + 2 28 = 2, 45, 99, 4 2 3 2 28 =, 879, 48, 92 You can test your prediction for 64-bit long int by building and running executable on Cygwin64. For 32-bits, you can write a small Mars program that uses addu to add the integers 3427728 and 7374824, then print the sum. What to Hand In There is nothing to hand in. If it s not clear to you why the two programs produce the output they do, you can check an explanation that will be posted on the course lab solutions web page on or before February 26. Exercise D: 64-bit addition with 32-bit registers Read This First The material in Exercise C may raise a number of questions. One of them might be: How is a 64-bit integer type possible on a machine where the all the general-purpose registers (GPRs) are 32 bits wide? partial answer is: If 64-bit integer variables are to be in GPRs, each of those variables will need two GPRs; an operation such as addition cannot be done with a single instruction, so will need a sequence of instructions instead. Consider this situation on MIPS: i, j, and k are all 64-bit signed integer variables in a C program. Suppose registers are allocated this way: i: bits 3 in $s, bits 63 32 in $s j: bits 3 in $s2, bits 63 32 in $s3 k: bits 3 in $s4, bits 63 32 in $s5 How could the C statement k = i + j; be implemented in assembly language? Let s pretend that two untrue things are actually true. First, let s suppose that the MIPS addu instruction places the carry out of the most significant bit of the adder hardware into a special location within the processor called the carry bit. Second, let s suppose there is an instruction called addc ( add-with-carry ) that is exactly like addu, except that it takes the or in the carry bit as a carry into the least significant bit of the adder hardware. With those two pretended conditions in place, the 64-bit addition is simple: addu $s4, $s, $s2 addc $s5, $s, $s3 # get bits 3- of result # get bits 63-32 of result with # appropriate carry from bit 3 to 32 So why did I bother to explain how to solve the problem using fictional properties of the MIPS architecture? I did it because the carry bit and add-with-carry instructions are available on a wide range of important architectures, including x86 and RM, and, I would guess, most others, so this kind of solution is useful to know about. similar solution is usually available to allow 32-bit integer addition on architectures with 6-bit GPRs. What to Do Consider the problem of implementing the 64-bit addition of the Read This First section with real MIPS instructions.

ENCM 369 Winter 29 Lab 6 page 6 of. Find a solution that is a sequence of five instructions addu, another addu, addiu, beq, sltu, not in that exact order. Hint: Think about the condition to detect unsigned overflow in addition that happens if and only if the carry out of the most significant bit is. 2. Find another solution that is only four instructions in length, without any branches. Hint: Think about what possible bit patterns sltu could put into its destination register. Note that if you want to test your work using MRS, you can, but first try to convince yourself of the correctness of your work without actually writing a MRS program. What to Hand In There is nothing to hand in. Solutions will be posted on the course lab solutions web page no later than March 2. Exercise E: Integer subtraction examples Read This First n 8-bit adder can compute a b by inverting the bits of b and supplying a value of as the carry in to the least significant bit. For example, if a is _ (9 in base ten) and b is _ (4 in base ten), here s how the subtraction works: carry in: ----------------------------- bits of a: inverted bits of b: ----------------------------- result: Note that the correct result (5 in base ten) is produced. What to Do Like Exercise B, this is a pencil and paper exercise. Don t use a computer or a calculator. For each of the following pairs of hexadecimal patterns, write 8-bit binary patterns, and find the 8-bit subtraction result a b. s in Exercise B, identify cases where signed overflow has occurred and cases where unsigned overflow has occurred. part a b part a b I x48 xfe III x9 xf II x6 xe IV xfe xf7 Show the work you did to generate the subtraction results and explain in each case how you decided whether signed overflow and/or unsigned overflow has occurred. Exercise F: Review of D Flip-Flops Read This First D flip-flops (DFFs) were covered in ENEL 353. They are very important building blocks for the processor designs that we will study in lectures starting on February 5.

ENCM 369 Winter 29 Lab 6 page 7 of Figure 2: Summary of D flip-flop behaviour. Nothing about digital logic design is more important than this! Getting this wrong in any way should be considered to be just as serious a mistake as writing an incorrect truth table for an inverter, an OR gate, or an ND gate. clock signal... time positive edge negative edge positive edge negative edge positive edge positive-edgetriggered DFF negative-edgetriggered DFF D Q D Q Q copies D on rising edges of. Q copies D on falling edges of Very shortly after an active clock edge, Q takes on the value D had just before that clock edge; Q then holds that value until the next active clock edge. The critical thing to understand about a DFF is that its state Q can change only in response to an active edge of its clock input. For positive-edge-triggered DFFs (the kind we saw a lot in ENEL 353) the active edge of the clock is the rising edge a low-to-high transition; for negative-edge-triggered DFFs (which we did not see much in ENEL 353), the active edge of the clock is the falling edge a high-to-low transition. Behaviour of DFFs is summarized in Figure 2. Knowing how a DFF responds as a black box to its clock and D inputs is essential in understanding sequential logic designs. On the other hand, knowing what is inside a DFF is not very important at all, unless your job is designing DFFs to meet specifications such as high speed, low chip area, and low power consumption. Figure 3 shows a classic design for a DFF that was presented in ENEL 353. Don t worry if you don t understand how it works that s not important in ENCM 369. (Note also that DFFs in modern CMOS integrated circuits don t use NND gates at all typically DFFs are built from inverters and devices called transmission gates, which we did not study in ENEL 353.)

ENCM 369 Winter 29 Lab 6 page 8 of Figure 3: Positive-edge-triggered D flip-flop built from two NND-based D latches. Knowing exactly how this circuit works will NOT help you at all in ENCM 369! It is infinitely more important to understand what is meant by the text in Figure 2! D Q Q Example problem. (This was a problem on the December 22 Final Exam in ENEL 353.) Complete the timing diagram: B B Solution to example problem. Before drawing waveforms, a very small amount of analysis is required: The DFFs are positive-edge-triggered, so the dotted lines dropping from negative edges of the clock are irrelevant and should be ignored. For the FF that has as its output, the D input is B. (I am assuming you have not forgotten what an inverter does!) That means that just after a positive clock edge, will take on the value B had just before that edge. In the notation of the textbook used for ENEL 353 and ENCM 369 this year and for the previous few years = B. For the FF that has B as its output, is wired directly to the D input. So B =. This analysis leads to the solution in Figure 4. What to Do Print a copy of page of this document. In the spaces beneath each of the two given circuits, write next-state equations for the circuit. In Part I, that means equations giving Q and Q in terms of Q and Q. In Part II, that means equations giving Q, Q and Q 2 in terms of Q, Q, Q 2 and the input. Then complete the given timing diagrams. Be very careful to check which clock edges are active for the given DFFs. What to Hand In Hand in your completed worksheet.

ENCM 369 Winter 29 Lab 6 page 9 of Figure 4: Solution to example DFF problem. Moving left to right, each time you encounter a positive clock edge, use values of signals just before the edge to find the values the FF outputs will take on after the edge. B = B = B = = = B = B = = = B = B = =

ENCM 369 Winter 29 Lab 6 page of Worksheet for Exercise F Part I Q Q Q Q Part II Q Q Q 2 Q Q Q 2