-
-
Save MhdSyrwan/2689757 to your computer and use it in GitHub Desktop.
bonian home work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.data | |
wmsg : .asciiz "welcome \nstudent : Mohmmad Eyad Arnabeh \nNum : 345 \n" | |
getmsg : .asciiz "Please Enter a statment : \n" | |
msg0 : .asciiz "your sentence is : " | |
msg1 : .asciiz "Please Enter a character :\n" | |
msg2 : .asciiz "your char is :\n" | |
msg3 : .asciiz "not found \n" | |
str : .space 256 | |
chr : .space 1 | |
.text | |
.globl main | |
main: | |
#printing the welcome message . | |
la $a0,wmsg | |
li $v0,4 | |
syscall | |
#ask the user to insert a statment . | |
la $a0,getmsg | |
li $v0,4 | |
syscall | |
#get user string | |
li $v0,8 | |
syscall | |
move $s0,$a0 | |
#print it | |
li $v0,4 | |
la $a0,msg0 | |
syscall | |
li $v0,4 | |
move $a0,$s0 | |
syscall | |
#ask the user to enter a char | |
la $a0,msg1 | |
li $v0,4 | |
syscall | |
#get user char | |
li $v0,8 | |
la $a0,chr | |
syscall | |
#print usr char | |
li $v0,4 | |
la $a0,msg2 | |
syscall | |
la $a0,chr | |
li $v0,4 | |
syscall | |
# search | |
add $t1,$zero,$zero #make $t1 zero | |
lb $s1,chr | |
search : | |
# t0 contain the currnet value | |
# t3 contain the currnet address | |
# t1 contain the index | |
add $t3,$t1,$s0 #go to the next index in array | |
lb $t0,0($t3) #loading the value of array[t1] | |
beq $t0,$zero,nfound #if not end of array | |
addi $t1,$t1,1 # t1+=1 | |
bne $t0,$s1,search # if array[t1] != chr go to search (not found) | |
beq $t0,$s1,found # if array[t1] == chr go to search (found) | |
found : | |
li $v0,4 | |
move $a0,$t3 | |
syscall | |
li $v0,10 | |
syscall | |
nfound : | |
la $a0,msg3 | |
li $v0,4 | |
syscall | |
li $v0,10 | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment