Refer the program in the next
page:
_________________________________
________________________________________________________
Binary:_______________________________________
Hex:___________________
Binary:_______________________________________
Hex:___________________
__________________________________
________________________________________________________________________________
____________________________________
# MIPS program for Questions
#
# ________________________________________________________________________________
#
# ________________________________________________________________________________
.data
prompt: .asciiz "The Number:"
Result: .asciiz "The Result:"
num1: .word 0
num2: .word 0
num3: .word 0
.globl main
.text
main:
____________________ # Question 2
la $a0, prompt #
syscall #
li $v0, 5 # Question 3
syscall #
sw $v0, num1 #
____________________ # Question 2
syscall #
li $v0, 5 # Question 3
syscall #
sw $v0, num2 #
lw $t1, num1 #
lw $t2, num2 #
add $t3, $t1, $t2 # Question 4
sw $t3, num3 # Question 5
____________________ # Question 2
la $a0, result #
syscall #
lw $a0, num3 #
li $v0, 1 #
syscall #
____________________ # Question 6
syscall #
Question 1
Assume the starting address of data segment: 0x10010000. What is the address of label num3?
Ans) 0x10010020
Explanation:-
Start address 0x10010000.Then 'Prompt' label start that address.
It has 11 charcater so allocate 11 bytes space +null termination=12 bytes there
Next address 'Result' starts from 0x10010000+12=0x1001000c
It has 11 charcater so allocate 11 bytes space +null termination=12 bytes there
Next address' num1' starts from 0x1001000c+12=0x10010018
'num1' is word data type , so 4 bytes allocate
Next address' num2' starts from 0x10010018+4=0x1001001c
Next address' num2' starts from 0x1001001c+4=0x10010020
----------------------------------------------------------------------------------------------------------
Question 2
Write the common syscall code to print string for the blank marked as #Question 2
Ans) li $v0,4
Explanation:-
string print syscall in MIPS is li $v0,4 and syscall
------------------------------------------------------------------------------------------
Question 3
Write proper comments for the lines marked as #Question 3
Ans) Instruction read for read integer input and get the read data in v0 register
Explanation:-
In MIPS comments start with # , then comment in english
--------------------------------------------------------------------------------------------------------
Question 4
Write the machine code for the line marked as #Question 4 in both binary and hex.
Instruction:-
add $t3, $t1, $t2
R-Type instruction format
opcode(6-bit) rs(5-bit) rt(5-bit) rd(5-bit) shampt(5-bit) func(6-bit)
000000 01001 01010 01011 00000 100000
Binary code: 00000001001010100101100000100000
Hex: 0x012a5820
------------------------------------------------------------------------------
Question 5
Write the machine code for the line marked as #Question 5 in both binary and hex.
Instruction:-
sw $t3, num3
I-Type instruction format
opcode(6-bit) rs(5-bit) rt(5-bit) offset(16-bit)
101011 00000 01011 0000000000100000
Binary code: 10101100000010110000000000100000
Hex:0xac0b0020
------------------------------------------------------------------------------------------------
Question 6
Write the syscall code to exit the program for the blank marked as #Question 6
Ans) li $v0,10
Explanation:-
It is MIPS exit system call
----------------------------------------------------------------------
Question 7
Describe what this program is doing in detail.
#Data declaration section
.data
prompt: .asciiz "The
Number:"
Result: .asciiz "The
Result:"
num1:
.word 0
num2:
.word 0
num3:
.word 0
#Program starts here
.globl main
.text
main:
#Prompt for number1
li $v0,4
la $a0,
prompt
syscall
#Read user input
li $v0,
5
syscall
#Store first number in variable num1
sw $v0,
num1
syscall
#Read num2 from user
li $v0,
5
syscall
#Store second number in
variable num2
sw $v0, num2
#Get first number in
t1
lw $t1,
num1
#Get first number
in t2
lw $t2, num2
#Add first and second
number and store into
t3
add $t3, $t1,
$t2
#Store sum,that is t3
value into memory num3
sw $t3, num3
#display reuslt
prompt
li $v0,4
la $a0,
Result
syscall
#Get sum from num3
lw $a0,
num3
#Display sum
li $v0,
1
syscall
#End of the
program
li $v0,10
syscall
------------------------------------------------------------
Question 8
Provide the memory address in which the character ‘t’ is stored.
Ans)0x10010017
Explanation:
'Result ' starts at the address 0x1001000c
't' is the 11 the character, so 0x1001000c+11=0x10010017
Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What...
QT
Spim question. Program and answer already given please explaine it.
Please explain the reason why each instruction was used
throughout the program step by step given the prompt, what is its
purpose to achive the goal asked in the prompt, why is written in
that order.
Please not just write to the side what each instruction means
in words like load $t0 to $t1. I want to understand the program
thoroughly.
Thanks in advance
Previous information needed to solve...
WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4 la...
.data prompt: .asciiz "Input an integer x:\n" result: .asciiz "Fact(x) = " .text main: # show prompt li $v0, 4 la $a0, prompt syscall # read x li $v0, 5 syscall # function call move $a0, $v0 jal factorial # jump factorial and save position to $ra move $t0, $v0 # $t0 = $v0 # show prompt li $v0, 4 la $a0, result syscall # print the result li $v0, 1 # system call #1 - print int move $a0,...
(USING THE PROGRAM MARS) Using the MemoryAccess program we wrote in class as a starting point, write a program called LoadStore # Title : Memory access.asm #Desc: Practice initially memory, #in val1 = 0x0a; #int val2 = 0x0b; #int result; #string resultstring = " final answer : "; #string returnchar = "\n"; #void main() { # result = val1 + val2; # cout<<< resultstring << returnchar; #} .data val1: .word 0x0a #store 0xa into variable val1 val2: .word 0x0b #store...
I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort. Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main: # la $t0, val # loads val into a register # li $t1, 0 #keeps track of how many numbers entered la $a0,...
im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler. im having hard times to debug this. The input is given to the array of Formula char (base address $ s0) in the form of a formula. The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored. For example,...
MIPS -
Takes two inputs from the user, which are the lengths of two
sides of a polygon. It adds those two lengths and prints the sum.
Your task is modify the program to make it specific to a triangle,
and to print the perimeter of that triangle.
See blue highlighted.
preamble: prompt1: prompt2: answer: endline: .data ascii .asciiz asciiz .asciiz asciiz .asciiz "\nThis program, written by <YOUR NAME>," " can be used to add the length of two sides...
Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to reduce the number of cycles needed to execute the program. Indicate the number of cycle reduction. 2. Describe how forwarding would affect the execution of the program. CODE # quad_sol.s # This assembly program calculates the integer solutions of a quadratic polynomial. # Inputs : The coefficients a,b,c of the equation a*x^2 +...
what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:li $v0, 1l li $s0,0 la $s1, A li $t3, 0 loop: slti $t0, $s0, 17 beq: $t0, $zero, end sll $t1, $s0 2 add $t2 $s1 $t1 syscall addi $s0, $s0, 1 j loop end: li $v0, 1 add $a0, $zero, $t3 syscall