175k views
4 votes
1. For this lab assignment, please implement an assembly program that counts the number of symbols in a string (characters other than uppercase/lowercase letters and numerals). The string can be hard-coded in the program as a cstring type. Your implementation should be in an assembly program. Please store the count value in a variable (defined using .data in your code). You should display this value using the memory browser. Hint: Create an assembly project as mentioned in the tutorial for Lab 4. You do not need to print the result in the console window. Hint: You need to declare your variable in data segment (.data) of the code to make them readable and writable as shown in the example below: data symb_count: int 0 (50 pts) Please include a flowchart for your implementation.

1 Answer

2 votes

Final answer:

To implement an assembly program that counts the number of symbols in a string, you need to define a variable in the data segment of your assembly code, load the address of the string into a register, initialize a counter register to 0, start a loop to iterate through each character in the string, check if the character is a symbol, increment the counter if it is a symbol, store the count value in the variable, and display the count value using the memory browser.

Step-by-step explanation:

To implement an assembly program that counts the number of symbols in a string, you will need to follow these steps:

  1. Define a variable in the data segment of your assembly code using the .data directive. For example, you can define a variable named symb_count as an integer and initialize it to 0.
  2. Load the address of the string into a register. You can use the lea (load effective address) instruction to do this.
  3. Initialize a counter register to 0 to keep track of the number of symbols.
  4. Start a loop to iterate through each character in the string.
  5. Load a character from the string into a register.
  6. Check if the character is a symbol. You can use conditional statements and comparison instructions to do this.
  7. If the character is a symbol, increment the counter register by 1.
  8. Continue the loop until all characters in the string have been processed.
  9. Store the count value in the symb_count variable.
  10. Display the count value using the memory browser.

Here is an example of how the assembly code might look like:.data

User Nuno Linhares
by
8.1k points