Find the answer to your Linux question:
Results 1 to 2 of 2
Hello I am working on a small Mips program for my Comp Organization class and I am having an impossible time with advancing an array which I wish to print ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Banned
    Join Date
    Sep 2008
    Posts
    1

    Mips Array/Loop assistance


    Hello

    I am working on a small Mips program for my Comp Organization class and I am having an impossible time with advancing an array which I wish to print integers from. I have a loop that terminates at the proper interval however I cannot seem to get the next value in the array.

    I have tried bit shifts which leads to to either print the first value followed by a constant set of the second value or leads to memory address faults. I have tried adding 4 to the address in an attempt to move to the next 4 bytes. I am at a loss. I have reviewed the text, the class slides, and days of google searches. Can someone help me see a solution? Code attached.


    Code:
    .data
    
    numWords:
    	.word  12
    
    bytes:	.word   4
    
    values:	.word  17
    	.word -50
    	.word   3
    	.word -23
    	.word -60
    	.word  97
    	.word  20
    	.word -82
    	.word  53
    	.word  30
    	.word -17
    	.word 142
    wordString:
    	.asciiz "The 32-bit integers are\n"
    
    newline:.asciiz "\n"
    
    # Your code goes below this line
    .text
    main:
    	li	$v0, 4		# Load print sys command
    	la	$a0, wordString	# Load wordString to $a0
    	syscall
    	
    	la	$s2, values	# Load address of array
    
    	lw	$a0, 0($s2)	# Load address to arg
    	la	$t2, numWords	# Load number of words
    	lw 	$s1, 0($t2)	# Set loop upper bound to numWords
    	li	$s0, 0		# Set loop lower bound to 0
    	
    	
    WordLoop:
    	li	$v0,1 		# Load Print int sys call
    	
    	add	$s2, $s2, 4	# Advance memory to next four bytes
    	syscall
    
    	addi	$s0, $s0, 1	# Add 1 to loop indexer
    	bne	$s0, $s1, WordLoop	# If loop equals less than word count continue
    	j 	Exit		# Else exit
    
    Exit:
    	jr $ra			# Jump to return addr ($ra)

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Sorry, but homework questions are not allowed as per The Forum Rules.

    I will say that your problem is indeed in your traversing of the array.

    Good luck. If you have any specific questions about concepts, please feel free to ask them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •