2013-10-14 9 views
0

을 .space 사용. 내가 값에 입력 할 때마다, QTSPIM는 내가 레지스터에 저장 어떤 임의의 값으로 가정 268,501,016 밖으로 뱉어.나는 그것이 배열을 채울 때까지 배열로 사용자 입력 정수를 추가하는 루프를 만들기 위해 노력하고

내 프로그램이 전체 루프를 통과하는지 테스트하려면 프로그램이 내 beq의 분기 부분에 도달했을 때 아스키 라인에 대한 호출을 추가했습니다. 프로그램은 비록 값이 (적어도 내 이해에) 동등하지 않더라도 분기하는 것처럼 보였다. 내가 생각할 수있는

.data 
array1: .space 24 
str1: .ascii "Type in numbers:" 
str2: .ascii "Reached Terminate" 

.text 

main: 

li $t2, 5 
li $t3, 0 

loop1: 
beq $t3, $t2, terminate #branch if equal 
la $a0, str1 
syscall 

ori $v0, $0, 5 #instruction to store user input in v0 
syscall  #get user input and store it in v0 

la $t4, array1 #load the address of the array 
addu $t0, $0, $v0 #add v0 (our user input) to $t0 
sw 0($t4), t0 #stores the value in $t4 to our array 
addi $t3, $t3, 1 #add 1 to t3 (incrementing the counter) 
addi $t4, $t4, 4 $add 4 to increment the array 4 bits to the next array slot 
jal loop1 

terminate: 

la $a2, str2 #load the string to check when the program reaches terminate 
syscall 
ori $v0, $0, 10 # end the program 
syscall 

유일한 것은 내 점프 호출이 다시 loop1은에 예정되지 않는 것입니다,하지만, 이러한 경우 그 문제를 해결하는 방법을 모르고입니다.

32 MIPS 비트 코드이다.

답변

0

syscalls 전에 레지스터를 올바르게 설정하지 않았습니다. 우리는 당신이 여기 str2를 인쇄하려고한다고 가정하면

la $a0, str1 
syscall 

에서, syscall 전에 li $v0, 4이 있어야하고, $a0이 사용되어야한다 : 여기

는이 li $v0, 4 syscall 전에이 있어야한다 $a2 대신 :

la $a2, str2 #load the string to check when the program reaches terminate 
syscall 

jal loop1 
:

sw 0($t4), t0 

jal (jal 함수 호출에 사용)하지 j을해야한다 :

sw $t0, 0($t4) 다른 방법은 주위를해야한다