0

そのため、配列内の重複する値を削除するプログラムに取り組んできました。私はそれを持っているので、重複した値をすべて出力しますが、実際にそれらを削除する方法がわかりません(下にシフトします)。これが私がこれまでに持っているものです。注:私の質問は「スカッシュ」機能にあります

        .text
test:
    la  $a0,info    # put address of array in $a0
    li  $a1,8       # put length of array in $a1 (words, not bytes)
    jal squash      # call the function

    la      $s0,info    # get address of array
    move    $s1,$v0     # save size of array
loop:
    ble $s1,$0,done
    lw  $a0,0($s0)  # get the next value from the result array
    li  $v0,1       # print it
    #syscall
    la  $a0,eol     # print end of line
    li  $v0,4
    syscall
    addi    $s1,$s1,-1  # decrement count
    addi    $s0,$s0,4   # advance pointer to next value
    b   loop        # print the next value (if one)

done:
    li  $v0,10      # exit
    syscall

# squash out duplicates
#
# $a0 = address of the first element of the array
# $a1 = the number of values (not bytes) in the array
#
# $v0 set to the number of values after duplicates have been removed
squash:
    move    $s0, $a0 #move address to s0
    move    $s1, $a1 #move size to s1
read:
    ble $s1, $0, donea  # (while x > 0) keep looping
    lw  $t0,0($s0)  # get the next 2 value from the result array
    lw  $t1,4($s0)  
    beq $t0, $t1, shift #Branch if two values are equal 
    b   end_if
end_if:
    addi    $s1,$s1,-1  # decrement count (size of arary)
    addi    $s0,$s0,4   # advance pointer to next value
    b   read

shift:
    lw  $a0, 0($s0)
    li  $v0, 1
    syscall
    addi    $s1,$s1,-1  # decrement count (size of arary)
    addi    $s0,$s0,4   # advance pointer to next value
    b   read

donea:              # end of 1st loop

doneb:              #end of 2nd loop    



    jr  $ra

    .data
eol:    .asciiz "\n"
info:
    .word   1
    .word   2
    .word   2
    .word   4
    .word   7
    .word   7
    .word   7
    .word   9
4

0 に答える 0