# ICS 233 Computer Architecture & Assembly Language

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 ICS 233 Computer Architecture & Assembly Language Assignment 3 SOLUTION: Procedures in MIPS Assembly Language For the following problems, the table holds C code functions. Assume that the first function listed in the table is called first. You will be asked to translate these C code routines into MIPS assembly. int compare(int a, int b) { if (sub(a, b) >= 0) return 1; else return 0; int sub(int a, int b) { return a b; int fib_iter(int a, int b, int n) { if (n == 0) return b; else return fib_iter(a+b, a, n-1); 1. Implement the C code in the table in MIPS assembly. What is the total number of MIPS instructions needed to execute the function? compare: addi \$sp, \$sp, 4 # allocate frame = 4 bytes jal sub # call sub li \$t0, 0 # result = 0 bltz \$v0, exit # if sub(a,b)<0 goto exit li \$t0, 1 # result = 1 exit: move \$v0, \$t0 # \$v0 = result addi \$sp, \$sp, 4 # free stack frame sub: sub \$v0, \$a0, \$a1 # result = a - b # return to caller 11 or 12 instructions (depending whether bltz is taken or not). Includes the call and return from sub Page 1 of 7

2 int fib_iter(int a, int b, int n) { if (n == 0) return b; else return fib_iter(a+b, a, n-1); fib_iter: bne \$a2, \$0, else # if (n!= 0) goto else move \$v0, \$a1 # result = b else: addiu \$sp, \$sp, 4 # allocate frame = 4 bytes move \$t0, \$a0 addu \$a0, \$a0, \$a1 # \$a0 = a+b move \$a1, \$t0 # \$a1 = a addiu \$a2, \$a2, -1 # \$a2 = n-1 jal fib_iter # recursive call addiu \$sp, \$sp, 4 # free stack frame Total number of instructions = n * instructions for each recursive call/return (if n>0) +3 instructions if (n == 0) 2. Functions can often be implemented by compilers in line. An in line function is when the body of the function is copied into the program space, allowing the overhead of the function call to be eliminated. Implement an in line version of the above C code in MIPS assembly. What is the reduction in the total number of MIPS assembly instructions needed to complete the function? compare: sub \$t0, \$a0, \$a1 li \$v0, 0 bltz \$t0, exit li \$v0, 1 exit: 4 or 5 instructions (whether bltz is taken or not) Due to recursive nature of the code, not possible for the compiler to in-line the function call. Page 2 of 7

5 6. The MIPS assembly program above computes the Fibonacci of a given input. The integer input is passed through register \$a0, and the result is returned in register \$v0. In the assembly code, there are few errors. Correct the MIPS errors. 7. For the recursive Fibonacci MIPS program above, assume that the input is 4. Rewrite the Fibonacci program to operate in a non recursive manner. Restrict your register use to registers \$s0 \$s7. What is the total number of instructions used to execute your nonrecursive solution versus the recursive version of the factorial program? According to MIPS convention, we should preserve \$s0 and \$1. We could have used \$t0 and \$t1 without preserving their values. For input 4, we have 23 instructions in non-recursive Fib versus 73 instructions to execute recursive Fi fib: addiu \$sp, \$sp, 8 # allocate stack frame sw \$s0, 0(\$sp) # save \$s0 sw \$s1, 4(\$sp) # save \$s1 li \$s0, 1 # prev value in Fib sequence li \$v0, 1 # curr value in Fib sequence blt \$a0, 3, EXIT # if (n < 3) goto exit LOOP: addu \$s1, \$v0, \$s0 # next = curr + prev move \$s0, \$v0 # prev = curr move \$v0, \$s1 # curr = next addiu \$a0, \$a0, 1 # n = n - 1 bge \$a0, 3, LOOP # Loop if (n >= 3) EXIT: lw \$s0, 0(\$sp) # restore \$s0 lw \$s1, 4(\$sp) # restore \$s1 addiu \$sp, \$sp, 8 # free stack frame Page 5 of 7

6 In this exercise, you will be asked to write a MIPS assembly program that converts strings into the number format as specified in the table. Positive integer decimal string String of hexadecimal digits 8. Write a program in MIPS assembly language to convert an ASCII number string with the conditions listed in the table above, to an integer. Your program should expect register \$a0 to hold the address of a null terminated string containing some combination of the digits 0 though 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register \$v0. If a nondigit character appears anywhere in the string, your program should stop with the value 1 in register \$v0. str2int: # convert string to integer li \$t6, 0x30 # \$t6 = '0' li \$t7, 0x39 # \$t7 = '9' li \$v0, 0 # initialize \$v0 = 0 move \$t0, \$a0 # \$t0 = pointer to string lb \$t1, (\$t0) # load \$t1 = digit character LOOP: blt \$t1, \$t6, NoDigit # char < 0 bgt \$t1, \$t7, NoDigit # char > 9 subu \$t1, \$t1, \$t6 # convert char to integer mul \$v0, \$v0, 10 # multiply by 10 add \$v0, \$v0, \$t1 # \$v0 = \$v0 * 10 + digit addiu \$t0, \$t0, 1 # point to next char lb \$t1, (\$t0) # load \$t1 = next digit bne \$t1, \$0, LOOP # branch if not end of string # return integer value NoDigit: li \$v0, -1 # return -1 in \$v0 Page 6 of 7

7 hexstr2int: # convert hex string to int li \$t4, 0x41 # \$t4 = 'A' li \$t5, 0x46 # \$t7 = 'F' li \$t6, 0x30 # \$t6 = '0' li \$t7, 0x39 # \$t7 = '9' li \$v0, 0 # initialize \$v0 = 0 move \$t0, \$a0 # \$t0 = pointer to string lb \$t1, (\$t0) # load \$t1 = digit character LOOP: blt \$t1, \$t6, NoDigit # char < 0 bgt \$t1, \$t7, HEX # check if hex digit subu \$t1, \$t1, \$t6 # convert to integer j Compute # jump to Compute integer HEX: blt \$t1, \$t4, NoDigit # char < A bgt \$t1, \$t5, NoDigit # char > F addiu \$t1, \$t1, -55 # convert: A =10, B =11,etc sll \$v0, \$v0, 4 # multiply by 16 add \$v0, \$v0, \$t1 # \$v0 = \$v0 * 16 + digit addiu \$t0, \$t0, 1 # point to next char lb \$t1, (\$t0) # load \$t1 = next digit bne \$t1, \$0, LOOP # branch if not end of string # return integer value NoDigit: li \$v0, -1 # return -1 in \$v0 Page 7 of 7

### Lecture 3: MIPS Instruction Set

Lecture 3: MIPS Instruction Set Today s topic: More MIPS instructions Procedure call/return Reminder: Assignment 1 is on the class web-page (due 9/7) 1 Memory Operands Values must be fetched from memory

### Typy danych. Data types: Literals:

Lab 10 MIPS32 Typy danych Data types: Instructions are all 32 bits byte(8 bits), halfword (2 bytes), word (4 bytes) a character requires 1 byte of storage an integer requires 1 word (4 bytes) of storage

### MIPS Hello World. MIPS Assembly 1

MIPS Hello World MIPS Assembly 1 # Hello, World!.data ## Data declaration section ## String to be printed: out_string:.asciiz "\nhello, World!\n".text ## Assembly language instructions go in text segment

### Lecture 4. Announcements:

Announcements: Lecture 4 HW1 posted on Saturday morning. We gave a little over a week. We are going to discuss relevant material over the next two lectures. Lab1 posted. But if you start doing it, you

### Mips Code Examples Peter Rounce

Mips Code Examples Peter Rounce P.Rounce@cs.ucl.ac.uk Some C Examples Assignment : int j = 10 ; // space must be allocated to variable j Possibility 1: j is stored in a register, i.e. register \$2 then

### Loop Example. CMPE 325 Computer Architecture II. Loop Solution. Loops in C. Improved Loop Solution. Loop Efficiency. Assembly Language (cont)

CMPE 325 Computer rchitecture II Cem Ergün Eastern Mediterranean University ssembly Language (cont) Loop Example Consider the code where array is an integer array with 100 elements Loop: g = g + [i] i

### Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9.

Code Generation I Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9.7 Stack Machines A simple evaluation model No variables

### Example: Array Access

ECE232: Hardware Organization and Design Part 7: MIPS Instructions III http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Example: Array Access

### Quiz for Chapter 2 Instructions: Language of the Computer3.10

Date: 3.10 Not all questions are of equal difficulty. Please review the entire quiz first and then budget your time carefully. Name: Course: Solutions in Red 1. [5 points] Prior to the early 1980s, machines

### ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Thursday, October 10 (100 points)

ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Thursday, October 10 (100 points) Objectives: Get familiar with MIPS instructions Assemble, execute and debug MIPS assembly

### Assignment 2 Solutions Instruction Set Architecture, Performance, Spim, and Other ISAs

Assignment 2 Solutions Instruction Set Architecture, Performance, Spim, and Other ISAs Alice Liang Apr 18, 2013 Unless otherwise noted, the following problems are from the Patterson & Hennessy textbook

### Winter 2002 MID-SESSION TEST Friday, March 1 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 2002 MID-SESSION TEST Friday,

### Machine Code. How the Assembler Works

1 / 32 Machine Code -and- How the Assembler Works Mar 8 13, 2013 2 / 32 Outline What is machine code? RISC vs. CISC MIPS instruction formats Assembling basic instructions R-type instructions I-type instructions

### Lecture 5: MIPS Examples

Lecture 5: MIPS Examples Today s topics: the compilation process full example sort in C Reminder: 2 nd assignment will be posted later today 1 Dealing with Characters Instructions are also provided to

### Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I)

Lecture Outline Code Generation (I) Stack machines The MIPS assembl language Adapted from Lectures b Profs. Ale Aiken and George Necula (UCB) A simple source language Stack- machine implementation of the

### The University of Nottingham

The University of Nottingham School of Computer Science A Level 1 Module, Autumn Semester 2007-2008 Computer Systems Architecture (G51CSA) Time Allowed: TWO Hours Candidates must NOT start writing their

### Computer Systems Architecture

Computer Systems Architecture http://cs.nott.ac.uk/ txa/g51csa/ Thorsten Altenkirch and Liyang Hu School of Computer Science University of Nottingham Lecture 10: MIPS Procedure Calling Convention and Recursion

### MIPS Architecture 32-bit processor, MIPS instruction size: 32 bits. Registers: Data formats: Instruction set:

MIPS Architecture 32-bit processor, MIPS instruction size: 32 bits. Registers: 1. 32 registers, notation \$0, \$1, \$31 \$0: always 0. \$31: return address. \$1, \$26, \$27, \$28, \$29 used by OS and assembler.

### Chapter 2: MIPS Instruction Set (cont d)

Chapter 2: MIPS Instruction Set (cont d) 1 Review Instruction Meaning add \$s1,\$s2,\$s3 \$s1 = \$s2 + \$s3 sub \$s1,\$s2,\$s3 \$s1 = \$s2 \$s3 addi \$s1,\$s2,4 \$s1 = \$s2 + 4 ori \$s1,\$s2,4 \$s2 = \$s2 4 lw \$s1,100(\$s2)

### 7. MIPS Instruction Set Architecture

CSEE 3827: Fundamentals of Computer Systems, Spring 2011 7. MIPS Instruction Set Architecture Prof. Martha Kim (martha@cs.columbia.edu) Web: http://www.cs.columbia.edu/~martha/courses/3827/sp11/ Outline

### 5 MIPS Assembly Language

103 5 MIPS Assembly Language Today, digital computers are almost exclusively programmed using high-level programming languages (PLs), eg, C, C++, Java The CPU fetch execute cycle, however, is not prepared

### a. Chapter 1: Exercises: =>

Selected Solutions to Problem-Set #1 COE608: Computer Organization and Architecture Introduction, Instruction Set Architecture and Computer Arithmetic Chapters 1, 2 and 3 a. Chapter 1: Exercises: 1.1.1

### Chapter 3 MIPS Assembly Language Morgan Kaufmann Publishers

Chapter 3 MIPS Assembly Language 1 Review MIPS instruction:fixed instruction size(32bit) and 3 simple formats bne or beq: R type or I-type? Using slt and beq to simulate branch if less than pseudo instruction

### We also introduced the MIPS processor and its instructions

5JJ70 Computation Implementatie van rekenprocessen Translate C into MIPS assembly Henk Corporaal December 2009 Welcome So far we covered almost all of C, and a large part of C++ We also introduced the

### The Program Counter. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

1 The Program Counter PC = 0040003c EPC = 00000000 Cause = 00000000 BadVAddr= 00000000 Status = 3000ff10 HI = 00000000 LO = 00000000 General Registers R0 (r0) = 00000000 R8 (t0) = 00000000 R16 (s0) = 00000000

### MIPS Assembly Code Layout

Learning MIPS & SPIM MIPS assembly is a low-level programming language The best way to learn any programming language is to write code We will get you started by going through a few example programs and

### Integer Multiplication and Division

6 Integer Multiplication and Division 6.1 Objectives After completing this lab, you will: Understand binary multiplication and division Understand the MIPS multiply and divide instructions Write MIPS programs

### MIPS Memory Organization

MIPS Memory Organization 1 In addition to memory for static data and the program text (machine code), MIPS provides space for the run-time stack (data local to procedures, etc.) and for dynamically-allocated

### A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Other architectures Example. Accumulator-based machines A single register, called the accumulator, stores the operand before the operation, and stores the result after the operation. Load x # into acc

### Translating C code to MIPS

Translating C code to MIPS why do it C is relatively simple, close to the machine C can act as pseudocode for assembler program gives some insight into what compiler needs to do what's under the hood do

### Instructions: Assembly Language

Chapter 2 Instructions: Assembly Language Reading: The corresponding chapter in the 2nd edition is Chapter 3, in the 3rd edition it is Chapter 2 and Appendix A and in the 4th edition it is Chapter 2 and

### Char Dec Oct Hex Char Dec Oct Hex Char Dec Oct Hex Char Dec Oct Hex

Table of ASCII Characters This table lists the ASCII characters and their decimal, octal and hexadecimal numbers. Characters which appear as names in parentheses (e.g., (nl)) are non-printing characters.

### CS 64 Lecture 5: Decision Instruc4ons

CS 64 Lecture 5: Decision Instruc4ons So Far Basic Arithme4c add, sub, addi, mult, div Load memory: lw \$s0, 8(\$t0) Store memory: sw \$s0, - 8 (\$t0) Q1 What opera4on copies data from main memory to a register

### More MIPS: Recursion. Computer Science 104 Lecture 9

More MIPS: Recursion Computer Science 104 Lecture 9 Admin Homework Homework 1: graded. 50% As, 27% Bs Homework 2: Due Wed Midterm 1 This Wed 1 page of notes 2 Last time What did we do last time? 3 Last

### Basic Computer Organization

SE 292 (3:0) High Performance Computing L2: Basic Computer Organization R. Govindarajan govind@serc Basic Computer Organization Main parts of a computer system: Processor: Executes programs Main memory:

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

### COMP MIPS instructions 3 Feb. 10, 2016

In the past two lectures, we discussed MIPS operations on integers. Today we will consider a few data structures that you are familiar with, namely arrays and strings, and discuss how to implement them

### CSCI-365 Computer Organization

CSCI-365 Computer Organization Lecture 4 Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson & Hennessy, 2005 Some slides and/or pictures in

### As in high level languages, when programming in assembly language you should split up your program into smaller functions, that you can reuse.

jal and jr Functions and register conventions Slide 1 Stacks Implementing Stacks on the MIPS As in high level languages, when programming in assembly language you should split up your program into smaller

### MIPS ISA-II: Procedure Calls & Program Assembly

MIPS ISA-II: Procedure Calls & Program Assembly Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions Review memory organization Memory (data movement) instructions

### MIPS Introduction. Reading: Chapter 3. Appendix A. Language of the Machine. More primitive than higher level languages

MIPS Introduction Reading: Chapter 3. Appendix A. Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow such as for and while only simple branch, jump,

### COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December 2009 23:59

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December 2009 23:59 Overview: In the first projects for COMP 303, you will design and implement a subset of the MIPS32 architecture

### MIPS Calling Convention

MIPS Calling Convention This document summarizes the calling conventions that we expect you to use in ECE 314 for homework problems and assembly language programming projects. These are the rules for how

### Assembly Language Convention Guide

Intro Computer Systems Van Hentenryck Conventions are especially important in assembly code. Unlike higher-level languages, which provide inherent structure through branches, loops, and functions, assembly

### A Quick Start Guide to CS/COE 0447 Informal discussion about basic concepts

A Quick Start Guide to CS/COE 0447 Informal discussion about basic concepts We ll refine and more formally define many of this material over the next few weeks!!! Digital Computer Stores information and

### Introduction to MIPS Assembly Programming

1 / 26 Introduction to MIPS Assembly Programming January 23 25, 2013 2 / 26 Outline Overview of assembly programming MARS tutorial MIPS assembly syntax Role of pseudocode Some simple instructions Integer

### MIPS: The Virtual Machine

2 Objectives After this lab you will know: what synthetic instructions are how synthetic instructions expand to sequences of native instructions how MIPS addresses the memory Introduction MIPS is a typical

### Array Declaration and Storage Allocation

Array Declaration and Storage Allocation The first step is to reserve sufficient space for the array: 1.data list:.space 1000 # reserves a block of 1000 bytes This yields a contiguous block of bytes of

### Computer Systems Architecture

Computer Systems Architecture http://cs.nott.ac.uk/ txa/g51csa/ Thorsten Altenkirch and Liyang Hu School of Computer Science University of Nottingham Lecture 11: Pointers and References What does the following

### Review 1/2. CS61C Characters and Floating Point. Lecture 8. February 12, Review 2/2 : 12 new instructions Arithmetic:

Review 1/2 CS61C Characters and Floating Point Lecture 8 February 12, 1999 Handling case when number is too big for representation (overflow) Representing negative numbers (2 s complement) Comparing signed

### CS107 Handout 12 Spring 2008 April 18, 2008 Computer Architecture: Take I

CS107 Handout 12 Spring 2008 April 18, 2008 Computer Architecture: Take I Computer architecture Handout written by Julie Zelenski and Nick Parlante A simplified picture with the major features of a computer

### Machine code generation

Machine-Code Generation Cosmin Oancea cosmin.oancea@diku.dk December 2012 Structure of a Compiler Programme text Lexical analysis Binary machine code Symbol sequence Assembly and linking Syntax analysis

### An Introduction to Assembly Programming with the ARM 32-bit Processor Family

An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2

### CS 430 Computer Architecture. Decisions in C/Assembly Language. William J. Taffe. David Patterson

CS 430 Computer Architecture Decisions in C/Assembly Language William J. Taffe using notes of David Patterson 1 Review (1/2) In MIPS Assembly Language: Registers replace C variables One Instruction (simple

### Assemblers, Linkers, and the SPIM Simulator

A A P P E N D I X Assemblers, Linkers, and the SPIM Simulator Fear of serious injury cannot alone justify suppression of free speech and assembly. Louis Brandeis Whitney v. California, 1927 James R. Larus

### CS 104 PRACTICE Midterm Exam 1

CS 104 PRACTICE Midterm Exam 1 This is a full length practice midterm exam. If you want to take it at exam pace, give yourself 75 minutes to take the entire test. Just like the real exam, each question

### Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Instruction Set Architecture or How to talk to computers if you aren t in Star Trek The Instruction Set Architecture Application Compiler Instr. Set Proc. Operating System I/O system Instruction Set Architecture

### Chapter 3. lw \$s1,100(\$s2) \$s1 = Memory[\$s2+100] sw \$s1,100(\$s2) Memory[\$s2+100] = \$s1

Chapter 3 1 MIPS Instructions Instruction Meaning add \$s1,\$s2,\$s3 \$s1 = \$s2 + \$s3 sub \$s1,\$s2,\$s3 \$s1 = \$s2 \$s3 addi \$s1,\$s2,4 \$s1 = \$s2 + 4 ori \$s1,\$s2,4 \$s2 = \$s2 4 lw \$s1,100(\$s2) \$s1 = Memory[\$s2+100]

### Some Samples of MIPS Assembly Language. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Some Samples of MIPS Assembly Language Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Structure of This Lecture This lecture will be built around a number

### High level language programs versus Machine code

High level language programs versus Machine code You all have experience programming in a high level language. You know that when you write a program in a language such as C or Java, the program is nothing

### Local workspace of a subroutine: Recursion and recursive subroutines:

Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary private variables used in addition to available data registers. Recursion and recursive

### System Programming. The SPIM S20 MIPS Simulator

Sep 06 Hugo Marcondes (http://www.lisha.ufsc.br) 1 System Programming The SPIM S MIPS Simulator Hugo Marcondes hugom@lisha.ufsc.br http://www.lisha.ufsc.br/~hugom Sep 06 Sep 06 Hugo Marcondes (http://www.lisha.ufsc.br)

### COMP15111: Examples5 (2016)

COMP15111 2016 Javier Navaridas/Richard Neville/Milan Mihajlovic Examples 5 section 1: 1 COMP15111: Examples5 (2016) You can find old Computer-Science exam papers via: http://www.cs.manchester.ac.uk/assessment/exam

### CSSE 232 Computer Architecture I Rose-Hulman Institute of Technology Computer Science and Software Engineering Department. Homework 1 Solutions

CSSE 232 Computer Architecture I Rose-Hulman Institute of Technology Computer Science and Software Engineering Department Homework 1 Solutions 1. (10 points) Please pay attention to this question. The

### MIPS Assembler and Simulator

MIPS Assembler and Simulator Reference Manual Last Updated, December 1, 2005 Xavier Perséguers (ing. info. dipl. EPF) Swiss Federal Institude of Technology xavier.perseguers@a3.epfl.ch Preface MIPS Assembler

### Instruction Set Architecture

Instruction Set Architecture Consider x := y+z. (x, y, z are memory variables) 1-address instructions 2-address instructions LOAD y (r :=y) ADD y,z (y := y+z) ADD z (r:=r+z) MOVE x,y (x := y) STORE x (x:=r)

### Roll Call. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas. Lecture #17: Final Session on SPIM; Bonus Set

Roll Call 1 Requirements for Test #3 Exemption 1. No unexcused absences to end of semester (written excuse required must be MD-verified illness or work-related, with written excuse from supervisor). 2.

### Computer Systems Architecture

Computer Systems Architecture http://cs.nott.ac.uk/ txa/g51csa/ Thorsten Altenkirch and Liyang Hu School of Computer Science and IT University of Nottingham Lecture 04: Machine Code, Data Transfer and

### Lecture 6 Machine language designed for the common case

Lecture 6 Machine language, the binary representation for instructions. We ll see how it is designed for the common case Fixed-sized (32-bit) instructions Only 3 instruction formats Limited-sized immediate

### Figure 1: Graphical example of a mergesort 1.

CSE 30321 Computer Architecture I Fall 2011 Lab 02: Procedure Calls in MIPS Assembly Programming and Performance Total Points: 100 points due to its complexity, this lab will weight more heavily in your

### CSE 378 Quiz Section #2 Coding in MIPS Assembly

Let s translate this C function into assembly: CSE 378 Quiz Section #2 Coding in MIPS Assembly int arr[10] = {1,2,3,4,5,6,7,8,9,10; int compute_smth() { int i, sum=0; for (i = 0; i < 10; i++) { printf(

### Architecture des Ordinateurs I

Architecture des Ordinateurs I Instruction Set Architectures Paolo.Ienne@epfl.ch EPFL I&C LAP Reminder: New Language Assembly Instructions 0 mov \$r1, 0x123456 # \$r1 data 1 mov \$r2, 0 # \$r2 result 2 mov

### MIPS Assembly Language Programming. Robert Britton Computer Science Department California State University, Chico Chico, California

MIPS Assembly Language Programming Robert Britton Computer Science Department California State University, Chico Chico, California Instructors are granted permission to make copies of this beta version

### Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

7 Objectives After completing this lab you will: know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine Introduction Branches and jumps provide ways to change

### ARM & IA-32. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

ARM & IA-32 Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu ARM (1) ARM & MIPS similarities ARM: the most popular embedded core Similar basic set

### Instructions: Language of the Computer

Instructions: Language of the Computer 1 The Stored Program Concept The stored program concept says that the program is stored with data in the computer s memory. The computer is able to manipulate it

### Assembly Language Programming

Assembly Language Programming Assemblers were the first programs to assist in programming. The idea of the assembler is simple: represent each computer instruction with an acronym (group of letters). Eg:

### Topic 7: Control Flow Instructions

Topic 7: Control Flow Instructions CSE 30: Computer Organization and Systems Programming Summer Session II Dr. Ali Irturk Dept. of Computer Science and Engineering University of California, San Diego So

### CSEE 3827: Homework 4 Due: 4/11/11

CSEE 3827: Homework 4 Due: 4/11/11 For this assignment you will write MIPS code, which you can test by simulating it with SPIM, a MIPS simulator. SPIM is a command line tool available on cunix (cunix.cc.columbia.edu).

### The programming language C. sws1 1

The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

### CSI 333 Lecture 17 MIPS Assembly Language (MAL): Part V (MIPS Instruction Formats) 17 1 / 16

CSI 333 Lecture 17 MIPS Assembly Language (MAL): Part V (MIPS Instruction Formats) 17 1 / 16 MIPS Instruction Formats Each MIPS machine instruction occupies one word (32 bits). Three instruction formats

### Stack Allocation. Run-Time Data Structures. Static Structures

Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,

### PROBLEMS (Cap. 4 - Istruzioni macchina)

98 CHAPTER 2 MACHINE INSTRUCTIONS AND PROGRAMS PROBLEMS (Cap. 4 - Istruzioni macchina) 2.1 Represent the decimal values 5, 2, 14, 10, 26, 19, 51, and 43, as signed, 7-bit numbers in the following binary

### Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types In this lecture Computer Languages Assembly Language The compiler Operating system Data and program instructions Bits, Bytes and Data Types ASCII table Data Types

### Introduction To MIPS Assembly Language Programming

Gettysburg College Open Educational Resources 2015 Introduction To MIPS Assembly Language Programming Charles W. Kann Gettysburg College Follow this and additional works at: http://cupola.gettysburg.edu/oer

### M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: IMPORTANT INSTRUCTIONS: 1. Question Paper in English and Hindi and Candidate can choose any one language. 2. In case of discrepancies in

### Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

### Lab Work 2. MIPS assembly and introduction to PCSpim

Lab Work 2. MIPS assembly and introduction to PCSpim The goal of this work is for the student to become familiar with the data types and the programming in assembly (MIPS32). To realize this lab work you

### VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 603 203 DEPARTMENT OF COMPUTER APPLICATIONS QUESTION BANK IN REVISED BLOOM S TAXONOMY

ACADEMIC YEAR: 0 7 VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 0 0 SEMESTER: ODD BRANCH: MCA YEAR: I SEMESTER: I SUBJECT CODE AND NAME: MC70 Problem Solving and Programming NAME OF THE FACULTY

### Chapter 7D The Java Virtual Machine

This sub chapter discusses another architecture, that of the JVM (Java Virtual Machine). In general, a VM (Virtual Machine) is a hypothetical machine (implemented in either hardware or software) that directly

### Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts

Assembly Language for Intel-Based Computers, 4 th Edition Kip R. Irvine Chapter 1: Basic Concepts Slides prepared by Kip R. Irvine Revision date: 07/21/2002 Chapter corrections (Web) Assembly language

### Optimization Techniques in C. Team Emertxe

Optimization Techniques in C Team Emertxe Optimization Techniques Basic Concepts Programming Algorithm and Techniques Optimization Techniques Basic Concepts What is Optimization Methods Space and Time

### The MIPS instruction set architecture

The IPS instruction set architecture The IPS has a bit architecture, with bit instructions, a bit data word, and bit addresses. It has addressable internal registers requiring a 5 bit register address.

### FBCA-02 April-2007 Programming in C Language BCA-102 (New Course)

Seat No. : FBCA-02 April-2007 Programming in C Language BCA-102 (New Course) Time : 3 Hours] [Max. Marks : 70 Instructions : (1) Figures to the right indicate full marks of the question. (2) Make and state

### Microprocessor project: Digital watch

Digital System 2009-2010: Semester 1 Netlists and simulator Table of contents 1 Netlists and simulator Netlists Specifications of the simulator Circuit watch 2 3 Instruction set - specifications Assembly

### Introduction to C for Atmel XMega

Introduction to C for Atmel XMega 1 Menu Overview of C Basics Variables, Types, and Definitions Conditionals Ports and Registers Interrupts Pointers Strongly Using C with Assembly 2 1 Overview of C Basics

### MLR Institute of Technology

MLR Institute of Technology DUNDIGAL 500 043, HYDERABAD COMPUTER SCIENCE AND ENGINEERING Computer Programming Lab List of Experiments S.No. Program Category List of Programs 1 Operators a) Write a C program