Write a MIPS assembly program that when run in MARS at 25 instructions/second wi
ID: 3667360 • Letter: W
Question
Write a MIPS assembly program that when run in MARS at 25 instructions/second will display in the Memory segment a 4-byte "sprite" that moves from left to right across the top of the memory display.
Important: set the MARS slider bar to execute at a slower speed. Omitting this step will run at full speed and no output will be apparent.
For example, consider the portion of the assignment where the sprite moves from left to right. Assuming that you chose a "background" of the hex digit and a "sprite" of the hex digit 0, a "time lapse" series of snapshots of the Memory segment display would look like the data below:
Time 1: 0x0eeeeeee 0xeeeeeeee. . .
Time 2: 0xe0eeeeee 0xeeeeeeee. . .
Time 3: 0xee0eeeee 0xeeeeeeee. . .
Time 4: 0xeee0eeee 0xeeeeeeee. . .
Time 5: 0xeeee0eee 0xeeeeeeee. . .
Time 6: 0xeeeee0ee 0xeeeeeeee. . .
Time 7: 0xeeeeee0e 0xeeeeeeee. . .
Time 8: 0xeeeeeee0 0xeeeeeeee. . .
Time 9: 0xeeeeeeee 0x0eeeeeeee. . .
(0 is the sprite character)
You may choose the hex digits used for the "background" and the "sprite" - select two hex digits that have as much contrast as possible for best visibility. For instance, the digits e and c are poor choices because they look so similar.
The program will involve a series of nested loops. Write this program in stages - do not attempt to write the entire program top-down.
Explanation / Answer
*display an image at a given location any necessary orientation, and possibly animation
*store any data necessary to achieve this orientation as well as a way to correctly display the image
} Sprite;
where 'data' points to the image data, x and y are the location of the sprite, and h and w are the height and width so that you can print the image correctly and other things (like collision detection). in assembly you can allocate this as a 12 byte array on the stack and index them according to there size. i don't know MIPS but i will show you in x86
his is my code so far but it loop is infinity
syscall
main:
load the immediate value 0x0eeeeeee into register $s2
load the immediate value 0 into register $s3
loop:
rotate the contents of $s2 right four bits
save the value in InArr
branch back to loop: if the register $s2 is not equal to $s3
The infinite loop is caused by the fact that $s3 contains a value of 0 and you make no change to this.
What you should have (again written in English) is this
main:
load the immediate value 0x0eeeeeee into register $s2
load the immediate value 7 into register $s3
loop:
rotate the contents of $s2 right four bits
save the value in InArr
subtract 1 from $s3
branch back to loop: if the register $s2 is not equal to $s3
Dry running this gives you the following results
$s2 $s3
1 0x0eeeeeee 7
2 0xe0eeeeee 6
3 0xee0eeeee 5
4 0xeee0eeee 4
5 0xeeee0eee 3
6 0xeeeee0ee 2
7 0xeeeeee0e 1
8 0xeeeeeee0 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.