Как объявить временную переменную и буфер для выполнения побитовых операций над строкой на ассемблере? - PullRequest
0 голосов
/ 13 апреля 2020

Я работаю над заданием для моего класса на ассемблере, и я застрял в побитовых операциях, я без проблем получил первый символ, но пока я продолжаю работать с l oop, временной переменной, которая Я установил не делать то, что предполагалось, и думаю, что все это происходит в этом наборе инструкций:

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

Я действительно ценю помощь

...