Download presentation
Presentation is loading. Please wait.
Published byGillian O’Connor’ Modified over 8 years ago
1
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 (a48-a49) Central Connecticut State University, MIPS Tutorial. Chapter 22.
2
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.
3
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 ? 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 ?
4
I/O by user program or by OS ? I/O by user program 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. I/O by user program 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. 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.
5
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. 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. System Calls
6
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 format
7
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. SPIM trap handler integer and character services Service Code in $2 ($v0) Arguments Returned Value print integer1($a0) $4 == integer to print read integer5 $2 ($v0) <-- integer print character11($a0) $4 == character to print read character12 $2 ($v0) <-- character
8
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 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. Read Integer 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.
9
The print integer service prints the integer represented by the 32 bits in $a0 to the SPIM terminal. Print Integer 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
10
The read character service reads one character from your keyboard. The character’s ASCII code is returned in $v0. Read Character ori $2,$0,12 # read character # to $2($v0) syscall General Purpose Register $V0 3 2 1 0 Low order
11
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. 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. Print Character ori $4,$0,0x41 # prepare character “A” in $4 ($a0) ori $2,$0,11 # print character syscall 4 1 General Purpose Register $a0 3 2 1 0 Low order
12
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. 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. No Input Line Buffer Correction
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.