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

Write an MIPS assembly language code to count all the \"a\", \"e\" and \"o\" cha

ID: 3680911 • Letter: W

Question

Write an MIPS assembly language code to count all the "a", "e" and "o" characters of an user defined string. These 3 characters will be counted and displayed at the console individually. The string to be counted will be given by the user input. The results are displayed at the console. The characters defined as 1 byte ascii characters.

Please continue from here;

stringArray: .space 400
msg1: .asciiz "Enter the String"
maxCharacterNo: .word 100
characterArray: .asciiz "aeo"
msg2: .asciiz " the number of a:"
msg3: .asciiz " the number of e:"
msg4: .asciiz " the number of o:"

.text
.globl main
main:
la $a0,msg1
addi $v0,$zero,4
syscall

lw $a1,maxCharacterNo
la $a0,stringArray
addi $v0,$zero,8
syscall

Explanation / Answer

.LC0:

.string " Enter a string : "

.LC1:

.string "%s"

.LC2:

.string "character a is found %d times"

.LC3:

.string "character e is found %d times"

main:

pushq %rbp

movq %rsp, %rbp

subq $48, %rsp

movl $0, -36(%rbp)

movl $0, -40(%rbp)

movl $0, -44(%rbp)

movl $.LC0, %edi

movl $0, %eax

call printf

leaq -32(%rbp), %rax

movq %rax, %rsi

movl $.LC1, %edi

movl $0, %eax

call scanf

movb $97, -5(%rbp)

movb $101, -6(%rbp)

movb $111, -7(%rbp)

movl $0, -4(%rbp)

.L6:

movl -4(%rbp), %eax

cltq

movzbl -32(%rbp,%rax), %eax

testb %al, %al

je .L2

movl -4(%rbp), %eax

cltq

movzbl -32(%rbp,%rax), %eax

cmpb -5(%rbp), %al

jne .L3

movl -36(%rbp), %eax

addl $1, %eax

movl %eax, -36(%rbp)

jmp .L4

.L3:

movl -4(%rbp), %eax

cltq

movzbl -32(%rbp,%rax), %eax

cmpb -6(%rbp), %al

jne .L5

movl -40(%rbp), %eax

addl $1, %eax

movl %eax, -40(%rbp)

jmp .L4

.L5:

movl -4(%rbp), %eax

cltq

movzbl -32(%rbp,%rax), %eax

cmpb -7(%rbp), %al

jne .L4

movl -44(%rbp), %eax

addl $1, %eax

movl %eax, -44(%rbp)

.L4:

addl $1, -4(%rbp)

jmp .L6

.L2:

leaq -36(%rbp), %rax

movq %rax, %rsi

movl $.LC2, %edi

movl $0, %eax

call printf

leaq -40(%rbp), %rax

movq %rax, %rsi

movl $.LC3, %edi

movl $0, %eax

call printf

leaq -44(%rbp), %rax

movq %rax, %rsi

movl $.LC2, %edi

movl $0, %eax

call printf

movl $0, %eax

leave

ret

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