Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ASSEMBLY LANGUAGE (MIPS) PROGRAM. EDIT THE EXAMPLE CODE ACCORDING TO THE INSTRUCTIONS: HERES THE EXAMPLE CODE: # Comments. Anything after # is comments. # MIPS

ASSEMBLY LANGUAGE (MIPS) PROGRAM. EDIT THE EXAMPLE CODE ACCORDING TO THE INSTRUCTIONS:

image text in transcribedimage text in transcribed

HERES THE EXAMPLE CODE:

# Comments. Anything after # is comments. # MIPS Example .data #data segment newline: .asciiz " " #ASCII for a new line. asciiz with z means 0 (not character '0') is placed after the last character. .align 2 # The next variable (symbol) should starts at an address that is a multiple of 4. name: .asciiz "CSE3666: Lab 0: YOUR NAME " .align 2 msg1: .asciiz " The string you just typed is " .align 2 buf: .space 128 # Reserve space for a variable (array). Not initialized. .align 2 reserved: .space 20 .text # Code segment .globl main # declare main to be global main: # load an address, which is a 32-bit value. # Could be a symbol. See the example below. Still, the value is a 32-bit value. # la is a pseudo instruction.It is converted into two instructions. la $a0, 0xBF63C886 # Load a large constant with two instructions. Higher 16 bits will be 0 although the MSB of the constant is 1. lui $a0, 0xBF63 ori $a0, 0xC886 # example of subtraction sub $a0, $a0, 1 # system call no. 8, read a string. # The address of the buffer 'buf', which stores the returned string, is specified by $a0. # Notice that buf is a label. You can consider it as a 32-bit constant. So you can load it directly into a register. # The max length of the buffer is spacified in $a1. Try type a long string and see what happens. la $a0, buf li $a1, 10 # load a small constant (signed). li $v0, 8 # prepare a system call. Type 8. syscall # read a string # system call no. 4, output a string that is ended with a NULL (0) byte. # msg1 is a label. Again, you can consider it as a 32-bit constant. la $a0, msg1 li $v0, 4 syscall la $a0, buf li $v0, 4 # system call, type 4, print an string, *$a0 syscall # call the "OS" Exit: li $v0,10 # System call, type 10, standard exit syscall 
10. Modify the example code. Instead of reading string, reads two integers (by calling system call 5 twice). Save the first integer in Ss0 and the second in Ss2. Note that the system calls return value in SvO. 11. Consider buffer 'buf as an array of words. The first integer you read (Ss0) is an index into the array (since buf has only 128 bytes, the first integer must be between 0 and 31). Store Ss2, the second integer you read in step 10, into bufSs0]. The steps you need to perform include: Load the starting address of 'buf into St0. Calculate the offset of word buf[$s0] (i.e., 4 times the value in $s0) Calculate the address of buf[Ss0] Store Ss2 (the second integer) in buflSs0]. 12. Print out the following information: Value $s0 (the first integer) in decimal (system call 1) New line string (at location newline'). Value Ss1 (the address) in hexadecimal (system call 34). New line string (at location newline). Value Ss2 (the second integer) in hexadecimal. 10. Modify the example code. Instead of reading string, reads two integers (by calling system call 5 twice). Save the first integer in Ss0 and the second in Ss2. Note that the system calls return value in SvO. 11. Consider buffer 'buf as an array of words. The first integer you read (Ss0) is an index into the array (since buf has only 128 bytes, the first integer must be between 0 and 31). Store Ss2, the second integer you read in step 10, into bufSs0]. The steps you need to perform include: Load the starting address of 'buf into St0. Calculate the offset of word buf[$s0] (i.e., 4 times the value in $s0) Calculate the address of buf[Ss0] Store Ss2 (the second integer) in buflSs0]. 12. Print out the following information: Value $s0 (the first integer) in decimal (system call 1) New line string (at location newline'). Value Ss1 (the address) in hexadecimal (system call 34). New line string (at location newline). Value Ss2 (the second integer) in hexadecimal

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions