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

please just review if code is good and there is no redundant code that can be mo

ID: 3695201 • Letter: P

Question

please just review if code is good and there is no redundant code that can be modified.


   ; Read a text file (Readfile.asm)
   ; Read, display, and copy a text file.

   .model small
   ;.stack 100h
   .data
   BufSize = 5000                           ;symbolic constant for maximum input file bytes to store
   infile       db "MYTXT.TXT",0           ;name of the file to be read
   outfile       db "myout.txt",0           ;name of the output file to creat and fill with data
   inHandle   dw ?                       ;16-bit identifier variable for the input file
   outHandle   dw ?                       ;16-bit identifier variable for the output file
   buffer       db BufSize DUP(?)           ;array to hold bytes of data read from input file
   bytesRead   dw ?                       ;counter to track number of bytes read from input file
       ;error messages
   fof           db "file open failed!$"
   frf           db "file read failed!$"
   fdf           db "file display failed!$"
   fc1f       db "close input file failed!$"
   fcf           db "file create failed!$"
   fwf           db "file write failed!$"
   fc2f       db "close output file failed!$"
   ;end of data definitions

   ;-------------begin main program section-------------;
   .code
   main PROC
       mov   ax,@data
       mov   ds,ax               ;initialize data segment register

   ; Section 1: Open existing input text file
       mov ah,3Dh             ; function: open file
       mov al,0             ; input mode
       mov dx,offset infile   ; pass a reference to the input file name
       int 21h            ; call DOS
       jc quit1               ; quit if error and display appropriate error message
       mov inHandle,ax           ; store input file handle

   ; Section 2: Read the input text file and store contents in the array buffer
       mov   ah,3Fh               ; function: read file or device
       mov   bx,inHandle           ; provide file handle of file to be read
       mov   cx,BufSize           ; specify the maximum bytes to read
       mov   dx,OFFSET buffer   ; pass a reference to the array buffer that will be filled
       int   21h                   ; call DOS
       jc   quit2               ; quit if error and display appropriate error message
       mov   bytesRead,ax       ; store the number of bytes that were read just now

   ; Section 3: Display the buffered text file contents in the console
       mov   ah,40h               ; function: write file or device
       mov   bx,1               ; specify console output
       mov   cx,bytesRead       ; specify number of bytes to write
       mov   dx,OFFSET buffer   ; pass a reference to the array to be displayed
       int   21h                   ; call DOS
       jc   quit3               ; quit if error and display appripriate error message

   ; Section 4: Close the input text file
       mov   ah,3Eh         ; function: close file
       mov   bx,outHandle   ; specify the file to be closed
       int 21h        ; call DOS
       jc   quit4           ; quit if error

   ; Section 5: Create the output text file
       mov   dx, offset outfile   ; pass a reference to the output file name
       mov   cx, 0               ; do not specify any file attributes
       mov   ah, 3ch               ; function: create or truncate file
       int   21h                   ; call DOS
       jnc   quit5               ; display message and quit if error
       mov   outHandle, ax       ; store output file handle

   ; Section 6: Write buffer to the output text file
       mov   ah,40h               ; function: write file or device
       mov   bx,outHandle       ; provide file handle of file to be written
       mov   cx,bytesRead       ; specify number of bytes to write
       mov   dx,OFFSET buffer   ; pass a reference to the array that will be written to file
       int   10h                   ; call DOS
       jc   quit6               ; quit if error

   ; Section 7: Close the output text file
       mov   ah,3Eh             ; function: close file
       mov   bx,offset outfile   ; specify the file to be closed
       int   21h            ; call MS-DOS
       jc quit7               ; go to program exit sequence

   ;----------   Begining of Error messages table   ----------;
   ;---------------------------------------------------------;
   ; display error message one
   quit1: mov dx, offset fof
           jmp Send_error
          
   ; display error message two
   quit2: mov dx, offset frf
           jmp Send_error

   ; display error message three
   quit3: mov dx, offset fdf
           jmp Send_error
          
   ; display error message four
   quit4: mov dx, offset fc1f
           jmp Send_error
          
   ; display error message five
   quit5: mov dx, offset fcf
           jmp Send_error
          
   ; display error message six
   quit6: mov dx, offset fwf
           jmp Send_error
          
   ; display error message seven
   quit7: mov dx, offset fc2f
           jmp Send_error
          
   Send_error:
           mov ah, 09h
           int 21h
           jmp       done
  
  
   ;----------   End of Error messages table       ----------;
   ;-----------------------------------------------------;
          
          
   ;----------   Program Termination   ----------;
   done:
           mov ah, 4ch       ; function: DOS Exit Program
           mov al, 0       ; specify return code 0
           int 21h           ; adios amigo!
   main ENDP
   END main

  

Explanation / Answer

the code is perfect no redundancy can be done