Write an assembly language program to input a string from t…

Write an assembly language program to input a string from the user, count and display the number of times each word occur in the user input string. For example if the user types in: Your output should be: Hello 3 there 2 how 1 are 2

Answer

Title: Assembly Language Program to Count Word Occurrences in User Input String

Introduction:
This assembly language program aims to prompt the user to input a string, count the occurrence of each word in the input string, and display the results. The program will perform input validation, word separation, word grouping, and word counting using appropriate assembly language instructions and data structures. The input string will be stored in memory, and the count for each word will be stored in an array. Finally, the program will display the word count results to the user.

Program Algorithm:
1. Declare variables and data structures:
– Define an input buffer to store the user input string.
– Define an array to store word counts and initialize it with zeros.
– Define a word buffer to temporarily hold each word while counting.

2. Read the user input string:
– Display a prompt message for the user.
– Read the input string from the user and store it in the input buffer.

3. Perform input validation and word separation:
– Iterate through each character of the input string.
– Check if the character is an alphanumeric character or a space.
– If alphanumeric, append it to the word buffer.
– If space, terminate the word with a null character and reset the word buffer for the next word.

4. Count the occurrence of each word:
– Iterate through each word in the word buffer.
– Check if the word is already present in the array of word counts.
– If present, increment the corresponding count.
– If not present, add the word to the array and initialize its count to one.

5. Display the word count results:
– Iterate through the array of word counts.
– If the count is greater than zero, display the word followed by its count.

Pseudocode:

“`assembly
.data
input_buffer: .space MAX_INPUT_LENGTH ; Buffer to hold user input string
word_counts: .space MAX_WORD_COUNT * (LABEL_LENGTH + 1) ; Array to store word counts
word_buffer: .space MAX_WORD_LENGTH ; Buffer to temporarily hold each word

.text
.globl _start

_start:
; Prompt the user for input
; Read the user input string into input_buffer

; Set up loop to iterate through each character of the input string
; Check if the character is alphanumeric or space
; If alphanumeric, add it to word_buffer
; If space, terminate the word with a null character and reset word_buffer

; Check if word_buffer is already present in word_counts
; If present, increment the corresponding count
; If not present, add the word to word_counts and initialize its count to 1

; Display the word count results to the user

_exit:
; Exit the program
“`

In the above pseudocode, MAX_INPUT_LENGTH represents the maximum length of the user input string, MAX_WORD_COUNT represents the maximum number of distinct words that can be counted, and MAX_WORD_LENGTH represents the maximum length of a word. The LABEL_LENGTH represents the length required to store a word in the word_counts array, including the null character.

This assembly language program outlines the algorithm and main structure required to count the occurrences of each word in a user input string. The specific implementation details will depend on the chosen assembly language and its available instructions and data structures.

Do you need us to help you on this or any other assignment?


Make an Order Now