Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 3rd, 2005, 6:14 AM   #1
Ansem
Newbie
 
Join Date: May 2005
Posts: 1
Rep Power: 0 Ansem is on a distinguished road
Help!!

Hi, can someone with mips knowledge look at my code please, I don't know whats wrong with my code, I'm trying to create a program that accepts 2 strings entered by the user, and compares the ascii values of the characters in the 2 strings and checks which is the lesser one. Also how can I make my code so that if a user enteres more than N characters, how can I take only the first N characters and store it?

Here's the my code:


.text
.globl main

.data
string1: .space 80
string2: .space 80
prompt1: .asciiz "Enter 1st string: "
prompt2: .asciiz "Enter 2nd string: "
firststr: .asciiz "The string that is first: "
maxlength1: .word 30
maxlength2: .word 30
line: .byte "\n"


main: li $v0, 4
la $a0, prompt1
syscall

li $v0, 8
la $a0, string1
lw $a1, maxlength1
syscall

li $v0, 4
la $a0, prompt2
syscall

li $v0, 8
la $a0, string2
lw $a1, maxlength2
syscall

li $t0, 0
loop: lb $t1, string1($t0)
lb $t2, string2($t0)
beq $t1, line, printstr2
beq $t2, line, printstr1
beq $t1, $t2, search
bne $t1, $t2, compare

search: addi $t0, $t0, 1, loop

compare: blt $t1, $t2, printstr1
blt $t2, $t1, printstr2

printstr1: li $v0, 4
la $a0, string1
syscall

li $v0, 5
syscall # wait for Enter

li $v0, 10
syscall # end of program

printstr2: li $v0, 4
la $a0, string2
syscall

li $v0, 5
syscall # wait for Enter

li $v0, 10
syscall # end of program
Ansem is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC