Assignment 2: MIPS virus
Due: 5:00pm, Tue 5 Feb. Value: 30 pts. Submit to Moodle.
This assignment uses MARS for simulating the MIPS architecture.
On the laboratory computers, you can start MARS
using the “mars
” command from the terminal.
For other computers, you can download it here
[Link];
this version differs from the one available on the official MARS Web site,
as the official version has a shortcoming preventing this
assignment from being feasible.
Your assignment is to write a MIPS assembly language program that duplicates and invokes itself — i.e., a virus. That is, while the program you write is loaded into memory starting at 0x400000; but as executed, it should copy the program found starting from 0x400000 (i.e., itself) into memory starting from 0x400100. It should then jump to 0x400100 to execute the copied program, which would then duplicate the code starting from 0x400100 into memory into 0x400200, which when invoked will duplicate itself into 0x400300, and so on.
As your program executes, it should display the number 1 when it executes the initially loaded version; it should display 2 when it executes the first copy; it should display 3 in executing the second copy; and so on.
Your program should work regardless of initial register values, even when jumping into the duplicated version of the program. That is, you must not use registers to receive information from a previous copy of the program.
Your program will need to place the program's initial address into a register. Unfortunately, this initial address will be different as it executes duplicated versions of the program. Therefore, as you copy instructions, some instructions will not be exact copies but rather changed slightly to account for the different address range.
You don't need to worry about what happens when the program makes so many copies as to go outside the allowed memory region. It just needs to work for, say, the first 20 copies.