Jump to content

MIPS Code help needed.

- - - - -

  • Please log in to reply
1 reply to this topic

#1
hrp2010

hrp2010

    Newbie

  • Members
  • Pip
  • 2 posts
I am new to MIPS assembly level programming. After refering few mips, i wrote my first code so i need help of expert who can verify whether code i wrote is correct or not and if not, what needs to be done to correct it and rational behind that. thank you in advance.


Prob: read a string (<=4 bytes), copy string to a word in memory, display the word as an integer

########################## Data segment #######################
.data

str: .space 4  # array of 4 bytes


########################### Code Segment ######################

.text
.global main

main:    # main program entry

la $a0, str  # $a0 = address of str 
li #a1, 4    # $a1 = max string length
li $vo, 8    # $ read string 
move $s0, $a0 # copy to $so
syscall

la $a0, str
li $v0,4  # read integer 4 ( 4 is the print_string syscall ) print string str 
syscall
move $a0, $s0  # copy string to $a0 and print
la $v0,1
syscall 

     
li $vo, 10 # exit program 
syscall

Edited by dargueta, 02 February 2012 - 11:16 AM.


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Can't you just use SPIM or XSPIM and check it out? It'll let you step through all the functions, examine memory and variables, etc. or you can just run it straight through.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users