CC2302 COAL Lab # 05
CC2302 COAL Lab # 05
3. MIPS Coprocessor
In MIPS32 architecture, Coprocessor 0 (CP0) and Coprocessor 1 (CP1) are special-purpose
coprocessors used for system control and floating-point operations, respectively.
1.3. Coprocessor 0 (CP0)
CP0 is primarily responsible for system control and management.
It handles exceptions, interrupts, and other system-level operations.
CP0 contains various registers that hold important system state information, such as the
status of interrupts, exception causes, and process context.
The registers in CP0 are accessed using special coprocessor instructions in MIPS
assembly language.
Examples of registers in CP0 include the Status register, Cause register etc.
CP0 is essential for exception handling, virtual memory management, and system-level
control in the MIPS architecture.
1.4. Coprocessor 1 (CP1)
CP1 is dedicated to floating-point operations.
It contains registers and instructions for performing floating-point arithmetic and
floating-point data manipulation.
CP1 is used for operations involving floating-point numbers, such as addition,
subtraction, multiplication, division, and conversion between floating-point and integer
representations.
Registers in CP1 include floating-point data registers (FPRs), control registers, and status
registers.
CP1 provides support for single-precision (32-bit) and double-precision (64-bit) floating-
point arithmetic.
CP1 instructions are used in applications that require high precision or efficiency for
floating-point calculations, such as scientific computing, graphics processing, and signal
processing.
4. Arithmetic Overflow Exception Code
In MIPS architecture, exceptions are events that occur during program execution that disrupt the
normal flow of instructions. MIPS defines several exception codes, which are used to classify
different types of exceptions that can occur. These exception codes provide information about
the cause of the exception and help in identifying the appropriate exception handling routine.
For example, in MIPS32 architecture, the value 0x00000030 in the Cause register indicates
that an exception occurred, specifically an arithmetic overflow.
Binary representation of 0x00000030: 0000 0000 0000 0000 0000 0000 0011 0000
Bits 6-2: 00110
The binary value 00110 in bits 6-2 represents the arithmetic exception code.
5. Task # 1: Run the following MIPS program and check if the overflow
occurs
.data
num1: .word 2147483647 # Max positive signed integer
num2: .word 10 # Just an arbitrary number
.text
.globl main
main:
# Load the numbers into registers
lw $t0, num1 # Load num1 into $t0
lw $t1, num2 # Load num2 into $t1
2. What is the result of addition after assembling and running the program?
4. Write the values of following registers after running the program and explain what is the
value?
Name Value What is the value
$at
$v0
$a0
$t0
$t1 0x0000000a Hexadecimal value of num2 which is 10
$t2
pc
6. Task # 2: Run the following MIPS program and check if the overflow
occurs
.data
num1: .word 2147483647 # Max positive signed integer
num2: .word 10 # Just an arbitrary number
.text
.globl main
main:
# Load the numbers into registers
lw $t0, num1 # Load num1 into $t0
lw $t1, num2 # Load num2 into $t1
6. What is the result of addition after assembling and running the program? If any error,
please write.
8. Write the values of following registers after running the program and explain what is the
value?
Name Value What is the value
$at
$v0
$a0
$t0
$t1 0x0000000a Hexadecimal value of num2 which is 10
$t2
pc
9. What is the value of “cause” register?
10. What is the value of program counter pc if the program in terminated with error? Is
the value different than the address of instruction which caused exception?
7. Task # 3: Write a MIPS code which take two values and subtraction them
using subu. Answer all the questions stated in Task # 1.
num1: .word -2147483647 # Min negative signed integer
num2: .word 10 # Just an arbitrary number
1.7. Observations in MARS
1. What is the expected result of subtraction?
2. What is the result of subtraction after assembling and running the program?
4. Write the values of following registers after running the program and explain what is the
value?
Name Value What is the value
$at
$v0
$a0
$t0
$t1 0x0000000a Hexadecimal value of num2 which is 10
$t2
pc
8. Task # 4: Write a MIPS code which take two values and subtraction them
using sub. Answer all the questions stated in Task # 2.
num1: .word -2147483647 # Min negative signed integer
num2: .word 10 # Just an arbitrary number
1.8. Observations in MARS
11. What is the expected result of subtraction?
12. What is the result of subtraction after assembling and running the program? If any error,
please write.
16. What is the value of program counter pc if the program in terminated with error? Is
the value different than the address of instruction which caused exception?