Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need some help with this exercise, I'm a little confused about what all we are supposed to do and what the output is supposed to look like. I started my code but I'm stuck at this point because I'm not entirely sure what all we are supposed to do for this assignment so I'm not sure if I'm on the right track or if I need to start over. It's not a difficult assignment but the prompt is just sort of vague and unclear.

here is the prompt:
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. Note: there are eight words in the top row of 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 e 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:(0 is the sprit character)
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 0x0eeeeeee. . .
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.
Your program will involve a series of nested loops.

What I have tried:

ASM
.data

InArr: .word 0x0eeeeeee

.text

.globl main

main:

#

li $s2,0x0eeeeeee

li $s3,0

#

loop:

ror $s2,$s2,4 # $s2 = $s2 >>4

sw $s2,InArr # InArr(0) = $s2

#addi $s2,$s2,4

bne $s2,$s3,loop # until i==0

#

li $v0,10 # System(exit)

syscall
Posted
Updated 10-Nov-20 21:05pm
v2
Comments
[no name] 10-Nov-20 5:32am    
Only your "teacher" knows the true requirement if you're "confused". A little risky asking strangers to interpret an assignment when you don't know what's being asked.

1 solution

As mentioned in the requirements, you have to use nested loops.
Try, for instance
ASM
.data
InArr: .word 0x0eeeeeee 0xeeeeeeee 0xeeeeeeee 0xeeeeeeee 0xeeeeeeee 0xeeeeeeee 0xeeeeeeee 0xeeeeeeee 
	
.text
.globl main

main:

li $s4, 8 # outer loop index, say 'i'
li $s5, 0 # offset used to access memory

outer_loop:

	li $s3,7 # inner loop index, say 'j'

	li $s2,0x0eeeeeee
	sw $s2,InArr($s5) # InArr[i] = 0x0eeeeeee

	inner_loop:
		ror $s2,$s2,4 # $s2 = $s2 >> 4
		sw $s2,InArr($s5) # InArr[i] = $s2

		addi $s3,$s3,-1 # j = j -1
		bne $s3,$zero,inner_loop # until j==0

	li $s2, 0xeeeeeeee
	sw $s2,InArr($s5) # InArr[i] = 0xeeeeeeee
	addi $s5,$s5,4	# increment the offset in order to access next word in memory
	addi $s4,$s4,-1 # i = i - 1
	bne $s4,$zero, outer_loop

li $v0,10 # System(exit)

syscall
 
Share this answer
 
Comments
Richard MacCutchan 11-Nov-20 4:03am    
+5.Is there no end to your talents? :)
CPallini 11-Nov-20 4:51am    
Thank you very much, Richard. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900