Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   Writing a basic function in MIPS (http://www.go4expert.com/forums/writing-basic-function-mips-t28830/)

bawse.c 4Aug2012 09:14

Writing a basic function in MIPS
 
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 =(


All times are GMT +5.5. The time now is 05:54.