我想一個while循環這樣的轉換:while循環與2個條件彙編代碼
i=0;
while ((s[i]!='t') && (i<=20)) {
d[i]=c[i];
i++;
}
2個條件彙編代碼。 我該怎麼做?下面是 的版本,同時有1個條件。
#################################################
# lab3_3a.s #
# while loop char!=ASCII 0 #
#################################################
.text
.globl __start
__start: # execution starts here
li $t1,0 # counter for string
li $s0,'t' # chararacter to end copy
while: lbu $t0,string($t1) # load a character
sb $t0,copy($t1) # copy character
beq $t0,$s0,end # if character to end copy then exit loop
addi $t1,$t1,1 # increment counter
b while # repeat while loop
end: li $t2,0
sb $t2,copy($t1) # append end character to copied string
la $a0,copy # display copy
li $v0,4
syscall
li $v0,10 # exit
syscall
.data
string: .asciiz "Mary had a little lamb"
copy: .space 80
謝謝你們。
我不會爲你寫代碼,但我可以告訴你在彙編中需要檢查兩次--JNE和JLE。另外,什麼是s,d,c? – EvgenyKolyakov
想怎麼做'if(s [i]!='t'&& i <= 20)i ++'首先然後替換body @EvgenyKolyakov MIPS中沒有'jne'和'jle' –
您應該至少顯示您已經擁有一個條件的代碼。並解釋你對'&&'(假定)短路行爲的理解。 –