Integers/Characters Input/Output

Slides:



Advertisements
Similar presentations
Catch up on previous topics Summary and putting together first four classes.
Advertisements

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
SPIM and MIPS programming
Syscall in MIPS Xinhui Hu Yuan Wang.
1 Computer Architecture MIPS Simulator and Assembly language.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
COSC 120 Computer Programming
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Introduction to Computers and Programming Lecture 7:
Feb 18, 2009 Lecture 4-2 instruction set architecture (Part II of [Parhami]) MIPS encoding of instructions Spim simulator more examples of MIPS programming.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
1 Input/Output. 2 Principles of I/O Hardware Some typical device, network, and data base rates.
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
CISC105 General Computer Science Class 1 – 6/5/2006.
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Slide 1 Wednesday, October 07, 2015 Low Level Machine.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
Ch2b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Thanks for all the Memory! When 32 registers just won’t do. Many times (almost.
Strings in MIPS. Chapter 2 — Instructions: Language of the Computer — 2 Character Data Byte-encoded character sets – ASCII: 128 characters 95 graphic,
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 Program Input Software Design Chapter 4. 2 You Will Want to Know... Prompting for and reading values into a program. Accessing data from a file. What.
Lecture 161 Lets examine a SPIM program in detail. io.asm This program is a simple routine which demonstrates input/output using assembly code. SPIM.
An Example Architecture. A Paper Computer - Woody Woody's characteristics Word size – 8 bits One word.
All code must be commented! Each problem part (1,2,3a,3b,…) will be in a separate file: problem_1.s …. You may be asked to demonstrate your program. You.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
The SPIM Trap Handler Syscall Trap handler services String operations File operations Memory allocation Central Connecticut State University, MIPS Tutorial.
Simple ALU How to perform this C language integer operation in the computer C=A+B; ? The arithmetic/logic unit (ALU) of a processor performs integer arithmetic.
Integers/Characters Input/Output Integers and Characters Input/Output System Calls. syscall Trap Handler Services for Integers and Characters Read Integer,
MIPS Architecture Topics –What resources MIPS assembly manipulates –CPU (Central Processing Unit) –ALU (Arithmetic & Logical Unit), Registers –Memory –I/O.
MISP Exception Facility Supported by SPIM simulator.
CHAPTER 1 COMPUTER SCIENCE II. HISTORY OF COMPUTERS (1.1) Eniac- one of the worlds first computers Used more electricity than an entire city block of.
CPS4200 System Programming Spring 1 Systems Programming Chapter 1 Background I.
Program Structure Example for Data Segment CRLF EQU 0DH, 0AH PROMPT DB 'Enter a digit between 0 and 9', 0 VAR1 DB ? ARRAY DW 1234h, 23h, 0FF54h.
CS 312 Computer Architecture & Organization
Binary Representation in Text
MIPS Arithmetic is 32 bits
Computers’ Basic Organization
Computer Science 210 tutorial 5
Computer Science II Chapter 1.
Topics Designing a Program Input, Processing, and Output
Engineering Problem Solving With C An Object Based Approach
Chapter 1: Introduction to computers and C++ Programming
Computer Science 210 Computer Organization
Microprocessor Systems Design I
Computer Science 210 Computer Organization
Microprocessor Systems Design I
ACOE301: Computer Architecture II Labs
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
ICS103 Programming in C Lecture 3: Introduction to C (2)
Computer Electronic device Accepts data - input
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Chapter One: Introduction
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
Operating Systems Chapter 5: Input/Output Management
Chapter 9 TRAP Routines and Subroutines
CSCI-N 100 Dept. of Computer and Information Science
COMS 361 Computer Organization
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
CS 286 Computer Architecture & Organization
Presentation transcript:

Integers/Characters Input/Output Integers and Characters Input/Output System Calls. syscall Trap Handler Services for Integers and Characters Read Integer, Print Integer, Read Character, Print Character, Example Program No Input Line Buffer correction. Textbook: Appendix A (a43) Central Connecticut State University, MIPS Tutorial. Chapter 22.

Review: MIPS Programming Model Based on this model we can suppose the existence of several groups of MIPS instructions: Inter Register transfer instructions. Arithmetic or Logical instructions with registers. Input / output instructions. Memory - register transfer instructions.

Single program without OS Up until now, our programs have been running with SPIM used as a computer with no machine code in it but our own. Can we write a program to deal with the Input / Output ?

I/O by user program or by OS ? is very costly process. In even the simplest computer, putting a character on the screen involves many instructions and a detailed knowledge of the video card duplication of significant parts of the program code. One of the Operating System’s task is: to implement all these input/output operations and allow the user programs to use the high level input/output services provided by the OS. System Calls.

System Calls Assembly language programs request operating system services using the syscall instruction. The syscall instruction transfers control to the operating system which then performs the requested service. Then control (usually) returns to the program.

SPIM trap handler integer and character services format Different operating systems use the syscall instruction in different ways. For the SPIM trap handler integer and character services it is used like this:

SPIM trap handler integer and character services The print services write characters to the simulated monitor of SPIM. The read services read characters from the keyboard and (for numeric read services) convert character strings into the appropriate type. Service Code in $2 ($v0) Arguments   Returned Value print integer 1 ($a0) $4 == integer to print read integer 5 $2 ($v0) <-- integer print character 11 ($a0) $4 == character to print read character 12 $2 ($v0) <-- character

Read Integer The read integer service reads an entire line of input from your keyboard—all the characters you type up to the newline character. These characters are expected to be ASCII digits '0', '1', .., '9' with an optional leading '-' or '+'. The characters are converted into a 32-bit two's complement representation of the integer which is returned in $v0. The terminal gives to computer only one character at a time That is why to get any other than character type of information (integer, string) OS reads characters one by one and translates them to the type we need.

Print Integer The print integer service prints the integer represented by the 32 bits in $a0 to the SPIM terminal. The terminal is able to print only one character at a time That is why any other type of information should be translated to the characters before printing to the terminal

Print Character The print character service prints the character represented in the lowest order byte of the 32 bits in $a0 to the SPIM terminal.  Characters 0x0D and 0x0A could be used for moving the console cursor to the next line’s first position. This is the standard End Of Line “\n” character’s behavior. What will be printed if we use: ori $2,$0,1 #print integer 65 ori $4,$0,0x41 # prepare character “A” in $4 ($a0) ori $2,$0,11 # print character syscall 4 1 Low order 3 2 1 0 General Purpose Register $a0

Read Character What will be in $v0 if we enter “6”? 0x 00 00 00 36 The read character service reads one character from your keyboard. The character’s ASCII code is returned in $v0. What will be in $v0 if we enter “6” but use: ori $2,$0,5 #read integer 0x 00 00 00 06 ori $2,$0,12 # read character # to $2($v0) syscall   Low order 3 2 1 0 General Purpose Register $V0

No Input Line Buffer Correction The user might make a mistake in entering the character and try to correct it by hitting the "backspace" key to erase the mistake. But this does not work. The ascii value of the key 0x08 is included in the string just as any character value. Odd byte values show up (in SPIM) as a small black rectangle.