1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Booth's Algorithm

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

  1. cyrow

    cyrow New Member

    Joined:
    Nov 19, 2007
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    I have been working on this Booth Algorithm in mips. The specifications of th problem are:
    1. Provide a prompt for the multiplicant and the multiplier. 12 bits must be used and since 2 four bits numbers are entered, the answer must be eight (8) bits. Help me identify the problem in this code.
    Code:
    .text
    	.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
    
    check01: 	add $v0, $v0, $a1
    
    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 19, 2007

Share This Page