Solved

Assembly language: dividing

Posted on 2007-04-11
7
557 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
  • 4
7 Comments
 
LVL 3

Author Comment

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

Assisted Solution

by:mr_egyptian
mr_egyptian earned 50 total points
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 19

Assisted Solution

by:BrianGEFF719
BrianGEFF719 earned 450 total points
Comment Utility
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
Comment Utility
Did you have any other questions? Because the code is working fine now.
0
 
LVL 19

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now