0

I searched through an array and find the maximum number to print, I have found the max and stored it in the register r4 but I don't know how to print it as a string with a new line.

    la $t0, sequence    #t0 is the address of array
    lw $t4, 0($t0)      #t4 is the updating max variable
    li $t1, 1       # initiate counter to 1, load into t1
    lw $t2, sequence_length
    loop: 
    beq $t1, $t2, exit 
    addi $t0, $t0, 4    #increment the address by 4 (the address of the next item in array)
    addi $t1, $t1, 1    #increment the counter by 1
    lw $t3, 0($t0)      #load the the next item into t3
    ble $t3, $t4, end_if    #if next item is larger than the current max in t4, 
    move $t4, $t3           #update t4 with t3
    end_if:
    j  loop
    exit:
    move $a0, $t4   
    li $v0, 1
    syscall
    jr $ra
  • 1
    Why do you mention "regex" in your title? Do you mean something like *formatting* into a string pattern, like `sprintf(buf, "%d\n", number)` in C? That's not a regular expression. BTW, the easy thing is to print a newline separately, after using the print_int system call. If you want to get a single string, you can convert int to string yourself into a buffer, like [How do I print an integer in Assembly Level Programming without printf from the c library?](https://stackoverflow.com/a/46301894) – Peter Cordes Oct 25 '22 at 15:08
  • Or like [How to iterate over the digits of a number in MIPS?](https://stackoverflow.com/q/61038368) – Peter Cordes Oct 25 '22 at 15:12
  • yeah I just want to convert a int to a string in mips and then print a new line separately in the end – David Huang Oct 25 '22 at 15:18
  • Basically a duplicate of [next line after printing an integer in MIPS](https://stackoverflow.com/q/42123888) but that was also just answered in comments. [MIPS Assignment with Poor Instruction](https://stackoverflow.com/q/73950666) includes the mention of breaking up a complex format string into separate print `syscall`s, but is also cluttered with answers to a bunch of other stuff. – Peter Cordes Oct 25 '22 at 15:24

0 Answers0