Announcement

Collapse
No announcement yet.

Vettori - Sorting

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Vettori - Sorting

    Code:
    #vet a 10 ele
    #vet b 10 ele
    #vet c 20 ele
    #a e b ordinati, fare il sort in c
    #
    #
    #$1=i
    #$2= spiaz i
    #$3= j
    #$4= spiaz j
    #$5= k
    #$6= spiaz di k
    #$7= slti i<10, slti j<10, slt a[i] < b[j]
    #$8= b[j]
    #$9 = a[i]
    #$10 = ind c[k]
    #
    #                k=-1
    #                j=0
    #                for(i=0;i<10;i++){
    #                                for (; j<10 && b[j] < = a[i];j++){
    #                                                    k=k+1;
    #                                                    c[k]=b[j]
    #                                }
    #                k=k+1
    #                c[k]=a[i]
    #               }
    #
    %veta = 1100
    %vetb = 1200
    %vetc = 1300
    %start = 1400
                    addi $5,$0,-1 #init k -1
                    add $3,$0,$0 #init j
                    add $4,$0,$0 # spiaz j
                    add $1,$0,$0 # init i
                    add $2,$0,$0 # spiaz i
    inizio_for:     slti $7,$1,10 # i<10 ?
                    beq $7,$0,fine_for
    inizio_for_2:   slti $7,$3,10 # j<10 ?
                    beq $7,$0,fine_for_2
                    addi $8,$4,1200 # indirizzo di b[j]
                    lw $8,0($8) # b[i] in $8
                    addi $9,$2,1100 # indirizzo di a[i]
                    lw $9,0($9) # a[i] in $9
                    slt $7, $9,$8 # slt a[i] < b[j]
                    bne $7,$0,fine_for_2
                    addi $5,$5,1 # k=k+1
                    add $6,$5,$5 # spiaz k
                    add $6,$6,$6
                    addi $10,$6,1300 # indirizzo c[k]
                    sw $8, 0 ($10) # c[k]= b[j]
                    addi $3,$3,1 #j=j+1
                    add $4,$3,$3 # spiaz j
                    add $4,$4,$4
                    j inizio_for_2        
    fine_for_2:     addi $5,$5,1 # k=k+1
                    add $6,$5,$5 # spiaz k
                    add $6,$6,$6
                    addi $10,$6,1300 #indirizzo di c[k]
                    sw $9,0($10) #c[k]= a[i]
                    addi $1,$1,1 #i=i+1
                    add $2,$1,$1 # spiaz i
                    add $2,$2,$2
                    j inizio_for
    fine_for:       add $0,$0,$0
    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
Working...
X

Google Profile


My name is Giovanni Di Grezia, but people call me xgiovio.

Here is my homepage:.

I'm a VFX Artist and Software Developer.

Giovanni Di Grezia