1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Writing a basic function in MIPS

Discussion in 'Assembly Language Programming (ALP) Forum' started by bawse.c, Aug 4, 2012.

  1. bawse.c

    bawse.c New Member

    Joined:
    Aug 4, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi guys,

    I have wrote a function in MIPS which is supposed to copy some words from memory and saving it to another memory address using assembly.
    The source address, destination address and the number of words to copy are input arguments of the function.

    I have used $a0 to $a2 for arguments as follows:
    $a0 = The source address,
    $a1 = destination address
    $a2 = the number of words to copy are input arguments of the function.


    Code:
    # UNTITLED PROGRAM
    
    	.data	# Data declaration section
    	
    	.text
    	.globl main
    main:		# Sta$t1 of code section
    
    funct:
    	beq $a2,0,done
    	lw $t1,($a0)
    	sw $t1,($a1)
    	add $a0,$a0,4
    	add $a1,$a1,4
    	sub $a2,$a2,1
    	j funct
    	
    done:
    add $v0, $a1, $0  #nop
    jr  $ra     #return to the main program
    
        # END OF PROGRAM
    # END OF PROGRAM
    

    Now the problem I have is I get Exceptions when I run the code.
    Is a function supposed to have .main, .text, .data parts in the file?

    how can I write a main program which calls this function to copy few hundred words from
    memory address for example 0x50000 to 0x90000.

    Cheers guys, I have been stuck on this for a day now =(
     

Share This Page