1

I wrote this simple program just to try and check if slt or any other comparing instruction can tell me if the value inside the string and the integers it represent are bigger then the other one. It's not working and I don't know why.

  1. Is this comparison legal or should I turn the strings to real integers?
  2. Why doesn't it work? from my understanding the address of each string+offset should move the correct value too $t0 and $t1.
  3. How do I turn this strings to the integers they represent?
  4. what can I do in case their are more then 4 integers inside the string? how can I turn "123456" to be the integer in decimal inside the memory? (hex is good too of course)

here's the code: (exited badly after doing the second lw)

 .data 

    str1: .asciiz "1234"
    str2: .asciiz "1222"

.text
.globl main
 main: 

     lw $t0, str1($t0)
     lw $t1, str2($t1)
     slt $t2, $t0, $t1

li $v0, 10
syscall
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Strings consist of characters that typically are one bytes each. So treating the contents as words makes little sense. Also, see http://stackoverflow.com/questions/15940331/convert-string-of-ascii-digits-to-int-in-mips-assembler – Michael Oct 28 '15 at 07:24
  • It should work, but what's in t0 and t1 before lw? Where do you actually load from? If the address is misaligned it may crash - depending if the ARM can handle non-aligned data and if that property is configured on. – turboscrew Oct 28 '15 at 23:15
  • You're essentially asking how to write `atoi` http://research.microsoft.com/en-us/um/redmond/projects/invisible/src/crt/atoi.c.htm – Konrad Lindenbach Oct 29 '15 at 06:36

0 Answers0