Question

In: Computer Science

Write a mips assembly language program. Ask the user whether he wants to repeat the program:...

Write a mips assembly language program. Ask the user whether he wants to repeat the program: "\nRepeat [y/n]? ". Use service code 12 to read a character and the branch instruction to repeat the main function if the user input is character 'y'.

Solutions

Expert Solution

Answer -

MIPS Assembly Language Program:



#Define text section

.text

        #Define main

     .globl main

  

#Define main method

main:

        #Push to stack

     sub $sp,$sp,12

  

     #Store return address

     sw   $ra,4($sp)

       #String output

     li   $v0,4    

  

     #Load address

     la   $a0,pow

  

     #Display string

     syscall    

  

     #Integer input

     li $v0,5     

  

     #system call

     syscall      

  

     #Move data into register

     move $t2,$v0

       

     #Load value

     li   $v0,4   

  

     #load address

     la   $a0,bas  

  

     #Display string

     syscall      

  

     #Load

     li $v0,5     

  

     #System call

     syscall      

  

     #Move value to register

     move $a0,$t2

  

     #Move value to register

     move $a1,$v0

  

     #Jump

     jal euc

  

     #Store

     sw   $v0,8($sp)

     #Load

     li   $v0,4

  

     #Load value

     la   $a0,str

  

     #System call

     syscall

       #Load value

     li   $v0,1

  

     #Load value

     lw   $a0,8($sp)

  

     #System call

     syscall

  

     #Restore address

     lw   $ra,4($sp)

  

     #Pop stack

     add $sp,$sp,12

  

     #Jump

     jr   $ra

        #Define data

     .data

  

#Define label

str:      

        #Display message        

     .asciiz "value = "

  

#Define label   

bas:       

           #Display message       

     .asciiz "second integer = "

  

#Define label

pow:      

        #Display message        

     .asciiz "first integer = "

  

     #Define text

     .text

#Define label

euc:

       #Push stack

     sub $sp,$sp,8

  

     #Store address

     sw   $ra,4($sp)

       #Exit if b is not 0

     bne $a1, $zero, L1

  

     #Return a0

     add $v0,$zero,$a0

     #Pop stack

     add $sp,$sp,8

     #Return

     jr   $ra

#Define L1

L1:

       #Set c to b

     move $t4,$a1       

     #Compute remainder

     rem $a1,$a0,$a1    

     #Set a

     move $a0,$t4

  

     #Call recursively      

     jal euc         

        #Load

     lw   $ra,4($sp)

     #Move value to $v0

     move $v0,$a0

        #Pop stack

     add $sp,$sp,

     #Return

     jr   $ra

Note: If you have any related doubts, queries, feel free to ask by commenting down below.


Related Solutions

Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS Assembly language program to request a file name from the user, open the...
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write out the contents to the console. This is what I have so far: .data    fileName:   .space 100    prompt1:   .asciiz "Enter the file name: "    prompt2:    .asciiz ""    prompt3:   .asciiz "\n"    buffer:    .space 4096 .text    main:        #        li $v0, 4        la $a0, prompt1       ...
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
Can someone write a method in MIPS assembly language that asks the user for a hexadecimal...
Can someone write a method in MIPS assembly language that asks the user for a hexadecimal value and converts it into a decimal? I will thumbsup if its right
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT