2015-01-28 2 views
1

그래서 저는 MIPS 32를 배웠고 사용자로부터 정수 값을 얻은 다음 다시 인쇄해야했습니다. 여기에 내가 가지고있는 것입니다 :mips 32 정수 값이 인쇄되지 않습니다

.text 

    main: 
    la $a0, str1 #put the address of the string to display in register $a0 
    li $v0, 4  #move 4 to the register $v0. This is the system service to display string messages 
    syscall  #system call to output str1 

    li $v0, 5  #load system service to read integer 
    syscall  #Integer inputted is saved to register $v0 
    sw $v0, x  #store contents of $t0 into x, x = $t0 

    la $a0, x  #put the address of x to display in $a0 
    li $v0, 4  #4 = system service to display strings 
    syscall  #system call to output x 


    .data 
    x: .word 0 
    y: .word 0 
    z: .word 0 
    str1: .asciiz "Please enter the value for X:"; 
    str2: .asciiz "Please enter the value for Y:"; 
    str3: .asciiz "Please enter the value for Z:"; 

입력하면 'r'이 콘솔 창에 인쇄됩니다.

답변

1

우리가 MARS을 말하는 것으로 가정하면 호출 5는 $v0에 정수를 반환하고 호출 4는 NULL로 끝나는 ASCII 문자열을 인쇄합니다. 정수는 NULL로 끝나는 ASCII 문자열이 아닙니다.

마지막 호출을 서비스 1에 대한 호출로 대체하고 해당 주소가 아닌 x의 계산식으로 바꾸는 것이 좋습니다. 따라서 :

lw $a0, x  #put the address of x to display in $a0 
li $v0, 1  #1 = system service to display an integer 
syscall  #system call to output x 
+1

'$ a0'은 주소가 아닌 실제 값으로 설정되어야합니다. – Michael

관련 문제