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

Write a program all written in assembly that inputs an entire line of text, up t

ID: 3572287 • Letter: W

Question

Write a program all written in assembly that inputs an entire line of text, up to 132 characters, into a buffer. Then have your program determine how many time each letter of the alphabet occurs You are to count all letters a-z, A-Z, and 0-9 only Your screen output is to look similar to a - 6 times b - 3 times c - 5 times etc, Only display the letters you are counting. You will declare the a input buffer called Char Input (i.e. array) and write the code to count the number of a's that occur, b's, etc and then display them. You will have another buffer Char Count that will hold the char accounts.

Explanation / Answer

#include "stdafx.h"

#include "stdio.h"

#include "stdlib.h"

#include <string>

using namespace std;

char msj1[50];

char text[135];

int arr_digits[ 10 ];

int arr_lowercase[ 26 ];

int arr_uppercase[ 26 ];

char str[6];

char charr;

char char_equal;

char space[4];

int idx,i,tmp;

void printspace () {

printf( space );

}

void printstr () {

printf( str );

}

void print_char_equal () {

printf( "%c",char_equal );

}

void print_digit_counter () {

printf( "%d",arr_digits[ i ] );

}  

void printcharr_digit () {

printf( "%c",i+48 );

}

void display_digit_counters () {

__asm {

mov i, 0

display_digits:

call printspace

call printcharr_digit

call print_char_equal

call print_digit_counter

;NEXT COUNTER TO DISPLAY.

inc i

cmp i, 10

jne display_digits ;IF ( I != 10 ) JUMP.

}

}

void printcharr_uppercase () {

printf( "%c",i+65 );

}

void print_uppercase_counter () {

printf( "%d",arr_uppercase[ i ] );

}  

void display_uppercase_counters () {

__asm {

mov i, 0

display_uppercase:

call printspace

call printcharr_uppercase

call print_char_equal

call print_uppercase_counter

;NEXT COUNTER TO DISPLAY.

inc i

cmp i, 26

jne display_uppercase ;IF ( I != 26 ) JUMP.

}

}

void printcharr_lowercase () {

printf( "%c",i+97 );

}

void print_lowercase_counter () {

printf( "%d",arr_lowercase[ i ] );

}  

void display_lowercase_counters () {

__asm {

mov i, 0

display_lowercase:

call printspace

call printcharr_lowercase

call print_char_equal

call print_lowercase_counter

;NEXT COUNTER TO DISPLAY.

inc i

cmp i, 26

jne display_lowercase ;IF ( I != 10 ) JUMP.

}

}

void inc_digit () {

arr_digits[ idx ]++;

}

void check_digit () {

__asm {

and ebx, 0ffh

cmp bl, '0'

jb   not_a_digit ;IF AL < '0' FINISH.

cmp bl, '9'

ja   not_a_digit ;IF AL > '9' FINISH.

;IF NO JUMP, AL IS A DIGIT. INCREASE COUNTER USING

;THE DIGIT AS OFFSET INSIDE THE ARRAY OF COUNTERS,

;FOR EXAMPLE, THE COUNTER FOR DIGIT '3' IS THE THIRD

;POSITION IN THE ARRAY.

sub bl, 48 ;CONVERT DIGIT IN NUMBER ('0'..'9'->0..9).

mov idx, ebx

call inc_digit

not_a_digit:

}

}

void inc_uppercase () {

arr_uppercase[ idx ]++;

}

void check_uppercase () {

__asm {

and ebx, 0ffh

cmp bl, 'A'

jb   not_uppercase ;IF AL < 'A' FINISH.

cmp bl, 'Z'

ja   not_uppercase ;IF AL > 'Z' FINISH.

;IF NO JUMP, AL IS AN UPPERCASE LETTER. INCREASE COUNTER

;USING THE LETTER AS OFFSET INSIDE THE ARRAY OF COUNTERS,

;FOR EXAMPLE, THE COUNTER FOR LETTER 'C' IS THE THIRD

;POSITION IN THE ARRAY.

sub bl, 65 ;CONVERT DIGIT IN NUMBER ('A'..'Z'->0..25).

mov idx, ebx

call inc_uppercase

not_uppercase:

}

}

void inc_lowercase () {

arr_lowercase[ idx ]++;

}

void check_lowercase () {

__asm {

and ebx, 0ffh

cmp bl, 'a'

jb   not_lowercase ;IF AL < 'a' FINISH.

cmp bl, 'z'

ja   not_lowercase ;IF AL > 'z' FINISH.

;IF NO JUMP, AL IS A LOWERCASE LETTER. INCREASE COUNTER

;USING THE LETTER AS OFFSET INSIDE THE ARRAY OF COUNTERS,

;FOR EXAMPLE, THE COUNTER FOR LETTER 'c' IS THE THIRD

;POSITION IN THE ARRAY.

sub bl, 97 ;CONVERT LETTER IN NUMBER ('a'..'z'->0..25).

mov idx, ebx

call inc_lowercase

not_lowercase:

}

}

int _tmain(int argc, _TCHAR* argv[])

{

strcpy( msj1,"Enter a line of text (132 max) : " );

char_equal = '=';

strcpy( space," " );

printf( msj1 );

scanf( "%s",text );

__asm {

;COUNT CHARACTERS OF THE LINE OF TEXT.

lea esi, text ;SI POINTS TO BEGINNING OF STRING. THE FIRST

                 ;2 BYTES ARE FOR CONTROL (MAX LENGTH, LENGTH).

repeat:

;CHECK IF CURRENT CHARACTER IS DIGIT, UPPERCASE OR LOWERCASE.

mov tmp, esi

mov bl, [ esi ] ;GET CURRENT CHARACTER.

call check_digit

mov esi, tmp

mov bl, [ esi ] ;GET CURRENT CHARACTER.

call check_uppercase

mov esi, tmp

mov bl, [ esi ] ;GET CURRENT CHARACTER.

call check_lowercase

mov esi, tmp

;NEXT CHARACTER.

inc esi

mov bl, [ esi ]

cmp bl, 0

jne repeat ;IF NEXT CHARACTER IS NOT 13, REPEAT.

;DISPLAY COUNTERS.

call display_digit_counters   

call display_uppercase_counters   

call display_lowercase_counters   

}

scanf( "%s",text );

return 0;

}

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