Question

In MASM(80x86) Assembly Language, how would one declare an array of strings? The user should be...

In MASM(80x86) Assembly Language, how would one declare an array of strings? The user should be able to use keyboard input to put each string in the array. When they are done, they will type "x."

The program should then print out the contents of the entire array.

How would one implement a MASM 80x86 program that accomplishes this?

Homework Answers

Answer #1

data segment
enter db 13
max db 10
n1 db 10,13,'$'
maxlen db 20
str db 10 dup(20 dup(?))
msg1 db "The strings entered are $"
data ends
code segment
;macro to print next line.....
pl macro
push dx
push ax
lea dx,n1
mov ah,9
int 21h
pop ax
pop dx
endm
;macro to write char.....
write macro
;dl
mov ah,2
int 21h
endm
;macro to read char per string.....
read macro
mov ah,1
int 21h
endm
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov cl,max
mov ch,0
mov di,0
;loop taking max no.of strings(max is defined in data segment)
l :
push cx
mov si,0
;maxlen is maximum len of each string(maxlen is defined in data seg)
mov ch,0
mov cl,maxlen
;loop to get a string until x or enter key is pressed
gets :
read
;is input is x then put enter key at end and jump to priting
cmp al,'x'
push ax
mov ax,di
mul maxlen
mov bx,ax
add bx,si
mov str[bx],13
pop ax
cmp al,'x'
je p
push ax
mov ax,di
mul maxlen
mov bx,ax
add bx,si
pop ax
mov str[bx],al
inc si
;if the pressed key is enter the jump to get next string else take next char
cmp al,13
je nxt
loop gets
nxt:
pop cx
inc di
loop l
p:
;calling macro
pl
;printing message
lea dx,msg1
mov ah,9
int 21h
mov cx,di
mov di,0
;printing starts here
p1 :
pl ;pl is macro to go to next line
mov si,0
;printing each char of a string
p2 :
mov ax,di
mul maxlen
mov bx,ax
add bx,si
mov dl,str[bx]
inc si
write
cmp dl,13
jne p2
inc di
mov si,0
loop p1
mov ah,4ch
int 21h
code ends
end start

==========================================================================================

Images:


output:

(p3 is program name here and string 1, string 2, and string 3 are inputs)

==========================================================================================

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a program that allows the user to input a list of first names into one...
Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. The output should be a list of emial addresses where the address is of the following form: [email protected] Declare FirstName[100] as String Declare LastName[100] as String Declare email as String Declare K as Integer Declare index as Integer Write "Enter first and last name." Write...
(MIPS Assembly language) Ask user for two decimal numbers and save to memory (not registers). Multiply...
(MIPS Assembly language) Ask user for two decimal numbers and save to memory (not registers). Multiply these two numbers using adding and shifting only, not the "mul" instruction and print the product to the user as both a base-10 and base-32 (again, no using div/mul/rem). Save the output to a txt file. The program should run 5 times, with no user input needed to continue the program.    
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
In assembly masm use the code below! Write a program that reverse a string using indirect...
In assembly masm use the code below! Write a program that reverse a string using indirect addressing (may not use the stack - push/pop). The string will be given by the user and be up to 64 characters long INCLUDE Irvine32.inc INCLUDE macros.inc MAX = 64 .data source BYTE MAX DUP('#'),0 destination BYTE LENGTHOF source DUP('*'),0 actual_length DWORD ? ask BYTE "Enter a String: ",0 .code main proc ; ask user for input mov edx, OFFSET ask call WriteString ;...
** Language Used : Python ** PART 2 : Create a list of unique words This...
** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...
3. Create a program which allows the user to swap individual words in an input string....
3. Create a program which allows the user to swap individual words in an input string. Given a string of input, your program should count and store the number of words in a 2D array. The user can then select the index of the words they want to swap. Your program should swap those two words and then print the entire string to ouput. • Use string prompt "> ". • Use indices prompt "Enter two indices: ". • Remove...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
You need to write a permute class that will take first and second strings to rearrange...
You need to write a permute class that will take first and second strings to rearrange letters in first, followed by second. For example, if the first is “CAT” string and second is “MAN” string, then the program would print the strings TACMAN, ATCMAN, CTAMAN, TCAMAN, ACTMAN, and CATMAN. The first and second strings can be any length of string or a null. The permute class uses a Node class as link list node to link all letters arrangement. The...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
In this lab, you complete a partially prewritten C++ program that uses an array. The program...
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help...