CSE 2021: Computer Organization

Similar documents
Previously. CSE 2021: Computer Organization. Memory Organization. The Load/Store Family (1) 5/26/2011. Used to transfer data to/from DRAM.

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

CSE 2021: Computer Organization

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

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

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

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

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

Problem 3: Theoretical Questions: Complete the midterm exam taken from a previous year attached at the end of the assignment.

The MIPS Instruction Set Architecture

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

F. Appendix 6 MIPS Instruction Reference

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved.

MIPS Reference Guide

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

MIPS Instruction Reference

Compiling Techniques

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

Computer Architecture. The Language of the Machine

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

Examples of branch instructions

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

M2 Instruction Set Architecture

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

TSK3000A - Generic Instructions

Assembly Programming

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Computer Architecture. MIPS Instruction Set Architecture

Flow of Control -- Conditional branch instructions

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

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

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

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

Thomas Polzer Institut für Technische Informatik

ECE Exam I February 19 th, :00 pm 4:25pm

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

Adventures in Assembly Land

CDA3100 Midterm Exam, Summer 2013

MIPS Instruction Set

SPIM Instruction Set

ECE 30 Introduction to Computer Engineering

CSc 256 Midterm (green) Fall 2018

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

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

MIPS Assembly Language. Today s Lecture

Lec 10: Assembler. Announcements

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

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

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Lecture 7: Examples, MARS, Arithmetic

NAME: 1. (2) What is a transistor?

Reduced Instruction Set Computer (RISC)

MIPS Instruction Format

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

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

ECE 15B Computer Organization Spring 2010

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

MIPS Instruction Set Architecture (2)

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

MIPS Assembly Language

CPS311 - COMPUTER ORGANIZATION. A bit of history

Chapter 2. Instructions:

Course Administration

Lecture 6 Decision + Shift + I/O

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

Reduced Instruction Set Computer (RISC)

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

Programming the processor

CSc 256 Midterm 2 Fall 2011

Chapter 2. Instructions: Language of the Computer

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Machine Instructions - II. Hwansoo Han

Computer Organization Lab #3.

MIPS function continued

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address.

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

Lecture 4: MIPS Instruction Set

Week 10: Assembly Programming

We will study the MIPS assembly language as an exemplar of the concept.

CS3350B Computer Architecture MIPS Instruction Representation

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 9 December 2015

Computer Architecture

Review of instruction set architectures

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

2.7 Supporting Procedures in hardware. Why procedures or functions? Procedure calls

Computer Systems and Architecture

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

CSc 256 Midterm 2 Spring 2012

CS 61c: Great Ideas in Computer Architecture

COMPUTER ORGANIZATION AND DESIGN

Transcription:

CSE 2021: Computer Organization Lecture-6 Code Translation-4 Review & Exercises Shakil M. Khan (adapted from Prof. Roumani)

MIPS Assembly Language (Summary) 32X32 bits Registers ($s0 - $s7, $t0 - $t9, $zero, ) Arithmetic and logical instructions (add, sub, mult, div, slt, sll, srl, sra, the i/u/v suffix) Jump and branch (j, beq, bne) Load and store (lb, lh, lw, sb, sw, sh, the u suffix) I/O (syscall) Static attributes and.data (directives:.byte,.half,.word,.ascii,.asciiz,.space),.globl,.text Procedures (jal, jr, $v0 - $v1, $a0 - $a3, $ra) Stack ($sp, $fp) Heap (syscall 9) lui, mfhi, mflo, Some pseudo-instructions (la, mul, ) CSE-2021 June-14-2012 2

MIPS Assembly Language (Summary) MIPS instruction formats (R-type, I-type, J-type) MIPS addressing modes (immediate, register, base, PCrelative, pseudo-direct) Next: Concurrent data access (ll, sc) Translating (compiler + assembly) and object files Linking (static vs. dynamic) and loading Translating and starting up in Java (JVM, JIT compiler) CSE-2021 June-14-2012 3

Pseudo Instructions Not real, merely conveniences added by the assembler Not portable: have no machine language encoding Examples: mul mult + mfhi nop sll $0, $0, 0 li/la ori + lui abs slt + beq + sub + $at move add + $zero blt slt + bne + $at Do NOT use pseudo in this course! CSE-2021 June-14-2012 4

Exercise 1 Method pofu (product overflow unsigned) detects O/F in the mult of unsigned integers. It takes two integers in $a0 and $a1 and returns $v0 = 0 or 1 if $a0*$a1 fits or does not fit in 32 bits. Is it correct? If not, fix it. pofu: multu $a0, $a1 mfhi $t0 beq $t0, $0, fits addi $v0, $0, 1 fits: add $v0, $0, $0 jr $ra CSE-2021 June-14-2012 5

Exercise 2 Method pof is similar to pofu except it deals with signed integers. One quick way to implement pof would be to copy and paste pofu and then replace the label pofu with pof and the instruction multu with mult. Would this be correct? If not, fix it. CSE-2021 June-14-2012 6

Exercise 3(a) lib.s (below) was loaded with.text at 0x0040002C and.data at 0x10010000. What is the address of x?.globl x.globl ch.data x:.byte 3 y:.word 4.text ch: lw $v0, y($0) jr $ra CSE-2021 June-14-2012 7

Exercise 3(b) lib.s (below) was loaded with.text at 0x0040002C and.data at 0x10010000. What is the address of y? Why?.globl x.globl ch.data x:.byte 3 y:.word 4.text ch: lw $v0, y($0) jr $ra CSE-2021 June-14-2012 8

Exercise 3(c) lib.s (below) was loaded with.text at 0x0040002C and.data at 0x10010000. What is the address of ch?.globl x.globl ch.data x:.byte 3 y:.word 4.text ch: lw $v0, y($0) jr $ra CSE-2021 June-14-2012 9

Exercise 4(a) The file app.s (below) was loaded immediately after lib.s. What is the address of main?.text main: sw $ra, 0($sp) addi $sp, $sp, -4 jal ch lb $t0, x($0) hint: the assembler replaces lw/sw with several instructions CSE-2021 June-14-2012 10

Exercise 4(b) The file app.s (below) was loaded immediately after lib.s. What is the machine language encoding of the instruction: jal ch?.text main: sw $ra, 0($sp) addi $sp, $sp, -4 jal ch lb $t0, x($0) CSE-2021 June-14-2012 11

Exercise 5 Argue that stack allocations are not likely to cause memory leaks but that heap allocations are Factors: scope in which push/pop appear versus allocate/de-allocate consequences of imbalanced push/pop versus a missing de-allocate CSE-2021 June-14-2012 12

Exercise 6 Assume that the word 0x01048025 represents an instruction. What is the corresponding assembly language instruction? Your answer must use register names, e.g. $t0, not register numbers, and must specify immediate s in decimal, not binary. CSE-2021 June-14-2012 13

Exercise 7(a) To handle a large 32-bit immediate X, we replace lw $t0, X($a0) with the four instructions below: lui $at, upper16_x ori $at, $at, lower16_x add $at, $at, $a0 lw $t0, 0($at) Why can t the second be addi instead of ori? CSE-2021 June-14-2012 14

Exercise 7(b) To handle a large 32-bit immediate X, we replace lw $t0, X($a0) with the four instructions below: lui $at, upper16_x ori $at, $at, lower16_x add $at, $at, $a0 lw $t0, 0($at) Can you do it with just three instructions? CSE-2021 June-14-2012 15

Exercise 8 Given the utility class:.globl work.text work: slt $t0, $a0, $a1 bne $t0, $0, less add $v0, $a0, $a1 j done less: sub $v0, $a0, $a1 done: jr $ra What are the outputs of the following apps: CSE-2021 June-14-2012 16

Exercise 8(a).text main: sw $ra, 0($sp) addi $sp, $sp, -4 addi $a0, $0, 3 addi $a1, $0, 8 jal work add $a0, $v0, $0 addi $v0, $0, 1 syscall addi $sp, $sp, 4 lw $ra, 0($sp) jr $ra CSE-2021 June-14-2012 17

Exercise 8(b).text main: sw $ra, 0($sp) addi $sp, $sp, -4 addi $a0, $0, 36 addi $a1, $0, 8 sb $a0, work($a1) jal work add $a0, $v0, $0 addi $v0, $0, 1 syscall addi $sp, $sp, 4 lw $ra, 0($sp) jr $ra CSE-2021 June-14-2012 18

Exercise 9(a) What is the value of $s0 after executing label A? Write down the value of $s1 after executing label B.data x:.word 10 y:.byte 4, 3, 2 p:.word y.text main: addi $t0, $0, -4 A: lw $s0, p($t0) addi $t0, $0, 3 B: lb $s1, y($t0) jr $ra CSE-2021 June-14-2012 19

Exercise 9(b) What is the value of $s2 after executing label D? What is the value of $s3 after executing label E?.data x:.word 10 y:.byte 4, 3, 2 p:.word y.text main: addi $t0, $0, 1 addi $s2, $0, -3 C: sb $s2, y($t0) D: lb $s2, y($t0) E: lbu $s3, y($t0) jr $ra CSE-2021 June-14-2012 20

Exercise 10(a) Write the method clone that copies a given array of bytes to a new array. Specifically, it receives in $a0 the number of elements in the array and in $a1 the address of its first element. The method should allocate enough space on the heap to store the copy and then copy the array and return in $v0 the address of the first element of the copy. CSE-2021 June-14-2012 21

Exercise 10(b).data array1:.byte 1,2,11,4,5 array2:.space 5 Write a main method that: uses clone to copy array1 to the heap copies the content of the heap to array2 (cf. posted programs on the web) CSE-2021 June-14-2012 22