Question

In: Computer Science

The following are to be completed using MIPS Assembly code. A.   Using syscall #4, display a...

The following are to be completed using MIPS Assembly code.

A.  

Using syscall #4, display a prompt for the user to enter a number. Then using syscall #5, get a decimal number from the user and save it to data memory (not into a register). After you have stored the number, display it back to the user as a 32-bit binary value.

B.  

Prompt the user to enter a decimal number and save it to data memory. Using addition and/or bit shifting, take the number and multiply it by 5 (do not use the multiply instruction). Finally, output the result using syscall #1.

C.

Output the number from Part B as 8 hex digits.

Solutions

Expert Solution

The system calls mentioned in the question have the following uses as per the MIPS instruction set.

syscall #4 is the print_string service used to display a string/text to the user. The address of string to be printed must be in $a0

syscall #5 is the read_int service used to take integer as input and it is stored in $v0

syscall #1 is the print_int service used to print integer. The address of integer to be printed must be in $a0

The part corresponding to line of code is mentioned as code comment. The program below solves all three parts of the question.

.data
     str1: .asciiz    "Enter a number"
     str2: .asciiz    "Enter a decimal number"
.text
main:
    la $a0, str1           #Load the string to be printed in $a0
    li $v0, 4              #Load the syscall in $v0  
    syscall                #Call service defined in $v0

    li $v0, 5              #Load value for next syscall
    syscall                #Call the service to store integer in $v0
    move $s0,$v0           #Move this value into $s0
    li $a1,32              #Specify the number of bits 
    jal binary             #The solution for part A ends here

    la $a0, str2           #Load the string to be printed in $a0
    li $v0, 4              #Load the syscall in $v0
    syscall                #Call service defined in $v0
    li $v0, 5              #Load value for next syscall
    syscall                #Call the service to store integer in $v0
    sw $v0,50($2)          #Store the value in $v0 in memory location mem[$2+50] can be custom

    move $s2,$v0           #Move number to multiply by 5
    sll $t1,$s2,2          #Store s2*4 in t1. Two left shifts is multiplication by 4
    add $t2,$t1,$s2        #Add $s2 and $t1 = $s2 + 4*$s2 = 5*$s2 and store in $t2
    li $a0,$t2             #Store $t2 in $a0 for priniting
    li $v0, 1              #Load value for next syscall
    syscall                #Call the service to store integer in $v0 to print
                           #The answer to part B ends here

    move $s0,$t2           #Move the answer into s0 for printing in hex
    li $a1,8               #Specify number of digits
    jal hexa               #This prints in hexa and answers part C
    

binary:
    li $a2,1               # number of bits for base digit
    j  printfunc           # $a0 and $a1 define output string and number of bits respectively

hexa:
    li $a2,4               #number of bits for base digit
    j  printfunc           # $a0 and $a1 have been defined in the main function

printfunc:      
    li      $t7,1
    sllv    $t7,$t7,$a2             
    subu    $t7,$t7,1              
    la      $t6,obufe               # printing till the end of buffer
    subu    $t6,$t6,1               # this is the last character
    sb      $zero,0($t6)            # storing value
    move    $t5,$s0                 # getting number

All functions must be added to the main program for a successful compilation.


Related Solutions

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
4.Translate the following C code to MIPS assembly code. Assume that the value of i is...
4.Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i]; 6.Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds...
(Make sure in Mips!!!) Use the correct “syscall” to create MIPS programs for the following. !!!...
(Make sure in Mips!!!) Use the correct “syscall” to create MIPS programs for the following. !!! please use comments and ALWAYS use the correct syscall program code to end the program. !!! 1) Write a program in MIPS which asks the user to enter their favorite type of pie. The program should then print out "So you like _____ pie", where the blank line is replaced by the pie type entered. ALSO: What annoying feature of syscall service 4 makes...
(Make sure in Mips!!!) Use the correct “syscall” to create MIPS programs for the following. !!!...
(Make sure in Mips!!!) Use the correct “syscall” to create MIPS programs for the following. !!! please use comments and ALWAYS use the correct syscall program code to end the program. !!! 1) Write a program to prompt, read, and then print a floating point number. ALSO NEEDED: What is strange about the registers used for this program???
(Make sure in Mips) Use the correct “syscall” to create MIPS programs for the following. !!!...
(Make sure in Mips) Use the correct “syscall” to create MIPS programs for the following. !!! please use comments and ALWAYS use the correct syscall program code to end the program. !!! 1) Explain the difference between an address and a value for data stored in memory. (this isn't a program just a basic question I also need.) 2) Write a program to print out a random number from 1..100. Hint: Use random int range syscall 42, be mindful on...
write the code of 4 digit 7-segment display using arduino uno in assembly language by using...
write the code of 4 digit 7-segment display using arduino uno in assembly language by using software AVR STUDIO 5.1?
4. Translate the following C code to MIPS assembly (in two separate files). Run the program...
4. Translate the following C code to MIPS assembly (in two separate files). Run the program step by step and observe the order of instructions being executed and the value of $sp. int main() { int x=2; z=Subfunc(x); printf(“Value of z is: %d”, z); } int Subfunc(int x) { return x+1;} Submission file: Lab4_4a.asm and Lab4_4b.asm
convert following C++ code into MIPS assembly: int main() {                                 &
convert following C++ code into MIPS assembly: int main() {                                         int x[10], occur, count = 0;                                                              cout << "Type in array numbers:" << endl; for (int i=0; i<10; i++) // reading in integers                               { cin >> x[i];        } cout << "Type in occurrence value:" << endl;                                 cin >> occur;                                                 // Finding and printing out occurrence indexes in the array                                  cout << "Occurrences indices are:" <<...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT