Recitation 5: Recitation 5: MIPS Interrupts and Floating Point

Similar documents
Writing an Embedded Controller

Lecture 7: MIPS Functions Part 2. Nested Function Calls. Lecture 7: Character and String Operations. SPIM Syscalls. Recursive Functions

CDA3100 Midterm Exam, Summer 2013

MIPS function continued

Implementing a Car Simulator in MIPS

Chapter loop: lw $v1, 0($a0) addi $v0, $v0, 1 sw $v1, 0($a1) addi $a0, $a0, 1 addi $a1, $a1, 1 bne $v1, $zero, loop

Patterson PII. Solutions

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Introduction to MIPS Processor

Common Problems on Homework

ECE 30 Introduction to Computer Engineering

SPIM Instruction Set

Exceptions and Interrupts

MIPS I/O and Interrupt

EE 109 Unit 17 - Exceptions

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

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

CS152 Computer Architecture and Engineering

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

Solutions for Chapter 2 Exercises

CSc 256 Midterm 1 Fall 2011

Points available Your marks Total 100

MIPS Assembly Language Guide

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

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

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

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

MIPS%Assembly% E155%

Quick Review. lw $t0, 4($a0) Registers x Memory. $a0 is simply another name for register 4 $t0 is another name for register (green sheet)

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

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

QtSPIM and MARS : MIPS Simulators

MIPS Instruction Reference

CSc 256 Midterm 2 Spring 2012

HW2 solutions You did this for Lab sbn temp, temp,.+1 # temp = 0; sbn temp, b,.+1 # temp = -b; sbn a, temp,.+1 # a = a (-b) = a + b;

MIPS Reference Guide

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

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

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

Examples of branch instructions

CSc 256 Midterm 2 Fall 2011

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

CSc 256 Midterm (green) Fall 2018

CS 61C, Midterm #2, Spring 1997 CS 61C. Spring 1997 Midterm #2. Professor Brian Harvey

Flow of Control -- Conditional branch instructions

Compiling Techniques

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

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

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

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

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

ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points)

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.

Course Administration

Lecture 6 Decision + Shift + I/O

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

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

MIPS Assembly Language Programming

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

Lecture 5: Procedure Calls

TSK3000A - Generic Instructions

Computer Architecture. MIPS Instruction Set Architecture

MIPS Assembly Language. Today s Lecture

USING A SIMULATOR. QUICK INTRODUCTION From various sources For cs470

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

Lec 10: Assembler. Announcements

F. Appendix 6 MIPS Instruction Reference

EE 361 University of Hawaii Fall

MIPS Assembly Language

Topic Notes: MIPS Instruction Set Architecture

MIPS Assembly Language Programming

Chapter 2. Instructions:

Computer Architecture. The Language of the Machine

MIPS (SPIM) Assembler Syntax

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

CSc 256 Final Fall 2016

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

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

COMP2611: Computer Organization MIPS function and recursion

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Reduced Instruction Set Computer (RISC)

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

ECE260: Fundamentals of Computer Engineering

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

ECE260: Fundamentals of Computer Engineering

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

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

ECE/CS 314 Fall 2003 Homework 2 Solutions. Question 1

MIPS Functions and the Runtime Stack

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

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.

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

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

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

MIPS Coding Continued

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

Lecture 5: Procedure Calls

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

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

Transcription:

Float Operations We will write a full program to read in two floats, perform an add, subtract, multiply, and divide, printing out each result Let s attempt in C (using blocking IO)

Float Operations We will write a full program to read in two floats, perform an add, subtract, multiply, and divide, printing out each result Let s attempt in C (using blocking IO) float a, b; scanf( %f, &a); scanf( %f, &b); printf( a + b = %f\n, a + b); printf( a b = %f\n, a b); printf( a b = %f\n, a b); printf( a / b = %f\n, a / b);

Float Operations float a, b; scanf( %f, &a); scanf( %f, &b); printf( a + b = %f\n, a + b); printf( a b = %f\n, a b); printf( a b = %f\n, a b); printf( a / b = %f\n, a / b);

Float Operations float a, b; scanf( %f, &a); scanf( %f, &b); li $v0, 6 # problem? li $v0, 6 # read into f0 # read into f0 printf( a + b = %f\n, a + b); printf( a b = %f\n, a b); printf( a b = %f\n, a b); printf( a / b = %f\n, a / b); add.s $f12, $f0, $f1 # and print sub.s $f12, $f0, $f1 # and print mult.s $f12, $f0, $f1 # and print div.s $f12, $f0, $f1 # and print

Convert To Float.data endl:.asciiz "\n" addmsg:.asciiz "a + b = " submsg:.asciiz "a - b = " mulmsg:.asciiz "a * b = " divmsg:.asciiz "a / b = ".text.globl main main: li $v0, 6 # enter a float mov.s $f1, $f0 li $v0, 6 # enter a float add.s $f12, $f0, $f1 la $a0, addmsg mfc1 $a1, $f12 jal printop sub.s $f12, $f0, $f1 la $a0, submsg mfc1 $a1, $f12 jal printop mul.s $f12, $f0, $f1 la $a0, mulmsg mfc1 $a1, $f12 jal printop div.s $f12, $f0, $f1 la $a0, divmsg mfc1 $a1, $f12 jal printop # add and print # sub and print # multiply and print # add and print exit: li $v0, 10 # exit # printop: print corresponding message, result, and newline # input: # a0 = &msg # a1 = result (float) # outputs: None printop: li $v0, 4 # print message (string) mfc1 $a1, $f12 li $v0, 2 # print result (float) la $a0, endl li $v0, 4 # print endl jr $ra

Convert to Float We will write a full program to read in nonblocking input and convert it to float Let s attempt in C (using blocking IO)

Convert to Float We will write a full program to read in nonblocking input and convert it to float Let s attempt in C (using blocking IO) while(tmp == getchar()) { if(tmp < 0 ) { printf( %d too low\n, tmp); else if(tmp > 9 ) { printf( %d too high\n, tmp); int intval = (int) tmp; float floatval = (float) intval; printf( %f, floatval); break;

Convert to Float while(tmp == getchar()) { if(tmp < 0 ) { printf( %d too low\n, tmp); else if(tmp > 9 ) { printf( %d too high\n, tmp); int intval = (int) tmp; float floatval = (float) intval; printf( %f, floatval); break;

Convert to Float while(tmp == getchar()) { if(tmp < 0 ) { printf( %d too low\n, tmp); else if(tmp > 9 ) { printf( %d too high\n, tmp); int intval = (int) tmp; float floatval = (float) intval; printf( %f, floatval); break; li $t0, 48 blt $s6, $t0, toolow li $t0, 57 bgt $s6, $t0, toohigh addi $s6, $s6, -48 mtc1 $s6, $f12 cvt.s.w $f12, $f12

.data endl:.asciiz "\n" lowmsg:.asciiz " is too low" highmsg:.asciiz " is too high".text.globl main main: mfc0 $a0, $12 # read from the status register ori $a0, 0xff11 # enable all interrupts mtc0 $a0, $12 # write back to the status register lui $t0, 0xFFFF ori $a0, $0, 2 sw $a0, 0($t0) li $s6, 10000 li $s7, 10000 ascii code loop: beq $s6, $s7, loop move $a0, $s6 # $t0 = 0xFFFF0000 # enable keyboard interrupt # write back to 0xFFFF0000 # $s6 used to pass the ascii code # a large number impossible to be an # if no input, loop li $t0, 48 # if (input < 48) goto loop blt $s6, $t0, toolow li $t0, 57 # if (input > 57) goto loop bgt $s6, $t0, toohigh addi $s6, $s6, -48 mtc1 $s6, $f12 cvt.s.w $f12, $f12 # convert char to int # convert int to float li $v0, 2 # print input la $a0, endl loopreset: mfc0 $t0, $12 # Set Status register andi $t0, 0xfffe # clear ENABLE mtc0 $t0, $12 # write back to status li $s6, 10000 mfc0 $t0, $12 ori $t0, 1 mtc0 $t0, $12 j loop toolow: li $v0, 11 li $v0, 4 la $a0, lowmsg la $a0, endl j loopreset toohigh: li $v0, 11 li $v0, 4 la $a0, highmsg la $a0, endl j loopreset exit: li $v0, 10.kdata s1:.word 10 s2:.word 11.ktext 0x80000180 # $s0 used to pass the ascii code # Set Status register # set ENABLE # write back to status # print low message # print high message # exit,if it ever comes here # kernel data # kernel code starts here sw $v0, s1 # To show how to save, we use these registers sw $a0, s2 # not using the stack because the interrupt might be # triggered by a memory reference # using a bad value of the stack pointer mfc0 $k0, $13 # Cause register srl $a0, $k0, 2 # Extract ExcCode Field (bits 2-6) andi $a0, $a0, 0x1f bne $a0, $zero, kdone processing I/O here lui $v0, 0xFFFF lw $s6, 4($v0) kdone: lw $v0, s1 lw $a0, s2 # Exception Code 0 is I/O. Only # $v0 = 0xFFFF0000 # get the input key # Restore other registers mtc0 $0, $13 # Clear Cause register mfc0 $k0, $12 # Set Status register andi $k0, 0xfffd # clear EXL bit ori $k0, 0x11 # Interrupts enabled mtc0 $k0, $12 # write back to status eret # return to EPC Convert To Float