是否可能将两个不同的阵列相互比较?

时间:2017-04-25 07:00:04

标签: arrays assembly mips

假设你有数组A = ['1','1','1']和数组B = ['1','1','0'];如何在MIPS汇编中比较阵列的元素?

以下是代码示例:

# syscall codes
PRINT_STRING = 4

    .data
    .align  2

ArrayA:
    .word   1, 1, 1

ArrayB: 
    .word   1, 1, 0

true:
    .asciiz "True!"
false:
    .asciiz "False!"

    .text
    .align  2

# Compares the two Arrays
main:
    la  $t0, ArrayA     # Loads the address of ArrayA into t0
    la  $t1, ArrayB     # Loads the address of ArrayB into t1

    beq $t0, $t1, T     # If ArrayA == ArrayB; then goto T
    bne $t0, $t1, F     # If ArrayA != ArrayB; then goto F


T:
    li  $v0, PRINT_STRING   # Prints True
    la  $a0, true       
    syscall

F:
    li  $v0, PRINT_STRING   # Prints False
    la  $a0, false       
    syscall

提前致谢!

0 个答案:

没有答案