Solved

Assembly language: dividing

Posted on 2007-04-11
7
564 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 50 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 450 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
Technology Partners: 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!

 
LVL 19

Assisted Solution

by:BrianGEFF719
BrianGEFF719 earned 450 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fizzArray3  challenge 1 107
fix34  challenge 9 168
t-sql sp_addlinkedserver possible risks 3 107
Link failure 16 71
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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

696 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