Я пытаюсь написать код MIPS, который открывает файл, считывает его и печатает одну строку, когда пользователь вводит ввод (новую строку) с клавиатуры до конца текстового документа. Но каким-то образом программа пропускает пользовательские входы и не ждет ввода.Ошибка ввода MIPS с клавиатуры с ошибкой
Код:
.data
buffer: .space 4
fin: .asciiz "input.txt" # filename for input
myName: .asciiz "\nTheUserName"
.text
openfile:
li $v0, 13 # system call for open file
la $a0, fin # board file name
li $a1, 0 # Flag for reading
li $a2, 0
syscall
add $s7, $v0, $0 # save the file descriptor
read:
#read from file code goes here
li $v0, 14 # system call for read from file
move $a0, $s7 # file descriptor
la $a1, buffer # address of buffer to which to read
li $a2, 1 # hardcoded buffer length
syscall
beq $v0,$0,exit #exit if EOF is seen
print:
#print file code goes here
la $a0, buffer # address of string to be printed
li $v0, 4 # print string
syscall
beq $a0,0x0A, input #check whether the character read from the file is ‘\n’ (new line) or not
b read
input:
#get input code goes here
li $v0, 12
syscall
beq $v0, 0x0A, read #check whether the character read from the keyboard is ‘\n’ (new line) or not
b input
exit:
# Close the file code goes here
li $v0, 16 # system call for close file
move $a0, $s7 # file descriptor to close
syscall # close file
name:
# Print your name and surname on the screen as a string as the last line
li $v0, 4
la $a0, myName
syscall
входного файла:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tristique dui at ornare pretium.
Phasellus ac vehicula libero. Fusce scelerisque dolor ipsum, vitae suscipit sapien dictum quis.
Praesent sed libero tellus. In vitae laoreet massa.
Duis vehicula fringilla orci, et iaculis nulla malesuada in.
Nam at cursus nisi. Duis convallis magna quis dolor aliquam ullamcorper.
Nunc sollicitudin a leo in placerat. Cras id pretium ligula, sed facilisis massa.
Curabitur semper ultricies nulla non lacinia. Nunc a fermentum ex, nec egestas ligula.
Quisque varius libero sed rhoncus venenatis. Cras pulvinar ultrices dignissim.
Thx для ответа и действительно ясное повествования. Но я хотел напечатать строку всякий раз, когда пользовательские входы вводят (новую строку) с клавиатуры. Мой плохой там мой вопрос не был действительно ясным. – fcanozkan
Думаю, я это понял. Я проанализировал вашу программу, а не текст вопроса. Было очевидно, что в строке _single_ я игнорировал «каждый» в тексте вопроса. Программа предложит пользователю ввести клавиатуру [до новой строки]. Затем он печатает строку _single_ из файла. Затем он запрашивает у пользователя новую строку. И так далее ... Я считаю, что это то, что вы хотели. Я думаю, что если вы на самом деле попытаетесь запустить программу, вы увидите, что она работает. –
Я опробовал ваше решение, прежде всего, пауза для ввода пользователем до первого раза работает хорошо. Но когда я ввожу программу ввода, распечатываются все строки. Не только одна строка. Thx для всех ваших усилий. Очень благодарю вас. – fcanozkan