Download presentation
Presentation is loading. Please wait.
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 (a43) 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 ?
4
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.
5
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.
6
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:
7
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
8
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.
9
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
10
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 General Purpose Register $a0
11
Read Character What will be in $v0 if we enter “6”? 0x 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 ori $2,$0, # read character # to $2($v0) syscall Low order General Purpose Register $V0
12
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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.