MIPS ASSEMBLY : 1) Code in MIPS a function that allows to store the text entered
ID: 3700095 • Letter: M
Question
MIPS ASSEMBLY :
1) Code in MIPS a function that allows to store the text entered by the user in a 300-byte buffer. The function must return the actual size of the entered text in number of bytes. The text could contain lines, that is to say that the symbol ' n' could be present. The end of reading is defined by both consecutive ' n' ' n' symbols. *Also if the user inputs more then 300 bytes is their a way to detect it and print a error and end the programme*
2) Code in MIPS a function that helps identify if the character passed in parameter represents a Latin alphabet letter (26 letters of alphabet English) lowercase or uppercase. Should look like this: bool letter(char l)
Explanation / Answer
Question 2(lowercaseletters)
--------------------------------------------------------------------------------------------------------
Code:-
#Variable declaration
.data
input: .asciiz "Enter a alphabet:"
outputTrue: .asciiz " true"
outputFalse: .asciiz " false"
#main program
.text
#input prompt to enter data
la $a0,input
li $v0,4
syscall
#read input character
la $a0,input
li $v0,12
syscall
#move value to $a0
move $a0,$v0
#call function
jal letter
#move return result to s0
move $s0,$v0
#if return result 1 then true else go to nolatin
beq $s0,0,notlatin
#print true
la $a0,outputTrue
li $v0,4
syscall
#end the program
li $v0,10
syscall
#return 0 then print false
notlatin:
la $a0,outputFalse
li $v0,4
syscall
li $v0,10
syscall
#function definition
letter:
#lattin small letter are in ascii 32,97-105,107-116,118,121 0r 122
beq $a0,32,exit #compare each values with the user enred value
bge $a0,97,next
loop: bge $a0,107,next1
loop1: beq $a0,118,exit
beq $a0,121,exit
beq $a0,122,exit
#if not match return0
li $v0,0
jr $ra
next: ble $a0,105,exit
j loop
next1:ble $a0,116,exit
j loop1
#if not match return1
exit:
li $v0,1
jr $ra
------------------------------------------------------------------------------------------------------------------------------------
Question1
ScreenShot
code
#variable declaration
.data
buffer: .space 300
output: .asciiz "You Wrote:"
count: .ascii "Count of the text:"
#main program
.text
li $s0,0
li $v0,8 #take in input
la $a0, buffer #load byte space into address
li $a1, 300# allot the byte space for string if user enter more than 300 then exit
move $t0,$a0 #save string to t0
syscall
loop: lb $a0,0($t0) # primary address = t0 address (load pointer)
beqz $a0,exit
addi $s0,$s0,1
addi $t0,$t0,1
j loop
exit: la $a0,output #load and print "you wrote" string
li $v0,4
syscall
la $a0, buffer #reload byte space to primary address
move $t0,$a0
li $v0,4 # print string
syscall
la $a0,count #load and print the count
li $v0,4
syscall
move $a0,$s0#count of the characters or bytes
li $v0,1 # print byte number
syscall
li $v0,10 #end program
syscall
--------------------------------------------------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.