Question

In: Computer Science

Assume a user wants to classify numbers in terms of whether they are “divisible by 2”,...

Assume a user wants to classify numbers in terms of whether they are “divisible by
2”, “divisible 3”, “both visible by 2 and 3” and “neither divisible by 2 nor 3”. Clearly
for each integer, only one of the classes is most accurate.
Write a SPIM program which allows a user to enter 5 integers and for each of them,
determines which of the mentioned classes it belongs to.

Solutions

Expert Solution

.LC0:

        .ascii "Enter number\000"

.LC1:

        .ascii "%d\000"

.LC2:

        .ascii "Divisible by 2 only\000"

.LC3:

        .ascii "Divisible by 3 only\000"

.LC4:

        .ascii "Divisible by 2 & 3 only\000"

.LC5:

        .ascii "Not Divisible by 2 and 3\000"

main:

        daddiu $sp,$sp,-48

        sd      $31,40($sp)

        sd      $fp,32($sp)

        sd      $28,24($sp)

        move    $fp,$sp

        lui     $28,%hi(%neg(%gp_rel(main)))

        daddu   $28,$28,$25

        daddiu $28,$28,%lo(%neg(%gp_rel(main)))

        li      $2,5                        # 0x5

        sw      $2,0($fp)

        b       .L2

        nop

.L7:

        ld      $2,%got_page(.LC0)($28)

        daddiu $4,$2,%got_ofst(.LC0)

        ld      $2,%call16(puts)($28)

        move    $25,$2

1:      jalr        $25

        nop

        daddiu $2,$fp,4

        move    $5,$2

        ld      $2,%got_page(.LC1)($28)

        daddiu $4,$2,%got_ofst(.LC1)

        ld      $2,%call16(__isoc99_scanf)($28)

        move    $25,$2

1:      jalr        $25

        nop

        lw      $2,4($fp)

        andi    $2,$2,0x1

        bne     $2,$0,.L3

        nop

        lw      $2,4($fp)

        move    $4,$2

        move    $3,$4

        move    $2,$3

        dsll    $2,$2,2

        daddu   $2,$2,$3

        dsll    $5,$2,4

        daddu   $2,$2,$5

        dsll    $5,$2,8

        daddu   $2,$2,$5

        dsll    $5,$2,16

        daddu   $2,$2,$5

        daddu   $2,$2,$3

        dsrl    $2,$2,32

        sll     $3,$2,0

        sra     $2,$4,31

        subu    $3,$3,$2

        move    $2,$3

        sll     $2,$2,1

        addu    $2,$2,$3

        subu    $2,$4,$2

        beq     $2,$0,.L3

        nop

        ld      $2,%got_page(.LC2)($28)

        daddiu $4,$2,%got_ofst(.LC2)

        ld      $2,%call16(puts)($28)

        move    $25,$2

1:      jalr        $25

        nop

        b       .L2

        nop

.L3:

        lw      $2,4($fp)

        move    $4,$2

        move    $3,$4

        move    $2,$3

        dsll    $2,$2,2

        daddu   $2,$2,$3

        dsll    $5,$2,4

        daddu   $2,$2,$5

        dsll    $5,$2,8

        daddu   $2,$2,$5

        dsll    $5,$2,16

        daddu   $2,$2,$5

        daddu   $2,$2,$3

        dsrl    $2,$2,32

        sll     $3,$2,0

        sra     $2,$4,31

        subu    $3,$3,$2

        move    $2,$3

        sll     $2,$2,1

        addu    $2,$2,$3

        subu    $2,$4,$2

        bne     $2,$0,.L5

        nop

        lw      $2,4($fp)

        andi    $2,$2,0x1

        beq     $2,$0,.L5

        nop

        ld      $2,%got_page(.LC3)($28)

        daddiu $4,$2,%got_ofst(.LC3)

        ld      $2,%call16(puts)($28)

        move    $25,$2

1:      jalr        $25

        nop

        b       .L2

        nop

.L5:

        lw      $2,4($fp)

        move    $4,$2

        move    $3,$4

        move    $2,$3

        dsll    $2,$2,2

        daddu   $2,$2,$3

        dsll    $5,$2,4

        daddu   $2,$2,$5

        dsll    $5,$2,8

        daddu   $2,$2,$5

        dsll    $5,$2,16

        daddu   $2,$2,$5

        daddu   $2,$2,$3

        dsrl    $2,$2,32

        sll     $3,$2,0

        sra     $2,$4,31

        subu    $3,$3,$2

        move    $2,$3

        sll     $2,$2,1

        addu    $2,$2,$3

        subu    $2,$4,$2

        bne     $2,$0,.L6

        nop

        lw      $2,4($fp)

        andi    $2,$2,0x1

        bne     $2,$0,.L6

        nop

        ld      $2,%got_page(.LC4)($28)

        daddiu $4,$2,%got_ofst(.LC4)

        ld      $2,%call16(puts)($28)

        move    $25,$2

1:      jalr        $25

        nop

        b       .L2

        nop

.L6:

        ld      $2,%got_page(.LC5)($28)

        daddiu $4,$2,%got_ofst(.LC5)

        ld      $2,%call16(puts)($28)

        move    $25,$2

1:      jalr        $25

        nop

.L2:

        lw      $2,0($fp)

        addiu   $3,$2,-1

        sw      $3,0($fp)

        bne     $2,$0,.L7

        nop

        move    $2,$0

        move    $sp,$fp

        ld      $31,40($sp)

        ld      $fp,32($sp)

        ld      $28,24($sp)

        daddiu $sp,$sp,48

        j       $31

        nop


Related Solutions

In C++ Prompt user to enter two integers •Determine whether the first number is divisible by...
In C++ Prompt user to enter two integers •Determine whether the first number is divisible by the second. If the second number is zero, the program should not do division •Output the remainder of the two numbers •Compare the two integers, display the integers in non-decreasing order.
using python 3 2. Write a python program that finds the numbers that are divisible by...
using python 3 2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000. 3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False. 4. In your...
using python 3 2. Write a python program that finds the numbers that are divisible by...
using python 3 2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000. 3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False. 4. In your...
Assume user will enter letters or numbers that are out of range. When user inputs invalid...
Assume user will enter letters or numbers that are out of range. When user inputs invalid values, show an alert message and ask user to enter a valid value again. Validate first and then proceed with the program. isNaN() method may be useful. Must validate user input. 1. Suggested Filename: fortune.html & fortune.js Write a program that simulates a fortune cookie. The program should display one of five unique fortunes, depending on user input. The user must enter a number...
How many numbers between 9 and 3009 are divisible by 2, 5, or 11? Please answer...
How many numbers between 9 and 3009 are divisible by 2, 5, or 11? Please answer correctly. Thanks
2. Classify the Sedimentary Rocks according to their depths and evaluate them in terms of their...
2. Classify the Sedimentary Rocks according to their depths and evaluate them in terms of their usability as foundation, tunnel and material (such as aggregate, anchoring, building block).
Prompt user to enter 2 integer numbers from console, compare and display these 2 numbers from...
Prompt user to enter 2 integer numbers from console, compare and display these 2 numbers from small to great. This is required to be done in MIPS assembly language.
(Prime Numbers) An integer is said to be prime if it is divisible by only 1...
(Prime Numbers) An integer is said to be prime if it is divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. Write pseudocode and function called isPrime that receives an integer and determines whether the integer is prime or not. Write a test program that uses isPrime to determine and print all the prime numbers between 1 and 1000. Display 10 numbers per line. Twin primes...
Suppose a user wants to do a system call. Assume that the service routine of this...
Suppose a user wants to do a system call. Assume that the service routine of this system call is at physical address 500., instead of executing a system call, the user simply jumps to this location 500. Assume that logical and physical addresses are the same and no memory protection is in place, i.e., cpu does not check that this address 500 is beyond the user’s memory space. Will something go wrong while the service routine executes?
Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers...
Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are even iii) Multiplies the two numbers if they are odd iv) Displays the appropriate output to the user You are writing 4 functions and calling them to test functionality. RUN in IDLE
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT