Solved

Assembly language: dividing

Posted on 2007-04-11
7
565 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
Independent Software Vendors: 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

726 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