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

Write an assembly program that will read in a person\'s name and then print it i

ID: 3768047 • Letter: W

Question

Write an assembly program that will read in a person's name and then print it in lastname, firstname [middle name] order. The notation [middle name] means zero or more middle names. For example using an input of: John James Smith You will print Smith, John James You will need to write a procedure that will read in characters until the enter key is pressed. Store the characters in an array of characters defined in your data segment. As you read the characters you will need to count the number of characters entered by the user, this may also be stored in a data segment variable. The maximum length of a name will be 80 characters. You will then need to start at the right end of the name and search backwards for a blank. At this point you can now print out the last name a comma and go back to the beginning of the array and print the rest of the name. Make sure to properly test you program before submitting it. You should test single names such as Rihanna, no name (hit enter key immediately), names with no middle name, and also multiple middle names.

Explanation / Answer

.MODEL SMALL
.STACK 100H

.DATA
    MSG_1 EQU 'Enter name : $'
    MSG_2 EQU 0DH,0AH,'name :',0DH,0AH,'$'
    MSG_3 EQU 0DH,0AH,'$'

    PROMPT_1 DB MSG_1
    PROMPT_2 DB MSG_2
    NEWLINE   DB MSG_3

.CODE
   MAIN PROC
     MOV AX, @DATA                ; initialize DS
     MOV DS, AX

     LEA DX, PROMPT_1             ; load and display PROMPT_1
     MOV AH, 9
     INT 21H

     MOV AH, 1                    ; read first initial
     INT 21H

     MOV BL, AL                   ; save the first initial into BL

     MOV AH, 1                    ; read second initial
     INT 21H

     MOV BH, AL                   ; save the second initial into BH

     MOV AH, 1                    ; read third initial
     INT 21H

     MOV CL, AL                   ; save the third initial into CL

     LEA DX, PROMPT_2             ; load and display PROMPT_2
     MOV AH, 9
     INT 21H

     MOV AH, 2                    ; display the first name
     MOV DL, BL
     INT 21H

     LEA DX, NEWLINE              ; display new line
     MOV AH, 9
     INT 21H

     MOV AH, 2                    ; display the middle name
     MOV DL, BH
     INT 21H

     LEA DX, NEWLINE              ; display new line
     MOV AH, 9
     INT 21H

     MOV AH, 2                    ; display the second name
     MOV DL, CL
     INT 21H

     MOV AH, 4CH                  ; return control to DOS
     INT 21H
   MAIN ENDP
END MAIN

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