Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

INPUT/OUTPUT LAB2

Objectives:

In this lab you will be introduced to the basic Input and Output (I/O) operations using
assembly language. Note that different service codes/ functions (an integer constant) are used
for input and output of values of different data types in order to access the keyboard and
video display.

I/O service codes:

Table-1 summarizes the main I/O service codes (functions). These service codes are mainly
used to read a character, a string, word (32 bit integer), float and double type value from the
keyboard, which could be an input data to a program, and display as output of a program.

Data Type Input Effect Output Effect Arguments


Service Service Register
codes in $v0 codes in $v0 for output
Byte (single Read a Display $a0
character) character character as
from output on
12 11
keyboard screen
and store in
$v0
string Read a Display string $a0
string from as output on
the screen
8 4
keyboard
and store in
$v0
Word(32 bit Read an Display an $a0
integer) integer integer
number number as
5 from the 1 output
keyboard
and store in
$v0
float Read a Display a $f12
floating floating point
point number as
number output
6 2
from the
keyboard
and store in
$f0
double Read a Display a $f12
double floating point
point number as
number output
7 3
from the
keyboard
and store in
$f0
Table 1
How to use SYSCALL system services:
Step 1: Load the service number/function number in register $v0.
li $v0, function
Step 2: Load argument values, if any, in $a0, $a1, $a2, or $f12 as specified.
la $a0, function
Step 3: Issue the SYSCALL instruction.
syscall
Step 4: Retrieve return values, if any, from result registers as specified.

1. Byte input (Character input):


This includes reading a single character using constant value 12.
TASK 1:
Write an assembly language program that prompts the user to input first three characters
of your name separately at run time.

Sample output:

Enter first character of your name: A


Enter second character of your name: L
Enter third character of your name: I

TASK 2:
Write an assembly language program that prompts the user to input your semester
number.

Sample output:

Enter your semester number: SP12

TASK3:
Write an assembly language program that prompts the user to input your complete
registration number.

Sample output:

Enter your registration number: SP12-BCS-012


Byte Output (Character Output):
This includes printing a single character out using constant value 11.

How to print character declared in the program:

Step 1: Out a character using function 11.


li $v0, 11
la $a0,'?'
syscall

How to use runtime Input and Output in a Program:


Step 1: Input a character using function 12.
li $v0, 12
syscall

Character will be moved into $v0 after input.

Step 2. Move $v0 into $a0 for output.


move $t0, $v0
Step 3. Output the moved character using function 11.
li $v0, 11
move $a0, $t0
syscall

.
TASK 1:
Write an assembly language program that prompts the user to print first three characters
of your name separately. Print them all the three letter entered again

Sample output:

First character of your name: A


Second character of your name: L
Third character of your name: I
The name entered is :ALI

TASK 2:
Write an assembly language program that prompts the user to accept input at run time and
output your semester number.
Sample output:
Enter your semester: SP12
Your semester number: SP12

TASK3:
Write an assembly language program that prompts the user to take run time input and
print your complete registration number.

Sample output:

Enter your registration number: SP12-BCS-012

TASK4:
Write an assembly language program to a) Read three initials b) Display them in the
middle of 11 X 11 box of asterisks.

You might also like