Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assembly code Create a program that performs the following operations: 1. Prompt

ID: 3605992 • Letter: A

Question

Assembly code

Create a program that performs the following operations:
1. Prompt for and accept a string of up to 85 characters from the user.
The memory buffer for this string is created by:
buffer: .space 80 # create space for string input
The syscall to place input into the buffer looks like:
li $v0, 8 # code for syscall read_string
la $a0, buffer # tell syscall where the buffer is
li $a1, 85 # tell syscall how big the buffer is
syscall
2. Determine how long the string which was entered. Every string that is entered will have a newline
character (0x0a) appended to its end and then lastly the null character (0x00). Do not count either of
these characters when reporting the string length (stop scanning when you reach the newline character).
You can use the la instruction to place the address of the buffer in a register. The lb (load byte is used
just like lw) instruction can be used to read a byte from memory into a register (it will be placed on the
right end of the register and the upper part of the register will be zeroed out. Use code similar to this to
count the characters in the string.
la $t0, buffer # place address of buffer in $t0
myloop: lb $t1, 0($t0) # read byte located at address in $t0
.
. # logic including code to leave loop
.
addi $t0, $t0, 1 # increment address in $t0
j myloop # jump to myloop
loopDone:
3. Determine how many uppercase letters are in the string.
4. Determine how many lowercase letters are in the string.
5. Determine how many digits are in the string.
6. Determine how many spaces are in the string.
7. Subtract the sum of 3-6 from the string length to determine how many other characters are in the string.
8. Your output should look approximately like this (user input is show in bold here):
Enter a string: abc234##
Your string contains: 16 characters.
There are 3 upper case characters.
There are 4 lower case characters.
There are 4 digits.
There are 0 spaces.
There are 5 other characters.
9. use a separate loop for each of the task from 3 to 6 rather than
attempting to do all in a single loop

Explanation / Answer

.data
prompt .ascizz "enter the string "
userInput: .space 100
error_msg: .ascizz "Empty string....error.Please try again "
character_msg: .ascizz " the number of characters is :"
space_msg: .ascizz " the number of spaces is :"
sentence_msg: .ascizz " the number of sentences is :"
uppercase_msg: .ascizz " the number of uppercase alphabets is :"
lowercase_msg: .ascizz " the number of lowercase alphabets is :"
word_msg: .ascizz " the number of words is :"
punc_msg: .ascizz " the number of punctuations is :"

.text
.globl main
main:

la $a0,prompt
li $v0,4
syscall

li $v0, 8
la $a0, userInput
li $a1, 200
syscall

la $t0,userInput

#check for empty string
lb $t1,0($t0)
beq $t1,$zero,error_funct

#checking for conditions
la $t0,userInput
li $t2,0    #character count
li $t3,0    #space count
li $t4,0    #sentence count
li $t5,0    #upper_case count
li $t6,0    #lower_case count

loop:
lb $t1,0($t0)
beq $t1,$zero,prints

addi $t2,$t2,1

addi $t7,$0,32 #ascii for space

bne $t1,$t7,sentence_check
addi $t3,$t3,1

sentence_check:
addi $t7,$0,46 #ascii for dot

bne $t1,$t7,uppercase_check
addi $t4,$t4,1

uppercase_check:
addi $t7,$0,65 #ascii for A
bl $t1,$t7,lowercase_check
addi $t7,$0,90 #ascii for Z
bg $t1,$t7,lowercase_check

addi $t5,$t5,1

lowercase_check:
addi $t7,$0,97 #ascii for a
bl $t1,$t7,l_count_increment
addi $t7,$0,122 #ascii for Z
bg $t1,$t7,l_count_increment

addi $t6,$t6,1

l_count_increment:
addi $t0,$t0,1
b loop

prints:
la $a0,character_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t2
syscall

la $a0,space_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t3
syscall

la $a0,sentence_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t4
syscall

la $a0,uppercase_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t5
syscall

la $a0,lowercase_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t6
syscall

la $a0,word_msg
li $v0,4
syscall

addi $t7,$t3,1

li $v0, 1
move $a0, $t7
syscall

la $a0,punc_msg
li $v0,4
syscall

#punctuation marks = total - spaces - uppercase count - lowercase count
sub $t7,$t2,$t3
sub $t7,$t7,$t5
sub $t7,$t7,$t6


li $v0, 1
move $a0, $t7
syscall

exit:
li $v0, 10
syscall


error_funct:
la $a0,error_msg
li $v0,4
syscall

li $v0, 10
syscall

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote