[英]MIPS - How to perform a shift on a string?
我對MIPS編程非常陌生,但是我一直試圖解決一個編程問題。 我意識到我要做的事可能很愚蠢,但請忍受! 這是我要嘗試做的描述。
假設我有以下字符串:“ ~~ Hello World!”。 我想獲取字符串“ Hello World!”。 將此字符串向左移動兩個字符。 到目前為止,我最接近執行此操作的嘗試是:
讓寄存器$ t0包含字符串“ ~~ Hello World!”。 我想對該字符串執行2位左移並將其存儲在寄存器$ t1中。
.data
output1: .asciiz "The value in $t1 is: "
.text
sll $t1, $t0, 2 # attempt at shifting left by 2 bits
li $v0, 4
la $a0, output1
syscall # print "The value in $t1 is: "
li $v0, 4
move $a0, $t1
syscall # print the contents of the register $t1
但是,當我匯編這些指令時,遇到地址超出范圍錯誤。 誰能指出我要去哪里錯了,也許我應該怎么做才能做到這一點?
我知道了! 這是一個更新的代碼段,現在包含工作說明。 如果有其他幫助,我將保留此帖子。
.data
output1: .asciiz "The value in $t1 is: "
.text
add $t0, $t0, 2 # shifts the string left by 2 bits (CORRECT)
li $v0, 4
la $a0, output1
syscall # print "The value in $t1 is: "
li $v0, 4
move $a0, $t1
syscall # print the contents of the register $t1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.