# Booth's Algorithm in MIPS

Discussion in 'Assembly Language Programming (ALP) Forum' started by cyrow, Nov 20, 2007.

Not open for further replies.
1. ### cyrowNew Member

Joined:
Nov 19, 2007
Messages:
21
0
Trophy Points:
0
I have been work on this program, but I am having problems in rectifying the errors. Help me..text
Code:
```* 12 bits register
* 8 bits anwer
* 4 bits multiplier and multiplicant
* user must enter multiplier and multiplicant
* print the results in both decimal and binary

.globl main
main:

li \$v0, 4	#Enter multiplicant
la \$a0, msg1
syscall
li \$v0, 5
syscall
move \$a0, \$v0

li \$v0, 4	#Enter multiplier
la \$a0, msg2
syscall
li \$v0, 5
syscall
move \$a1, \$v0

li \$v0, 0
li \$t1, 0
li \$t0, 12 	# twelve bits

algorithm:
and \$t2, \$a0, 24 #24 bit mask
sll \$t2, \$t2, 1
or \$t2, \$t2, \$t1
beq \$t2, 2, check10
beq \$t2, 1, check01
b shift

check10: 	sub \$v0, \$v0, \$a1
b shift

shift:
and \$t1, \$a0, 16 #16 bit mask
and \$t2, \$v0, 8  #8 bit mas
sll \$t2, \$t2, 31
srl \$a0, \$a0, 1
or \$a0, \$a0, \$t2
sra \$v0, \$v0, 1
sub \$t0,\$t0, 1
bnez \$t0, algorithm

# Printing the 8 bits results (\$v0,\$a0)
li		\$v0, 4
la		\$a0, msg3
syscall
li		\$v0,1
move		\$v0, \$a0
syscall

.data
msg1: .asciiz"\nEnter multiplicand"
msg2: .asciiz"\nEnter multiplier"
msg3: .asciiz"\nThe Eight bits result is"```

Last edited by a moderator: Nov 20, 2007

Joined:
Jul 12, 2004
Messages:
15,287
364
Trophy Points:
83