title: MIPS Assembly program that can read 2 integers from a text file and multiply them
body: <p>I am working on a MIPS Assembly program in MARS that simply needs to be able to request a file name from the user, then multiply 2 integers within that text file. The integers must be on separate lines. The program must also output the results as "num1 * num2 = result". Here's what I have so far:</p>
  
  <pre><code> .data
  file:      .asciiz     "" #filename for input
  prompt:     .asciiz     "Please enter the file name.\n"
  buffer:     .asciiz      ""
  newline: .asciiz "\n"
  multi: .asciiz "*"
  equals: .asciiz "="
  
  
  .text
  li $v0, 4
  la $a0, prompt      #display prompt
  syscall
  
  li $v0, 8       #save entered string
  la $a0, file    
  li $a1, 200
  syscall
  
  li   $v0, 13       # system call for open file
  la   $a0, file      # input file name
  li   $a1, 0        # flag for reading
  li   $a2, 0        # mode is ignored
  syscall            # open a file 
  move $s0, $v0      # save the file descriptor
  
  # reading from file just opened
  
  li   $v0, 14       # system call for reading from file
  move $a0, $s0      # file descriptor 
  la   $a1, buffer   # address of buffer from which to read
  li   $a2,  1000  # hardcoded buffer length
  syscall            # read from file
  move $s1, $v0           #$t0 = total number of bytes
  
  #where I am stuck:
  #
  #
  #
  #
  
  
  
  
  jal output
  jal closeFile
  li $v0, 10
  syscall
  
  
  output:#needs to have the form: integer1 * integer2 = result
  li $v0, 1
  move $a0, $t5
  syscall
  
  li $v0, 4
  la $a0, multi
  syscall
  
  li $v0, 1
  move $a0, $t6
  syscall
  
  li $v0, 4
  la $a0, equals
  syscall
  
  li $v0, 1
  move $a0, $s7
  syscall
  jr $ra
  
  closeFile:
      # Close the file 
      li   $v0, 16       # system call for close file
      move $a0, $s0      # file descriptor to close
      syscall            # close file
  jr $ra
  </code></pre>
  
  <p>Requesting the filename from the user and opening/reading the file are no problem. But I can't figure out how to store the 2 integers so I can perform the multiplication and save the result. I'm assuming a loop that goes character by character and stores in an array but I'm not sure how to do that in MIPS. I also looked into an atoi procedure and thought it may be useful? Thanks for any help!</p>