![]() |
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 |
| All times are GMT -5. The time now is 6:02 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC