Как сохранить входные значения файла в массив из буфера в MIPS - PullRequest
0 голосов
/ 08 марта 2020

Итак, я читаю файл с именем input.txt и помещаю целые числа в буфер размером 80 байт. Как поместить содержимое буфера в массив? Я думаю, что я должен использовать что-то, связанное со словом и байтом, но я не уверен, как это сделать.

.data
fileName:   .asciiz "input.txt"
fileWords:  .space  80      
array:      .space  20   # array

.text

main:
    #READ INTO A FILE

    li  $v0, 13                 # open_file with syscall code 13
        la  $a0, fileName       # get file name
        li  $a1, 0              # file flag = read (0)
        syscall
        move    $s0, $v0        # save the file descriptor. $s0 = file

    #read the file
    li  $v0, 14             # read_file syscall code = 14
    move    $a0, $s0        # file descriptor
    la  $a1, fileWords      # The buffer that holds the string of the WHOLE file
    la  $a2, 80             # hardcoded buffer length
    syscall

    # print whats in the file
    li  $v0, 4          # read_string syscall code = 4
    la  $a0, fileWords
    syscall

    #Close the file
        li  $v0, 16                 # close_file syscall code
        move    $a0,$s0             # file descriptor to close
        syscall

# exiting program
exit:   li $v0, 10
    syscall     #syscall to exit program

input.txt выглядит так:

4
21
22
34
41
12
21
52
65
91
42
80
7
17
53
38
12
23
32
...