Question

In: Computer Science

Solve following tasks using MIPS Task Write a program that gets a number from user and...

Solve following tasks using MIPS
Task

Write a program that gets a number from user and displays “Even”, or “Odd. (If-else)


Write a program that input a number from user displays each digit separately. For example if input is 3986, output is  6, 8, 9 ,3. (Loop)


Write a program that converts a decimal number to binary. (Loop)


Hint for Task 1 and Task 3.

    Use, div $tdivident,$tdivider and mfhi $tdestination instructions.

For example,

Div $t1,$t2 will divide $t1 from $t2 and move the quotient to LOW register and remainder to HI        register

mfhi $t3 will move remainder from HIGH register to $t3.

Solutions

Expert Solution

Answer.)

Write a program that gets a number from user and displays “Even”, or “Odd. (If-else)

Solution:

.file   1 ""
        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=32
        .module nooddspreg
        .abicalls
        .rdata
        .align  2
$LC0:
        .ascii  "Enter a number?\000"
        .align  2
$LC1:
        .ascii  "%d\000"
        .align  2
$LC2:
        .ascii  "Even\000"
        .align  2
$LC3:
        .ascii  "Odd\000"
        .text
        .align  2
        .globl  main
        .set    nomips16
        .set    nomicromips
        .ent    main
        .type   main, @function
main:
        .frame  $fp,40,$31              # vars= 8, regs= 2/0, args= 16, gp= 8
        .mask   0xc0000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .cpload $25
        .set    nomacro
        addiu   $sp,$sp,-40
        sw      $31,36($sp)
        sw      $fp,32($sp)
        move    $fp,$sp
        .cprestore      16
        movz    $31,$31,$0
        lw      $2,%got($LC0)($28)
        nop
        addiu   $4,$2,%lo($LC0)
        lw      $2,%call16(printf)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,printf
1:      jalr    $25
        nop

        lw      $28,16($fp)
        addiu   $2,$fp,24
        move    $5,$2
        lw      $2,%got($LC1)($28)
        nop
        addiu   $4,$2,%lo($LC1)
        lw      $2,%call16(__isoc99_scanf)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,__isoc99_scanf
1:      jalr    $25
        nop

        lw      $28,16($fp)
        lw      $2,24($fp)
        nop
        andi    $2,$2,0x1
        bne     $2,$0,$L2
        nop

        lw      $2,%got($LC2)($28)
        nop
        addiu   $4,$2,%lo($LC2)
        lw      $2,%call16(printf)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,printf
1:      jalr    $25
        nop

        lw      $28,16($fp)
        b       $L3
        nop

$L2:
        lw      $2,%got($LC3)($28)
        nop
        addiu   $4,$2,%lo($LC3)
        lw      $2,%call16(printf)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,printf
1:      jalr    $25
        nop

        lw      $28,16($fp)
$L3:
        move    $2,$0
        move    $sp,$fp
        lw      $31,36($sp)
        lw      $fp,32($sp)
        addiu   $sp,$sp,40
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    main
        .size   main, .-main
        .ident  "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"

Related Solutions

write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
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 program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user to enter an integer, and then output the number of 1’s and 0’s that are present in the integer’s signed 32-bit binary representation. For example, 15 has a binary representation of 0000 0000 0000 0000 0000 0000 0000 1111, which has 28 zeroes and 4 ones. We have provided you the starter code that deals with the input/output logic. The integer input is saved...
Write code in MIPS ,read tow number from the user that do the following: 1- multiply...
Write code in MIPS ,read tow number from the user that do the following: 1- multiply 2- Dividing 3- sum 4- average 5- minimum 6- maximum 7- print message to thank the user for using my program
Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Write MIPs program that will read two intergers from the user and compute for the sum...
Write MIPs program that will read two intergers from the user and compute for the sum and difference of the two intergers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Question) The following simple shell program/code using gets() function to obtain input from user. Using the...
Question) The following simple shell program/code using gets() function to obtain input from user. Using the gets() function is potentially dangerous and it allows buffer to overflow. You need to do following modification in the code; (a) change the provided code so that you now use fgets() function instead of fget() to obtain input from the user, (b) make any other necessary changes in the code because of using fgets() function, and (c) fill in the code for the exectute()...
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       ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT