Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sol in MARS 45 Statement Purpose: The purpose of this Lab. is to familiarize student with Arithmetic, Logical and control instructions and how to deal

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedSol in MARS 45

Statement Purpose: The purpose of this Lab. is to familiarize student with Arithmetic, Logical and control instructions and how to deal with looping. This lab explains how to control the sequence of instructions execution, depending on the value of a registers using the branching instructions and how to repeat some instructions for many times. Activitv Outcomes: Student will learn how to write MIPS programs that make decisions, execute different parts and repeat some instructions depending on registers values. Student will solve different problem that will help them to choose appropriate Logical and branching statement for a given task. There are some exercises, through which they will understand the concept learn in this chapter. MIPS Jump and Branch Instructions Like all processors, MIPS has instructions for implementing unconditional and conditional jumps. The MIPS Jump and Branch instructions are shown in following table Program To Demonstrate Branch-if-Equal(beq) and Branch-if Not- Equal(bne). data message: .asciiz "The Numbers are Equal" message2: asciiz "The Numbers are Not Equal" .text main: addi $t1, $ zero , 6 addi $t2,$ zero , 15 beq $t1,$t2, numbersEqual bne $t1,$t2, numbersdifferent li \$v0,10 syscall numbersEqual: li \$v0, 4 la $a0,message syscall j End numbersdifferent: li \$v0, 4 la $a0, message 2 syscall End: li \$v0, 10 syscall Pseudo Instructions: Pseudo instructions are instructions introduced by an assembler as if they were real instructions. We have seen an example of a pseudo instruction before, which is the li instruction. Pseudo instructions are useful as they facilitate programming in assembly language. For example, the MIPS processor does not have the following useful conditional branch comparison instructions: blt, bltu branch if less than (signed/unsigned) ble, bleu branch if less or equal (signed/unsigned) bgt, bgtu branch if greater than (signed/unsigned) bge, bgeu branch if greater or equal (signed/unsigned) The reason for not implementing these instructions as part of the MIPS instruction set is that th can be easily implemented based on a set of two instructions. For example, the instruction blt $s0,$s1, label can be implemented using the following sequence of two instructions: slt \$at, Ss0, \$sl bne \$at, Szero, label Similarly, the instruction ble \$s 2,$s3, label can be implemented using the following sequence of two instructions: slt \$at, \$s 3, \$s2 beq \$at, Szero, label (2). Program To Demonstrate check if number is less than another number. data message1: asciiz "First number is less than second number " message2: asciiz "Second number is less than first number" .text main: addi $ to,\$zero, 9 addi $ t1, \$zero , 1 slt $ so,\$to, \$t 1 bne \$s0, \$zero, printMessage li $v0,4 la \$a0,message 2 syscall j End printMessage: li \$v0, 4 la Sa0,message 1 syscall End: li $v0,10 syscall (3). Program To Demonstrate check if number is greater than another number. data message: asciiz " greater than " mg1:asciiz "Enter first number: " mg2: asciiz "Enter second number: " .text main: li $v0,4 la Sa0,mg1 syscall li \$v0,5 syscall move Ss0,Sv0 \#first number in s0 li \$v0,4 la Sa0,mg2 syscall li $v0,5 syscall move \$s 1,$v0 \#second number in s1 bgt \$s0, \$s1,DisplayMsg li \$v0,1 move \$a0,\$s1 \#print second number syscall li $v0,4 la Sa0,message syscall li \$v0,1 move \$a0,\$s0 \#print first number syscall j End DisplayMsg: li \$v0,1 move $aa0,$s0 \#print first number syscall li \$v0, 4 la Sa0,message syscall li \$v0,1 move Sa0,$s1 \#print second number syscall End: \#End of main li $v0,10 syscall Exercise 1. Write a program to find the largest of 3 numbers. 2. Write a program to find the smallest of 3 numbers. Exl-Solution: .data message: .asciiz " the greatest number " mg1:asciiz "Enter first number: " mg2: asciiz "Enter second number: " mg3:asciiz "Enter third number: " .text main: li $v0,4 la Sa0,mg1 syscall li $v0,5 syscall move Ss0, Sv0 \#first number in s0 li $v0,4 la SaO,mg2 syscall li $v0,5 syscall move \$s1, Sv0 \#second number in s1 li $v0,4 la Sa0,mg3 syscall li $v0,5 syscall move \$s2,\$v0 \#third number in s2 bgt \$s0, \$s1,L1 bgt $s1,$s2, NumberTwo j NumberThree L1: bgt $s0,$s2, NumberOne j NumberThree NumberOne: \# number one is the greatest li $ v0, 1 move $a0,$s0 syscall j End NumberTwo: \# number two is the greatest li $v0,1 move \$a0, \$s1 syscall j End NumberThree: li \$v0,1 \# number three is the greatest move \$a0, \$s 2 syscall j End End: li \$v0,4 la Sa0, message syscall \#End of main li \$v0,10 syscall

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions

Question

What are the two entities that govern LDAP standards?

Answered: 1 week ago

Question

3. What are the current trends in computer hardware platforms?

Answered: 1 week ago