Search code examples
pythonmipsmips32qtspimspim

Use Python to simulate sending user input to SPIM


I am trying to write a program in python that can run SPIM and send user input to the SPIM subroutine.

I tried using

mips=subprocess("spim",stdin=PIPE, stdout=output.txt, stderr=output.txt)
mips.stdin.write(b"10")
mips.stdin.write(b"15")
mips.stdin.write(b"15")

but it completely skipped waiting for user input.

Here is what the MIPS subroutine is supposed to do

enter first value: 10
enter second value: 15
enter third value: 15
your Sum is: 40

This works correctly when I call it from a terminal and enter values myself, but if I run it as a subprocess it prints the following:

enter first value: 
enter second value: 
enter third value: 
your Sum is: 101515

The 101515 appears to be printing after SPIM execution completes.

What can I do to programmatically enter values into the SPIM virtual machine?

If it helps SPIM is pts not tty.


Solution

  • To programmatically send input to spin you place the values in a text file and pipe in

    Each value on a new line

    So if the mips prompts were

    "Enter string"

    "Enter digit"

    The text file must look as follows with each separate input on its own line

    My string input

    127

    And in terminal you type the following

    spim asm-name.s < input-file.txt