Hi. I need help to write one program in Assembly Mips.

<< read the characters typed by the user and store these characters a string. This string is later converted to an integer. If the user tries introducing non-valid characters (that is, other than the numerals 0 to 9) the program "complaining" and start all over.
What's is wrong?


text:          .asciiz "\nEnter a number : "
text2:       .asciiz "\nThe value entered was: "    
text3:       .asciiz "\nEntered an invalid character"
val:          .space 160

            .globl  main  

main:       li $v0, 4               
               la $a0, text    

main2:      li $v0, 12               
            sw    $v0, val 

if_1:    lb    $t2, val            
           blt    $t2, 48, if_2    

if_2:    bgt $t2, 57, imp2    
           b    main2    

if_3:    lb    $t2, val             
           bge    $t2, 48, if_4    

if_4:    ble    $t2, 57, imp1    

imp1:    li    $v0, 4          
            la    $a0, text2

           li     $v0, 11                
           lw     $a0, val

        b end      

imp2:    li    $v0, 4          
            la    $a0, text3

        b    main                

            li $v0, 10              

I won't read or even test your code.

This is a good start:
Have a look at an ASCII-table. The number 0...9 have a defined representation there. You need to subtract the this offset, then multiply it by 10^x and add it to your result.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.