I cant check if this is write as I have to do it at school. But I wanted to know if you can read over for me.

This is my multiplication

``````add       \$s2, \$zero, \$zero

LOOP:           beq       \$t0, \$s0, EXIT

EXIT:``````

Okay it takes two integers stores them in \$s0 and \$s1

\$s2 is a registry will be the product
\$t0 is the increment

It suppose to loop until the values of \$t0 = \$s0

\$s2 should equal the product of \$s0 and \$s1

``````add       \$t2, \$s0, \$zero

LOOP:           bne       \$t0, \$s0, EXIT
beq       \$s1, \$zero, DividebyZero
beq       \$s0, \$zero, AnsZero

sub       \$t2, \$t2, \$s1
beq       \$t2, \$zero, ANS
j Loop

DividebyZero:

AnsZero:

ANS:

EXIT:``````

This one I am not sure what I am doing. I wrote the code in C++ first and came up with this.

``````#include <iostream>
using namespace std;

int main(){

int i = 0;
int num1, num2;

cout << "Enter Number 1" << endl;
cin >> num1;

cout << "Enter Number 2" << endl;
cin >> num2;

int x = num1;
while(i != num1)
{

if(num2 == 0){
cout << "Divsion by Zero" << endl;
return 0;
}

x -= num2;

if(x <= 0)
{
cout << num1 << " / " << num2 << " " << i << endl;
return 0;
}
i++;
}

if (num1 == 0){
cout << " 0 " << endl;
return 0;
}

}``````

\$s0 and \$s1 are still the numbers as they were before
\$t0 is the increment number

1
Contributor
1
3
Views
9 Years
Discussion Span
Last Post by .11

Didnt see an edit button so I got to double post.

I think I did everything, if some can test and point errors that would be great :)

``````.data

str1:		.asciiz "Enter the first integer: "
str2:		.asciiz "Enter the second integer: "
str3:		.asciiz "Multiplication: "
str4:		.asciiz "Division: "
str5:		.asciiz "Division by zero"
newline:	.asciiz "\n"

.text
la   \$a0, str1
syscall

syscall

la   \$a0, str2
syscall

syscall

add  \$s2, \$zero, \$zero				# Multiplication Start
Loop:		beq  \$t0, \$s0, MEXIT
MEXIT:

la   \$a0, str3
syscall

syscall

syscall

add  \$t2, \$s0, \$zero				# Division Start
beq  \$s0, \$zero, ANSZERO
DLoop:		bne  \$t1, \$s0, EXIT
beq  \$s1, \$zero, DivideByZero

sub  \$t2, \$t2, \$s1
beq  \$s2, \$zero, ANS
j DLoop

ANSZERO:
la   \$a0, str4
syscall

syscall
j EXIT

DivideByZero:
la   \$a0, str5
syscall
j Exit

ANS:
la   \$a0, str4
syscall