2012-03-08 3 views
0

그래서 일부 코드를 디버깅하고 계속 이상한 결과가 나옵니다. 배열을 반복하고 각 요소를 콘솔에 인쇄합니다. 각 요소를 인쇄 한 후에는 "\ n", 줄 바꿈 문자로만 구성된 문자열을 인쇄하려고합니다. QtSpim에서 코드를 실행합니다. 내가 할 때 새로운 줄과 다음 줄 str3을 출력한다. 나는 단지 str2를 출력하기를 원하므로 다음 줄을 인쇄 할 준비가되어있다. 누구나 이와 같은 문제가 발생하거나 내 코드에 문제가있는 것을 볼 수 있습니다.코드가 지정된 문자열을 읽는 중입니다.

문제 .ascii와 차이를 알고 있어야 사람 .asciiz 상기 조사 결과 print_sorted_data 기능

.data   
    x: .word 1,2,3,4,5,6,7,8 #OR x: .space 32 #since x contains 8 words,we have to reserve 32 bytes.  
    min: .word 0 
    max: .word 0 
    mean: .word 0 
    str1: .ascii "\n The Min, Max and Mean of the array are : \n " 

    str2: .ascii " \n" 

    str3: .ascii "Enter Number: \n" 

.text 
#======================================================================= 
main: 
#======================================================================= 

    #Push $ra into stack 
addi $sp, $sp, -4 
sw $ra, 0($sp) 

#------------------------------------------------------------------- 
#***jal read_data 
#***nop 
#------------------------------------------------------------------- 

la $a0, x 
ori $a1, $0, 8 

#------------------------------------------------------------------- 
jal print_sorted_data 
nop 
#------------------------------------------------------------------- 




jr $ra 
nop 

#======================================================================= 
read_data: 
#======================================================================= 
    #reading data from console , storing it in memory 
    #initialization for the counter of the loop 

addi $t1, $0, 0  ## $t1<-stores counter for loop. 

## don't need addi $t2, $0, 8  ## max value of loop 

#lodad The base adderss of array 
la $t0, x 

check_cond1: ############################## 
     #check condition of the loop, if not met branch to read_done 

slti $t3, $t1, 8 
beq $t3, $0, read_done1 
nop 

     #read an int from console and store it in &x[i] 

ori $v0, $0, 4 ## print " enter number" to screen 
la $a0, str3 ## changed lw to la 
syscall 

ori $v0, $0, 5 
syscall 
sw $v0, 0($t0) 

    #update both counter of the loop and pointer to the next element in the array 

addi $t1, $t1, 1 
addi $t0, $t0, 4 

j check_cond1 
nop 

read_done1: 
jr $ra 
nop 

#======================================================================= 
#printing the sorted data 
print_sorted_data: 
#======================================================================= 
    #initialization for the counter of the loop 
    #lodad The base adderss of array 

ori $t9, $a0, 0 ## We get base address in $a0 
ori $t0, $0, 0 ##counter for loop 


check_cond2: ############################## 
     #check condition of the loop, if not met branch to print_done1 

slt $t1, $t0, $a1 
beq $t1,$0, print_done1 

    #print x[i] 
sll $t2,$t0 ,2 ## Multiply counter by 4 for offset 
add $t2, $t2, $t9 ## Add to base address 

ori $v0, $0, 1 ## set syscall up to print integer 
lw $a0, 0($t2) 
syscall ## not sure if this is right func name## it is 

    #go to next line by printing "\n" 

ori $v0, $0, 4 ## set syscall up to print string 
la $a0, str2 
syscall 



    #update both counter of the loop and pointer to the next element in the array 
##Dont think i have to update array. It does that in the loop. 

add $t0, $t0, 1 

j check_cond2 
nop 

print_done1: ####################### 
jr $ra 
nop 

**의 초 콜에인가?

답변

1

차이는 .asciiz으로 주어진 문자열 뒤에 오는 0입니다. 기본적으로 .ascii과 거의 동일하며 0 문자 만 추가됩니다.이 문자는 문자열의 종료 문자로 사용됩니다.

따라서 .ascii을 사용하고 수동으로 종료 0을 지정하지 않으면 문자열이 메모리의 다음 데이터와 병합됩니다. \n은 문자열 종료 (회선 종료 만 해당)가 아닙니다.

관련 문제