0

I'm new to assembly and I'm trying to output the division and modulus of two numbers, and so far I was successful. I can print the two numbers with space separating them be making a space character, but when I try to print a new line character '\n', I get syntax error... Here is a snippet:

        .text
main:   #-------------------
        addi    $t0, $0, 60
        addi    $t1, $0, 7
        #-------------------
        div     $t0, $t1        #Divide the two numbers
        mflo    $a0             #store division
        addi    $v0, $0, 1      #Call service 1 to print integers
        syscall                 #print
        #-------------------
        addi    $v0, $0, 11     #Call service 11 to print characters
        add     $a0, $0, '\n'   #print new line
        syscall                 #print
        #-------------------
        div     $t0, $t1        #Divide the two numbers
        mfhi    $a0             #Store modulus
        addi    $v0, $0, 1      #Call service 1 to print integers
        syscall                 #print
Struggling
  • 51
  • 2
  • 11
  • `\n` is an immediate, you should use `addi` or `li`. Furthermore, maybe your assembler doesn't understand `\n` itself, in which case use the numeric value (`10`) directly. – Jester May 28 '16 at 00:21
  • Much appreciated. Where did you learn that \n = 10? And I'm using PCSpim so that might be the reason. Anyways, your solution works. Thank you again. @Jester – Struggling May 28 '16 at 00:25
  • In any [ascii](http://asciitable.com) [table](http://man7.org/linux/man-pages/man7/ascii.7.html) – Jester May 28 '16 at 00:26
  • @Jester `mars` will understand `'\n'` in just about any context. `spim` does in most. But, (e.g.) if we were rolling our own `atoi`, doing `addi $t1,$t1,-'0'` does _not_ work in `spim` but _does_ in `mars`. Go figure ... – Craig Estey May 28 '16 at 01:50

0 Answers0