[Asembler][MIPS] Dzielnie restytucyjne dwoch liczb

kejkun7
Użytkownik
Użytkownik
Posty: 405
Rejestracja: 24 lip 2012, o 23:16
Płeć: Mężczyzna
Lokalizacja: hmm ?
Podziękował: 147 razy
Pomógł: 2 razy

[Asembler][MIPS] Dzielnie restytucyjne dwoch liczb

Post autor: kejkun7 »

Moim zadaniem jest napisanie w MIPS assembly programu, który dzieli dwie liczby podane przez uzytkownika restytucyjnie.

Tutaj mozna znalezc algorytm:

pod ' Sequential Restoring Division '

Tutaj mozna znalezc cały kod:
:

Kod: Zaznacz cały

  .data
        GETDivisor:           .asciiz "Enter Divisor (dzielnik) "
        GETDividend:           .asciiz "Enter Dividend (dzielna) >(dzielnik) "
        QMSG:           .asciiz "Q = "
        RMSG:           .asciiz "R = "
        NL:             .asciiz "\n"
        ERR:            .asciiz "Divide by zero error\n"
        left:           .word 1
        right:          .word 1
    	jedynka:		.word 1
    .text
    
    .global main
    main:
        # Prompt for an integer Divisor :
        li $v0, 4                            
        la $a0, GETDivisor                          
        syscall                                     
        # Read A from user
        li $v0, 5                              
        syscall                              
     
        move $t0, $v0    
    	
        # Prompt for an integer dividend :
        li $v0, 4                             
        la $a0, GETDividend                     
        syscall     
     
        # Read B from user
        li $v0, 5                               
        syscall                   
    	
        move $a1, $v0                          
    
    # $t0 Divisor-(dzielnik) , #a1 dividend(dzielna)
     mul $t1, $t0, -1        # w t1 mam zaprzeczenie 
     # $t0 Divisor-(dzielnik) ,#t1 '2’s complement' of divisor zaprzeczenie dzielnika
    # #a1 dividend(dzielna)
     
     li $a2,0  #  upper-half of dividend!
     # $t0 Divisor-(dzielnik) ,$t1 ($t0 '2’s complement')  -1*dzielnik ,  
     # $a1 lower-half of dividend(dzielna), $a2 upper-half of dividend(dzielna)
     
     # 1. Write MSB from lower half,  2. shake-left upper-half, 
     #3. LSB upper-half =MSB from point 1.   4. shake-left lower-half
     
     # Integer 1 -> $a1
    # Integer 2 -> $a2
    # Result -> $a3
    # Setting up retreiving mask
    
    xor     $t2, $t2, $t2
    lui     $t2, 0x8000
    #R8  [t2] = 10000000000000000000000000000000
    
    # 1. write MSB from lower half:
    # Extracting MSB from $a1:  1*1 = 1 only 1st bit then $t3=10000000000000000000000000000000, else $t3=0
    and     $t3, $a1, $t2
    
    
    # Moving MSB to LSB      if $t3=0 then the same,if $t3=10000000000000000000000000000000 then $t3=1
    srl     $t3, $t3, 31
     #2. shake-left upper-half:
     sll $a2, $a2, 1 
     #3. LSB upper-half =MSB
    # adding bit to another int:
    # Setting up setting mask  $t2=1
    xor     $t2, $t2, $t2
    li      $t2, 0x0001
    
    
    #im taking 1-st bit from $a1  and paste in LSb of $a2 and store result in $a3  
    #  , for example $a1 = -5 ->MSB=1,   $a2=4 [100] , $a3 = 5 [101]
    # second example: #a1 = 8 [00..100] msb=0, $a2=5 [101]  , $a3= 4 [ 100]
    # Applying r = a ^ ((a ^ b) & mask)
    # a = $a2
    # b = $t3
    # mask = $t2
    xor     $t4, $a2, $t3
    and     $t4, $t4, $t2
    xor     $a3, $a2, $t4
    
    # $a2 = $a3 to make! how to ? !
     
     #4. shake-left lower-half
     
      sll $a1, $a1, 1
    
    
    
    
    exit_program:
        li $v0, 10                       
        syscall
    swl $t0, left
        lwl $a0, left  
    

Mam problem go skonczyc..
Jednym z wiekszych problemow jest dodany bit [znaku], nie wiem jak to sprytnie zrobić
Ostatnio zmieniony 18 sty 2014, o 20:41 przez Afish, łącznie zmieniany 1 raz.
Powód: Poprawa wiadomości.
ODPOWIEDZ