Solved

Assembly language: dividing

Posted on 2007-04-11
7
563 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
groupNoAdj 7 105
Need To Find FireFox Binary Path For Python Selenium On Windows 7 15 709
Capture logon name 13 87
Work with App store 7 68
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 …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

839 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