?
Solved

Assembly language: dividing

Posted on 2007-04-11
7
Medium Priority
?
566 Views
Last Modified: 2008-02-01
I am writing a program in MIPS assembly language with PCSpim. I want it to be able to Multiply. Here is what I have. Any suggestions?

.data
.globl       firstNum
.globl      secondNum

firstNum:      .asciiz"\nWhat is the First Number?\n"
secondNum:      .asciiz"\nWhat is the Second Number?\n"
space:            .asciiz"\n"

.text
.globl main

main:
addu      $s7, $0, $ra

#Queries user for the first number
li      $v0, 4
la      $a0, firstNum
syscall
li      $v0, 5                  
syscall
add      $t1,$v0,$zero

#Queries user for the second number
li      $v0, 4
la      $a0, secondNum
syscall
li      $v0, 5                  
syscall
add      $t2,$v0,$zero

mul      $t3,$t1,$t2

add      $t4,$t3,$zero
add      $t5,$t3,$zero      

mfhi      $t4
mflo      $t5

#Space
add      $t3,$t4,$t5
li      $v0, 4
la      $a0, space
syscall

add      $a0,$t3,$zero
li      $v0, 1
syscall
addu      $ra, $0, $s7
jr      $ra
add      $0, $0, $0
0
Comment
Question by:TheTechGuysNYC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 3

Author Comment

by:TheTechGuysNYC
ID: 18891338
I'm sorry, the title here should be multiplying..
0
 
LVL 15

Assisted Solution

by:mr_egyptian
mr_egyptian earned 200 total points
ID: 18895681
Check here:

http://www.cs.uic.edu/~i366/notes/MIPS%20Quick%20Tutorial.htm

under 'Arithmetic Instructions'

mult      $t3,$t4
mflo      $t1
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 1800 total points
ID: 18993057
Hi,

I'm not sure what you're doing here:

mul      $t3,$t1,$t2

add      $t4,$t3,$zero
add      $t5,$t3,$zero      

mfhi      $t4
mflo      $t5

You're storing the result in $t3, you then move it to $t4 and $t5? Why are you doing this? I think what you want to do is something like:

mult      $t1,$52  ;$t2 * $t2
mfhi    $t3        ;high 32 bits in $t3
mflo    $t4        ;low 32 bits in $t4

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 19

Assisted Solution

by:BrianGEFF719
BrianGEFF719 earned 1800 total points
ID: 18993066
Your code works fine, here is the output I get when I test it:


What is the first number?
5

What is the second number?
2

10
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 19069347
Did you have any other questions? Because the code is working fine now.
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 19138532
@TheTechGuysNYC, was there anything else that I can clarify for you?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question