0

我正在为我的汇编语言课程分配作业,并且我陷入了按位运算,我得到了第一个字符没有任何问题,但是当我继续在循环中进行时,我设置的临时 var 没有做什么它假设并且认为这一切都发生在这组指令中:

addi $t2, $t2, -5   # bits -=5
 srlv $t3, $t0, $t2 #newTempVar = buffer >> bits
 and $t4,$t3,0x1F   #temp = newTempVar & 0x1F

 la $s0, chars      #load the address of the first element of string: chars
 addu  $s0,$s0,$t4  #get the character in the possition $t4 
 lb $a0, ($s0)      #load the character in memory
 li $v0, 11         #function print character             
 syscall
 move $t4, $0

这是整个代码:

.data
      chars:    .ascii "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,!-'"
       msg1:    .word 0x93EA9646, 0xCDE50442, 0x34D29306, 0xD1F33720
    msg1end:    .word 0x56033D01, 0x394D963B, 0xDE7BEFA4
     msglen:   .word 16   

.text
   .globl main

main:   

    la $s1, msg1
    lbu $s0, ($s1)
    #la $s2, msg1end
    addu $s2,$s0,16
    #la $t0, buffer     
    li $t0, 0   #set buffer = 0

    addi $t1, $t1, 0    #index
    addi $t2, $t2, 0    #bits
    lw $t5, ($s1)       #*msg1

while:
    bgt $t5,$s2,endwhile
    if: 
      bgt $t2, 5,endif

      addi $s1,$s1, 4   # next element in the array
      addi $t1, $t1, 1  #increment the index
      lw $t5, ($s1)     #msg1

      move $t4, $t5     #temp = nextbyte++

      sll $t3, $t0,8    # newTemp = buffer << 8
      or $t0, $t3, $t4  # buffer = newTemp | temp
      addi $t2, $t2, 8
      move $t4, $0

    endif:
      addi $t2, $t2, -5     # bits -=5
      srlv $t3, $t0, $t2    #newTempVar = buffer >> bits
      and $t4,$t3,0x1F      #temp = newTempVar & 0x1F

      la $s0, chars     #load the address of the first element of string: chars
      addu  $s0,$s0,$t4 #get the character in the possition $t4 
      lb $a0, ($s0)     #load the character in memory
      li $v0, 11         #function print character             
      syscall
      move $t4, $0
      j while         #jump back to the while loop

endwhile:
    li,$v0,10
    syscall

我非常感谢您的帮助

4

0 回答 0