Answered step by step
Verified Expert Solution
Question
1 Approved Answer
. model small . stack 1 0 0 h . data names db 5 * 2 0 dup ( ' $ ' ) ; Array
model small
stack h
data
names db dup$ ; Array for names, each characters long
numberofnames db ; Total number of names
menuprompt db "Select an option:",
db Select Number and Length of Names",
db Enter Names",
db Perform Ascending Sorting",
db Perform Descending Sorting",
db Display Sorted Names",
db Exit", $
nameprompt db "Enter name: $
numberprompt db "Enter the number of names to display: $
invalidinputmsg db "Invalid input, try again.$
code
main proc
mov ax @data
mov ds ax
call displaymenu
jmp exitprogram
displaymenu:
mov ahh
lea dx menuprompt
int h
call getoption
cmp al
je selectnumberandlengthofnames
cmp al
je enternames
cmp al
je sortascending
cmp al
je sortdescending
cmp al
je displaysortednames
cmp al
jmp exitprogram ; Correctly handle exit without looping
getoption:
mov ahh ; Read character
int h ; from keyboard
sub al ; Convert ASCII to integer
cmp al
ja displaymenu ; Jump if input invalid
ret
selectnumberandlengthofnames:
mov ahh
lea dx numberprompt
int h
call getnumberofnames
jmp displaymenu
getnumberofnames:
mov ahh ; Read character
int h ; from keyboard
sub al ; Convert ASCII to integer
cmp al
ja selectnumberandlengthofnames ; Jump if input invalid
mov numberofnames, al
ret
enternames:
xor bx bx ; Reset BX to use as index for names array
xor cx cx ; Clear CX to use it for counting
mov cl numberofnames ; Load the number of names to enter into CL
enterloop:
lea dx nameprompt ; Load address of name prompt into DX
mov ahh ; Function to output string at DS:DX
int h ; DOS interrupt
lea dx namesbx ; Point DX to the current name entry in the array
mov ahAh ; Function to read string into buffer at DS:DX
int h ; DOS interrupt
add bx ; Move to the next name slot in the array
loop enterloop ; Repeat for the number of names
jmp displaymenu ; Return to the main menu after entering names
sortascending:
jmp displaymenu
sortdescending:
jmp displaymenu
displaysortednames:
mov bx
mov cl numberofnames
displayloop:
lea dx namesbx
mov ahh
int h
call displaynewline
add bx
loop displayloop
jmp displaymenu
displaynewline:
mov ahh
mov dl
int h
mov dl
int h
ret
exitprogram:
mov axCh ; Terminate program with return code
int h
main endp
end main
complete this code of ascending and descending part
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started