Booth's Algorithm in MIPS

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

Thread Status:
Not open for further replies.
  1. cyrow

    cyrow New Member

    Joined:
    Nov 19, 2007
    Messages:
    21
    Likes Received:
    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
    
    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 20, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice