GIDForums  

Go Back   GIDForums > Computer Programming Forums > Assembly Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Feb-2009, 11:28
PaulGarcha PaulGarcha is offline
New Member
 
Join Date: Feb 2009
Posts: 12
PaulGarcha is on a distinguished road

ASM program


Hey

Im currently trying to learn the asm language but im struggling to edit this program to make it do what i want.

Atm it just tells me the number of a chosen letter in the string given but i want it to count the number of more than 1 letters if it makes sense

Iv tried changing it but it gives me the wrong number.

Can anyone help please?

## t0 - holds each byte from string in turn
## t1 - index into array: k in str(k)
## t2 - count of occurences
## t3 - holds the character to search for
##
.text
.globl main
main: nop # initialise loop variables [no operation 'instruction']
li $t1,0 # $t1 will be the array index
li $t2,0 # $t2 will be the counter
lb $t3,char # $t3 holds the search-for character
#
loop:
lb $t0,str($t1) # fetch next character
# from location: str + ($t1) i.e. " str(k)"
# indexed addressing (= base + offset)
# (psuedo instruction; assembles as two actual instructions)

beqz $t0,strEnd # if it's a null, then exit loop
bne $t0,$t3,con # else not null; is it same as target char?
add $t2,$t2,1 # yes, so increment counter
con: add $t1,$t1,1 # and either way increment index: "k = k + 1"
j loop # then continue to work along string
#
strEnd: # string search all done so deliver output
la $a0,str # system call to print the string
li $v0,4
syscall

la $a0,txt1 # then print output message
syscall
la $a0,char # with target char in
syscall

la $a0,txt2 # then print output link message
syscall

move $a0,$t2 # system call to print [ = 'copy']
li $v0,1 # out the count worked out
syscall

la $a0,endl # system call to print
li $v0,4


la $a0,txt1
syscall
la $a0,char2
syscall

la $a0,txt2 # then print output link message
syscall

move $a0,$t2 # system call to print [ = 'copy']
li $v0,1 # out the count worked out
syscall

la $a0,endl # system call to print
li $v0,4 # out a newline and identity sign-off
syscall

li $v0,10 # (usual quit)
syscall # au revoir...
###
.data
str: .asciiz "abcde" #
char: .asciiz "a" #
char2: .asciiz "z" #

txt1: .asciiz "\n\n the number of "
txt2: .asciiz " in the above string is:: "
endl: .asciiz "\n Bye, please test again! \n" #

## end
  #2  
Old 17-Feb-2009, 00:43
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: ASM program


What assembler? What OS?
  #3  
Old 17-Feb-2009, 01:21
PaulGarcha PaulGarcha is offline
New Member
 
Join Date: Feb 2009
Posts: 12
PaulGarcha is on a distinguished road

Re: ASM program


PCSpim on XP/vista
  #4  
Old 17-Feb-2009, 09:55
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: ASM program


MIPs assembler!
Sorry I don't know anything about that and don't have time to learn it right now...
Maybe someone else would happen by and enlighten us both?
  #5  
Old 17-Feb-2009, 10:14
PaulGarcha PaulGarcha is offline
New Member
 
Join Date: Feb 2009
Posts: 12
PaulGarcha is on a distinguished road

Re: ASM program


oh ok Howard, thank you for looking though

Yes i hope someone can help me with my problem
  #6  
Old 18-Feb-2009, 01:06
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: ASM program


Alright , you talked me into it...
It is a quick install for windows and I am reading up on MIPs assembly with this:
chortle.ccsu.edu/AssemblyTutorial/TutorialContents.html
I just opened the chapter 9 sample program ... and LOOK AT ALL THOSE REGISTERS!!!
This should be interesting. Maybe I can catch up to you in a day or so...
I need to get familiar with the cpu and assembler syntax etc.
  #7  
Old 18-Feb-2009, 01:45
PaulGarcha PaulGarcha is offline
New Member
 
Join Date: Feb 2009
Posts: 12
PaulGarcha is on a distinguished road

Re: ASM program


oo interesting site youve found there..might take a look myself too!
haha yup this is terrible.

Ah thank you!
  #8  
Old 19-Feb-2009, 21:34
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: ASM program


Well it turns out that your program runs about how I think you wanted it to:
Code:
abcde the number of a in the above string is:: 1 the number of z in the above string is:: 1 Bye, please test again! ################# # if I change str to this: .data str: .asciiz "abcadea" #I get abcadea the number of a in the above string is:: 3 the number of z in the above string is:: 3 Bye, please test again!
Now the z report is not right of course,,, in fact you never actually check for char2 at all, it just uses the same register value as the count you got on char,,, but I guess you had left that hanging...

So what was it you were having trouble with? Above you had said:
Quote:
it just tells me the number of a chosen letter in the string given
but i want it to count the number of more than 1 letters if it makes sense
I think it does that.

I did have trouble getting the program to load in PCSpim at first.
The problem seemed to be with the commands like li.
Then I was scanning in the code samples at the chortle.ccsu.edu tutorials and found that they begin using those commands in chapter 22.
In the 'programs' part of that chapter they say this:
Quote:
Code:
For these programming exercises, use only those instructions that have been discussed so far in these notes: ... PseudoInstructions la lw nop syscall li move sw In the Settings menu of SPIM set Bare Machine OFF, Allow Pseudo Instructions ON, Load Trap File ON, Delayed Branches ON, Delayed Loads ON, Mapped IO ON, Quiet OFF.
Which got me going.
I don't have the delayed branches setting available in my PCSpim... which (according to the help info) is:
PCSpim Version 1.0
SPIM Version 6.2 of January 6, 1999 ....

But it runs. If I open the register, text, data, windows and situate them just so in the main window I get a pretty good view of things. It's easy to see your register values change. Pretty neat little program. The console window on the other hand kept disappearing although I could open it up (even after the program was finished) from the "Window" menu. So what , are you going to work on Nintendo games?
Last edited by Howard_L : 19-Feb-2009 at 22:26.
  #9  
Old 20-Feb-2009, 16:11
PaulGarcha PaulGarcha is offline
New Member
 
Join Date: Feb 2009
Posts: 12
PaulGarcha is on a distinguished road

Re: ASM program


Quote:
Originally Posted by Howard_L
Well it turns out that your program runs about how I think you wanted it to:
Code:
abcde the number of a in the above string is:: 1 the number of z in the above string is:: 1 Bye, please test again! ################# # if I change str to this: .data str: .asciiz "abcadea" #I get abcadea the number of a in the above string is:: 3 the number of z in the above string is:: 3 Bye, please test again!
Now the z report is not right of course,,, in fact you never actually check for char2 at all, it just uses the same register value as the count you got on char,,, but I guess you had left that hanging...

So what was it you were having trouble with? Above you had said:I think it does that.

Yes exactly the z report is not right and thats what im trying to get to work..im having trouble getting it to check char2 and iv been spending days on this which i cant get to run!!!

Do you know how to fix it so it checks char2 aswell and give the correct result at all?

Well im just trying to get to grips with similar programs like this and for example using asm for useful programs like converting things like metres into inches etc...maybe soon I can develop more advanced stuff.
  #10  
Old 21-Feb-2009, 01:28
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: ASM program


So you didn't write this did you... great.
There is already a test in place for char.
You would do the same thing for char2.
If you do not know how , you should go through the tutorial listed above and learn how.
It's all there.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Equation solver RazoR C Programming Language 3 18-May-2008 10:24
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 04:48
Help with a complex program lordfuoco C++ Forum 5 24-Jun-2006 07:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:52.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.