Thread: Help!!
View Single Post
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