adding two numeric strings - MIPS ASSEMBLY
Question
I am working on a MIPS Assembly program. I am new at this, and am having some trouble.
How do you convert digits in a .asciiz string to there numeric counter parts.
EX: "1" -> 49
Solution
Assuming you use a simulator like http://sourceforge.net/projects/spimsimulator/:
.data
input: .asciiz "1234"
.text
main:
la $t0, input # load address of input
loop:
lb $a0, ($t0) # load one byte
beq $a0, $0, exit # exit if null-byte
li $v0, 1 # print integer system call
syscall
addi $t0, $t0, 1 # increment address
j loop
exit:
jr $ra
Output: 49505152
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow