write a MIPS program that calculates d=a*b-a*c without using mult instruction --- just for practicing your MIPS assembly.

  1. • Hint: use loop of additions to replace mult.
  2. • Practice SPIM system calls to input values for a, b and c, as well as printout the value of d.

Recommended Answers

All 3 Replies

If you signed up for piano lessons, but then decided that you didn't feel like taking them, would you ask somebody to go in your place?

And the answer is:

###################################################
# author: Andor Pásztor
###################################################


#################################################
#		text segment	  								   #
#################################################
.text
.globl main
main:

la $a0, str1
li $v0, 4
syscall
li $v0, 5
syscall
or $t0, $v0, $v0 

la $a0, str2
li $v0, 4
syscall
li $v0, 5
syscall
add $t1, $v0, 0

la $a0, str3
li $v0, 4
syscall
li $v0, 5
syscall
add $t2, $v0, 0

add $t7, $t0, $zero 
startMul: # mult loop
blez $t7, endMult 
add $t3, $t3, $t1
add $t4, $t4, $t2
sub $t7, $t7, 1
j startMul

endMult:
sub $t5, $t3, $t4
la $a0, str4
li $v0, 4
syscall
move $a0, $t5
li $v0, 1
syscall

li $v0, 10
syscall

#################################################
#     	 	data segment								#
#################################################
.data

str1: .asciiz "input a = "
str2: .asciiz "input b = "
str3: .asciiz "input c = "
str4: .asciiz "The result is "
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.