MIPS Assembly Language
* Write a simple program to count the number of non overlapping repetitions of a character pattern in a character string. For example " the pattern "aa" appears twice in the in the string "aabbaaa". Provide a user interface to read the character pattern and the string.
Function in Python
searches for occurence of pattern 11 in '1011101111'
def function(string, str_to_search_for):
count = 0
for x in xrange(len(string) - len(str_to_search_for) + 1):
if string[x:x+len(str_to_search_for)] == str_to_search_for:
count += 1
return count
function('1011101111','11')
returns 5
pROGRAM IN
x86
COUNTSTR CSECT
USING COUNTSTR,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
STM R14,R12,12(R13) prolog
ST R13,4(R15) "
ST R15,8(R13) "
LR R13,R15 "
MVC SOMW_VAR,=CL32'TREE THREE THROUGH'
MVC LENH,=F'17' lh=17
MVC SOM_SHOP,=CL8'REE' SOM_SHOP='REE'
MVC LENN,=F'2' ln=2
BAL R14,SHOW call show
MVC SOMW_VAR,=CL32'SUNSUNSHINE '
MVC LENH,=F'11' lh=11
MVC SOM_SHOP,=CL8'SUN' SOM_SHOP='SUN'
MVC LENN,=F'4' ln=4
BAL R14,SHOW call show
L R13,4(0,R13) epilog
LM R14,R12,12(R13) "
XR R15,R15 "
BR R14 exit
HAYSTACK DS CL32 SOMW_VAR
SOM_SHOP DS CL8 SOM_SHOP
LENH DS F length(SOMW_VAR)
LENN DS F length(SOM_SHOP)
*------- ----
show---------------------------------------------------
SHOW ST R14,SAVESHOW save return address
BAL R14,COUNT count(SOMW_VAR,SOM_SHOP)
LR R11,R0 ic=count(SOMW_VAR,SOM_SHOP)
MVC PG(20),SOMW_VAR output SOMW_VAR
MVC PG+20(5),SOM_SHOP output SOM_SHOP
XDECO R11,PG+25 output ic
XPRNT PG,80 print buffer
L R14,SAVESHOW restore return address
BR R14 return to caller
SAVESHOW DS A return address of caller
PG DC CL80' ' buffer
*------- ----
count--------------------------------------------------
COUNT ST R14,SAVECOUN save return address
SR R7,R7 n=0
LA R6,1 istart=1
L R10,LENH lh
S R10,LENN ln
LA R10,1(R10) lh-ln+1
LOOPI CR R6,R10 do istart=1 to lh-ln+1
BH ELOOPI
LA R8,SOM_SHOP @SOM_SHOP
L R9,LENN ln
LA R4,SOMW_VAR-1 @SOMW_VAR[0]
AR R4,R6 +istart
LR R5,R9 ln
CLCL R4,R8 if substr(SOMW_VAR,istart,ln)=SOM_SHOP
BNE NOTEQ
LA R7,1(R7) n=n+1
A R6,LENN istart=istart+ln
NOTEQ LA R6,1(R6) istart=istart+1
B LOOPI
ELOOPI LR R0,R7 return(n)
L R14,SAVECOUN restore return address
BR R14 return to caller
SAVECOUN DS A return address of caller
* ----
-------------------------------------------------------
YREGS
END COUNTSTR
Output:
TREE THREE THROUGH REE 2
SUNSUNSHINE SUN 2
MIPS Assembly Language * Write a simple program to count the number of non overlapping repetitions...
2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...
Write a simple and short MIPS assembly language program that asks the user for 6 numbers, merge-sorts them, and then prints them out in ascending order comment each and every programme .(USING WINDOWS QtSpim) Note : This question is not giving desired solution may you please try it in a simple manner for six number inputed by the user.
MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and print a simple checksum for each string. Make your string long enough to hold 50 characters. Don't forget to leave space for the null byte. Our checksum algorithm will produce a value which you can print with the syscall for printing a character. Stop reading strings when the user enters ".". The syscall to read a string (sycall code 8) adds a newline to...
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write it out to the console.
Linear Search: Write a MIPS assembly language program that can search for a number that entered by user in an array with 20 integer numbers and prints the index of the number in the array if it is found and -1 if not found
In this part of the assignment, you will write MIPS assembly code to replace characters in a string. This program asks the user for a string named string and two characters orig and new. It then replaces each instance of the character orig found in string with the character new. It outputs the resulting string and the number of substitutions that were made. For example, if string were "wow", orig were 'w', and new were 'b', the program would output...
Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the user to enter a string which is subsequently displayed in uppercase. It is important to first ensure that string to be converted is in the a-z range. The program does not recognize any space, symbols or any kind of punctuation marks. Any time the user enters any of this character the program is going to repeatedly ask for the...
Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence. Your program should prompt for an integer input n from the user. The program should call a recursive function to compute the nth fibonacci number. Your program must follow programming convention. You should submit program and screenshot of output in a single word/pdf file. You should use following recursive definition of fibonacci function: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) +fib(n-2)
Programming: Write a SPIM assembly language program num-vowel.s based on the hardware implementation method in the lab notes and the above practice. The program will do the following: Prompt the user to enter a string. The program will call the procedure vowelp to check if a character entered in the string is a vowel or not. Count how many vowels and how many non-vowels are in the string. Print out the calculated results with appropriate message. Hint: A loop is...
Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the user to enter a string which is subsequently displayed in uppercase. It is important to first ensure that string to be converted is in the a-z range. The program does not recognize any space, symbols or any kind of punctuation marks. Any time the user enters any of this character the program is going to repeatedly ask for...