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?
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)
==========================================================================================
Get Answers For Free
Most questions answered within 1 hours.