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

Problem Description: Write an assembly program to read three 32-bit signed integ

ID: 3731924 • Letter: P

Question

Problem Description:

Write an assembly program to read three 32-bit signed integers from the user.

Write an assembly program that reads a line of input from the user and counts the total number of characters, and the number of spaces (ASCII character 32). Prompt the user for the line of input and label the outputs.

It can be safely assumed that the line of input from the user will contain at most 255 characters. Note that the system call that reads the string includes the newline character in the returned string. That should be included as one of the characters to count.

Submit the Following File(s):

WordCount.asm

Required Input:

A line of input with at most 255 characters (including the newline). The input may contain some space characters.

Required Output:

Your output should look something like the following example.

Explanation / Answer

WordCount.asm :-

This is a assembly program to take a string as input and gives the count of ascii chars and spaces.

print macro m ;macro for a string

mov ah,09h

mov dx,offset m

int 21h

endm

.model small

;Data segment

.data

empty db 10,13, " $"

str db 25,?,25 dup('$')

str1 db 10,13, "Enter the string: $"

str2 db 10,13, "Numberof characters: $"

str3 db 10,13, "Number of spaces: $"

INSTR1 DB 50 DUP ( "$" )

scount db ?

;Code segment

.code

start:

mov ax,@data

mov ds,ax

lea si,INSTR1

mov ah,9

lea dx,str1

int 21h

mov ah,0ah

mov dx,si

int 21h

mov ah,2

mov dl,0ah

int 21h

mov dl,0dh

int 21h

mov ah,9

lea dx,str2

int 21h

mov bl,INSTR1+1

mov al,bl

aam

add ax,3030h

mov dh,al

mov dl,ah

mov ah,2

int 21h

mov dl,dh

mov ah,2

int 21h

print str1

call accept_string

mov si,offset str+2 ;position si to start of the string

mov cl,str+1 ;copy length in cl

mov dh,00 ;counter to store number of spaces  

cmpagain1: mov al,[si] ;copy content at memory location "si" in "al"

cmp al,' ' ;compare "al" with space

jne below ;if not equal jump to label "below"

inc dh

  

below: inc si ;move to next character

dec cl ;decrement string length counter

jnz cmpagain1 ;if not zero check again

  

mov scount,dh ;save the count in memory location "scount"

mov bl,scount ;copy count to "bl" for printing

print str3

call display1

exit:

mov ah,4ch ;exit the program

int 21h

;accept procedure

accept proc near

mov ah,01

int 21h

ret

accept endp

display1 proc near

mov al,bl

mov bl,al

and al,0f0h

mov cl,04

rol al,cl

cmp al,09

jbe number

add al,07

number: add al,30h

mov dl,al

mov ah,02

int 21h

mov al,bl

and al,00fh

cmp al,09

jbe number2

add al,07

number2: add al,30h

mov dl,al

mov ah,02

int 21h

ret

display1 endp

accept_string proc near

mov ah,0ah ;accept string from user function

mov dx,offset str ; store the string in memory pointed by "DX"

int 21h

ret

accept_string endp

end start

end

By giving the string we can abserve the required outcome.

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