User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,760 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 803 | Replies: 2
Reply
Join Date: Dec 2007
Posts: 2
Reputation: Destini is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Destini Destini is offline Offline
Newbie Poster

strcat in MIPS

  #1  
Dec 3rd, 2007
edit: sorry strcopy not strcat

Hi I'm new to MIPS and just need some basic clarification on what is actually going on here. I'm trying to make a copy of string1 into string2 by reading through the string copying each bit seperately, and stopping at the 0 terminator:

	.data
string1:	.asciiz "Hello"
string2:	.space 128
	.text
	

main:	la	$a2, string1
	la	$a3, string2
	jal 	strcopy
moo:	la	$a0, $a3
	li	$v0, 4
	syscall
	li	$v0, 10
	syscall



strcopy:	move	$v0, $a2
loop:	lbu	$t0,0($a2)
	sb	$t0,0,($a3)
	addi	$a2,$a2,1
	bgtz	$t0,loop
	jal	moo


The only problem is im getting really mixed up with all my $a-something.
I've looked at other examples of strcat but I can never actually figure out which line actually overwrites the one string. I think it's cause I don't fully understand the principle of $a0.

Could someone please adjust the above so that string1 will be copied into string2?

Thanks for any help or information you can give.
Last edited by Destini : Dec 3rd, 2007 at 7:49 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: strcat in MIPS

  #2  
Dec 3rd, 2007
Are you taking a course or just doing this on your own?

You need to watch a few things. First, though, your strcopy should look like this:
  1. strcopy: lbu $t0,($a2) # load the char at $a2
  2. sb $t0,($a3) # save the char at $a3
  3. addi $a2,$a2,1 # next $a2
  4. addi $a3,$a3,1 # next $a3
  5. bgtz $t0,strcopy # do it all again?
  6. jr $ra # return to caller
If you don't already have a good MIPS reference you need to get one. It makes all the difference.
This one at WikiPedia is short, but good.

1. Every jal should be to a subroutine that returns with jr $ra. Using jal means that you don't need moo: at all.

2. The link I gave you gives the general meaning of all the register names.

3. The syscall to print the string requires $a0 to have the address of the string to print and $v0 to have the value 2.

The syscall to terminate the program only requires $v0 to have the value 10.

Hope this helps.
Reply With Quote  
Join Date: Dec 2007
Posts: 2
Reputation: Destini is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Destini Destini is offline Offline
Newbie Poster

Re: strcat in MIPS

  #3  
Dec 3rd, 2007
that's really helpful, thankyou.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Assembly Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Assembly Forum

All times are GMT -4. The time now is 9:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC