You are on page 1of 9

LAB 4 “ARITHEMETIC OPERATION

THROUGH USER”
Table of Contents

INTRODUCTION: ................................................................................................. 2
CODE INSTRUCTIONS: ........................................................................................ 2
PRACTISE PROBLEMS: ........................................................................................ 3
TASK 1 (ADDITION OF TWO INTEGERS):............................................................. 3
LAB TASK 2(SUBTRACTION OF TWO INTEGERS):................................................ 4
LAB TASK 3(Multiplication of two numbers): .................................................... 5
LAB TASK 4(Division of two numbers): .............................................................. 5
LAB TASK 5(Age display): ................................................................................... 6
LAB TASK 6(String): ............................................................................................ 7

1
INTRODUCTION:
This lab introduces the MARS simulator for MIPS assembly language.
MARS is a Java application, so it can run on any machine that has the
Java virtual machine installed.
The main window shows the assembly source code.
MARS highlights the code using the following conventions
• Comments are shown in light green italics
• Labels defining variables or blocks of code are in italics e.g,
myMessage etc.
• Instructions are shown in blue e.g, li, lw , la , syscall.
• Registers are shown in red e.g $v0, $a0 etc
• Special keywords are shown in magenta e.g, .data , .text etc.
• All lines are numbered
CODE INSTRUCTIONS:
 .data -- The following lines define items to be stored in the data
segment. This is where global variables would be stored.
 .text -- The following lines define items (code) to be stored in the
text segment. Note that this segment is read-only, so you cannot
modify these lines after the program has been loaded.
 DIRECTIVES: These directives can be used to declare the data
types:
1. .byte -- an 8-bit value
2. .half -- a 16-bit value
3. .word -- a 32-bit value
4. .float -- a floating-point single precision number
5. .double -- a floating-point double precision number
6. .space n -- n bytes of space
7. .asciiz -- a null-terminated string
8. .ascii -- a string that is not null-terminated
 REGISTERS: register is represented by “$”
Example:

2
$a0 is used to print integer value, is address of null terminated string,
address of input buffer, character to print, character read.
$f12 is used to print double and float value
$v0 is used to read integer
$f0 is used to read double and float value
$zero stores zer0 value in it

PRACTISE PROBLEMS:
TASK 1 (ADDITION OF TWO INTEGERS):
 Code

 Display

 Values stored in register:

3
LAB TASK 2(SUBTRACTION OF TWO INTEGERS):

 Code

 Display

 Values stored in registers

4
LAB TASK 3(Multiplication of two numbers):
 Code

 Display

 Values stored in registers

LAB TASK 4(Division of two numbers):


 Code

5
 display

 Values stored in registers

LAB TASK 5(Age display):


 Code

6
 Display

 Values stored in Register

LAB TASK 6(String):


 Code

7
 Display

 Values stored in Registers

You might also like