Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ok, so I suppose to debug the following code and I think Ialmost have it. But I

ID: 3608466 • Letter: O

Question

Ok, so I suppose to debug the following code and I think Ialmost have it. But I can't figure out this last part.. I'll pastethe code then explain more:
At the marked line below I where Xspim aaand PCSpim (I tried both)gives me an error.. I'm not sure if I'm loading something into thecorrect register or not.. Then we have only had two classes so Idon't dont too much about Assembly yet..

If I'm not mistaken, I believe this code is suppose to read in astring of 8 number and then spit them right back out as singleintegers. Please Help, I WILL RATE..

Below is the code and this is the error I get..
The output is -1, which I'm assuming is the ascii_error, since whenI change the -1, to say -3 I get a -3.. My Spim tells me this..

Read from unusedmemory-mapped IO address (0xffffffff)
# Beginning of code
.data
prompt: .asciiz " Enter a string of numbers up to 8 characters:"
newln: .asciiz " "
str: .space 10
.text
main:
li $v0, 4
la $a0, prompt
syscall                        

li $v0,8                   
li    $a1,10                  
la    $a0,str                 
syscall                        

jalascii_loop                 

li    $v0,1               
syscall                                           

ascii_loop:                            
li    $t4,10                  
addi $t2, $0,0               
move $t1,$a0                 


loop:  
lb     $t1,($t0)             <<<---- Error happens here
la $t3, newln
beq   $t1, $t3,ascii_end                                              
li    $t3,'0'                 
blt   $t1, $t3, ascii_error    
li    $t3,'9'                 
bgt   $t1, $t3, ascii_error
addi $t3, $t1, -48
mul   $t2, $t2, $t4
add   $t2, $t3, $t2
addi $t0, $t0, 1
b     loop

ascii_error:
li    $t2, -1

ascii_end:
move $a0, $t2
jr    $ra Thanks in Advance! Ok, so I suppose to debug the following code and I think Ialmost have it. But I can't figure out this last part.. I'll pastethe code then explain more:
At the marked line below I where Xspim aaand PCSpim (I tried both)gives me an error.. I'm not sure if I'm loading something into thecorrect register or not.. Then we have only had two classes so Idon't dont too much about Assembly yet..

If I'm not mistaken, I believe this code is suppose to read in astring of 8 number and then spit them right back out as singleintegers. Please Help, I WILL RATE..

Below is the code and this is the error I get..
The output is -1, which I'm assuming is the ascii_error, since whenI change the -1, to say -3 I get a -3.. My Spim tells me this..

Read from unusedmemory-mapped IO address (0xffffffff)
.data
prompt: .asciiz " Enter a string of numbers up to 8 characters:"
newln: .asciiz " "
str: .space 10
.text
main:
li $v0, 4
la $a0, prompt
syscall                        

li $v0,8                   
li    $a1,10                  
la    $a0,str                 
syscall                        

jalascii_loop                 

li    $v0,1               
syscall                                           

ascii_loop:                            
li    $t4,10                  
addi $t2, $0,0               
move $t1,$a0                 


loop:  
lb     $t1,($t0)             <<<---- Error happens here
la $t3, newln
beq   $t1, $t3,ascii_end                                              
li    $t3,'0'                 
blt   $t1, $t3, ascii_error    
li    $t3,'9'                 
bgt   $t1, $t3, ascii_error
addi $t3, $t1, -48
mul   $t2, $t2, $t4
add   $t2, $t3, $t2
addi $t0, $t0, 1
b     loop

ascii_error:
li    $t2, -1

ascii_end:
move $a0, $t2
jr    $ra Thanks in Advance!

Explanation / Answer

.data
prompt: .asciiz " Enter a string of numbers up to 8 characters:"
newln: .asciiz " "
str: .space 10
.text
main:
li $v0, 4
la $a0, prompt
syscall                        

li $v0,8                   
li    $a1,10                  
la    $a0,str                 
syscall                        

jalascii_loop                 

li    $v0,1               
syscall                                           

ascii_loop:                            
li    $t4,10                  
addi $t2, $0,0               
move $t0,$a0              # t0 now has the address of the inputbuffer


loop:  
lb     $t1,($t0)                          #load the 1st character input intot1
la $t3,newln                              #load address of newln into t3
beq   $t1, $t3,ascii_end        #are they the same?   -comparing address and value doesn't make sense???                              
li    $t3,'0'                 
blt   $t1, $t3, ascii_error    
li    $t3,'9'                 
bgt   $t1, $t3, ascii_error
addi $t3, $t1, -48
mul   $t2, $t2, $t4
add   $t2, $t3, $t2
addi $t0, $t0, 1
b     loop

ascii_error:
li    $t2, -1

ascii_end:
move $a0, $t2
jr    $ra
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote