PLEASE USE SIMPLE MIPS CODE Assignment 2 Write a program in

PLEASE USE SIMPLE MIPS CODE

Assignment 2 Write a program in assembly language that asks the user to input two integers in the range 1 to 1,000 and calculates their product. You can only use shift, add or sub instructions to calculate the multiplication (not the mult instruction). The program should verify that both integers are within the specified range. If either on the integers are outside this range, the program should display a message \"input range error\" and ask the user to input again. If user persist in entering the wrong integers more than two times, the program should exit and display message \"error limit exceeded.\" Else it should exit after calculating the product of the two integers that are within the specified range.

Solution

.data

err: .asciiz \"\ Input range error, try entering input again\ \"

err1: .asciiz \"\ LIMIT EXCEEDED \ \"

count: INTEGER               1;

result: INTEGER               0;

.code

INPUT:

; input first number

li $v0, 5                       ;initiate service with 5 which is for reading integer from console

syscall                         ;system call with service 5

move $t0, $v0             ; store input into register t0

; input second number

li $v0, 5                      

syscall                        

move $t1, $v0            

; check if first number is in the range, if not exit

cmp     $t0, #1

blt        ERROR

cmp     $t0, #1000

bgt       ERROR

; check if second number is in the range, if not exit

cmp     $t1, #1

blt        ERROR

cmp     $t1, #1000

bgt       ERROR

jmp      MULT

ERROR:

li $v0, 4                             ;system call code for printing string = 4

la $a0, err                       ; load address of string to be printed into $a0

syscall

addi      count,#1             ; input counter becomes 2

cmp count, #2                 ; If 2 let user input once more

je           INPUT

jmp       EXIT

MULT:

mov     $t3, 1               ; loop counter will run from 1 to t0

mov     $t4,0                ; register to store result of multiplication

LOOP:

cmp     $t3, $t0

bgt       EXIT_SUC

add      $t4,$t1             ; add value in t1 t0 times to compute $t0x$t1

addi     $t3,#1

jmp      LOOP

EXIT:

li $v0, 4                            

la $a0, err1                       ; Error limit exceeded   

syscall

EXIT_SUC:

store     result,$t4           ; store the final result into “result”


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site