-
-
Save eyadof/2689404 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" | |
msg4 : .asciiz "\nFound!\n" | |
msg5 : .asciiz "\nFound time : \n" | |
msg6 : .asciiz "\nChoose an option :\n | |
1- enter a new char\n | |
2- Is Found ?\n | |
3- How many time Found\n | |
4- What is its index\n | |
5- exit\n" | |
msg7: .asciiz "\nFound in :\n" | |
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 | |
getchr: | |
#ask the user to enter a char | |
la $a0,msg1 | |
li $v0,4 | |
syscall | |
#get user char | |
li $v0,8 | |
la $a0,chr | |
syscall | |
lb $s1,chr | |
#print usr char | |
# li $v0,4 | |
# la $a0,msg2 | |
# syscall | |
#move $a0,$s1 | |
#li $v0,4 | |
#syscall | |
choose : | |
#print choose message | |
li $v0,4 | |
la $a0,msg6 | |
syscall | |
#get usr option | |
li $v0,5 | |
syscall | |
move $s4,$v0 | |
jal zeros | |
beq $s4,1,getchr | |
beq $s4,2,isf | |
beq $s4,3,hm | |
beq $s4,4,allf | |
beq $s4,5,exit | |
j exit | |
# t0 contain the currnet value | |
# t1 contain the index | |
# t2 contain the currnet address | |
zeros: | |
add $t0,$zero,$zero | |
add $t1,$zero,$zero | |
add $t2,$zero,$zero | |
jr $ra | |
#is found | |
isf : | |
add $t2,$t1,$s0 #go to the next index in array | |
lb $t0,0($t2) #loading the value of array[i] | |
beq $t0,$zero,nfound #if end of array | |
addi $t1,$t1,1 #t1+=1 | |
bne $t0,$s1,isf #if array[i] != chr go to search (not found) | |
beq $t0,$s1,found #if array[i] == chr go to search (found) | |
found : | |
li $v0,4 | |
la $a0,msg4 | |
syscall | |
j choose | |
nfound: | |
li $v0,4 | |
la $a0,msg3 | |
syscall | |
j choose | |
#how many found | |
hm: | |
add $t2,$t1,$s0 #go to the next index in array | |
lb $t0,0($t2) #loading the value of array | |
beq $t0,$zero,print #if end of array | |
addi $t1,$t1,1 #t1+=1 | |
bne $t0,$s1,hm #if array[i] != chr go to search (not found) | |
beq $t0,$s1,found1 | |
found1: | |
add $s2,$s2,1 | |
j hm | |
print: | |
li $v0,4 | |
la $a0,msg5 | |
syscall | |
li $v0,1 | |
move $a0,$s2 | |
syscall | |
j choose | |
#its indexes | |
allf: | |
add $t2,$t1,$s0 #go to the next index in array | |
lb $t0,0($t2) #loading the value of array | |
beq $t0,$zero,choose #if end of array | |
addi $t1,$t1,1 #t1+=1 | |
bne $t0,$s1,allf #if array[i] != chr go to search (not found) | |
beq $t0,$s1,found2 #if array[i] == chr go to search (found) | |
found2: | |
li $v0,4 | |
la $a0,msg7 | |
syscall | |
li $v0,1 | |
move $a0,$t1 | |
syscall | |
j allf | |
exit: | |
li $v0,10 | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment