Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. model small . stack 1 0 0 h . data names db 5 * 2 0 dup ( ' $ ' ) ; Array

.model small
.stack 100h
.data
names db 5*20 dup('$') ; Array for 5 names, each 20 characters long
number_of_names db 5 ; Total number of names
menu_prompt db "Select an option:", 13,10
db "1. Select Number and Length of Names", 13,10
db "2. Enter Names", 13,10
db "3. Perform Ascending Sorting", 13,10
db "4. Perform Descending Sorting", 13,10
db "5. Display Sorted Names", 13,10
db "6. Exit", 13,10,'$'
name_prompt db "Enter name: $"
number_prompt db "Enter the number of names to display: $"
invalid_input_msg db "Invalid input, try again.$"
.code
main proc
mov ax, @data
mov ds, ax
call display_menu
jmp exit_program
display_menu:
mov ah,09h
lea dx, menu_prompt
int 21h
call get_option
cmp al,1
je select_number_and_length_of_names
cmp al,2
je enter_names
cmp al,3
je sort_ascending
cmp al,4
je sort_descending
cmp al,5
je display_sorted_names
cmp al,6
jmp exit_program ; Correctly handle exit without looping
get_option:
mov ah,01h ; Read character
int 21h ; from keyboard
sub al,'0' ; Convert ASCII to integer
cmp al,6
ja display_menu ; Jump if input >6(invalid)
ret
select_number_and_length_of_names:
mov ah,09h
lea dx, number_prompt
int 21h
call get_number_of_names
jmp display_menu
get_number_of_names:
mov ah,01h ; Read character
int 21h ; from keyboard
sub al,'0' ; Convert ASCII to integer
cmp al,5
ja select_number_and_length_of_names ; Jump if input >5(invalid)
mov number_of_names, al
ret
enter_names:
xor bx, bx ; Reset BX to use as index for names array
xor cx, cx ; Clear CX to use it for counting
mov cl, number_of_names ; Load the number of names to enter into CL
enter_loop:
lea dx, name_prompt ; Load address of name prompt into DX
mov ah,09h ; Function to output string at DS:DX
int 21h ; DOS interrupt
lea dx, names[bx] ; Point DX to the current name entry in the array
mov ah,0Ah ; Function to read string into buffer at DS:DX
int 21h ; DOS interrupt
add bx,20 ; Move to the next name slot in the array
loop enter_loop ; Repeat for the number of names
jmp display_menu ; Return to the main menu after entering names
sort_ascending:
jmp display_menu
sort_descending:
jmp display_menu
display_sorted_names:
mov bx,0
mov cl, number_of_names
display_loop:
lea dx, names[bx]
mov ah,09h
int 21h
call display_new_line
add bx,20
loop display_loop
jmp display_menu
display_new_line:
mov ah,02h
mov dl,13
int 21h
mov dl,10
int 21h
ret
exit_program:
mov ax,4C00h ; Terminate program with return code 0
int 21h
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

How We Listen?

Answered: 1 week ago