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

X86 Assembly Language help implement a program with two procedures create one pr

ID: 3720267 • Letter: X

Question

X86 Assembly Language help implement a program with two procedures
create one procedure, called getString that
    receives:
        esi - the address of a prompt (asks the user for something)
        edi - the address of the buffer where to put the string (from the user)
        ecx - the size of the buffer
    returns:
        eax - number of char read
    have it restore the values of all register (except eax)

and create the second procedure that prints two strings, called DisplayStrings that
    receives:
        esi - the address of a prompt or description
        edi - the address the second string with some info
    returns: nothing
    have it restore the values of any register it uses

Use the following main procedure that calls getString twice, asking the user for
a filename for input and second time a filename for output
main then calls DisplayStrings, twice, to display the two filenames

INCLUDE Irvine32.inc

.data
    InputFilenamePrompt   BYTE "Please write the name of the file to read:",0
    OutputFilenamePrompt BYTE "Please Write the name of the file to write:",0
    InputFilenameDisplay BYTE "The input filename is: ",0
    OutputFilenameDisplay BYTE "The output filename is: ",0

    MAXNAMESIZE = 64
    inFileName   BYTE MAXNAMESIZE DUP(0)
    outFileName BYTE MAXNAMESIZE DUP(0)
    inFileSize   DWORD MAXNAMESIZE
    outFileSize DWORD MAXNAMESIZE



.code

main PROC
    ; get name for input file
    mov esi, OFFSET InputFilenamePrompt
    mov edi, OFFSET inFileName
    mov ecx, MAXNAMESIZE
    call GetString
    mov outFileSize, eax

    ; get name for output file
    mov esi, OFFSET OutputFilenamePrompt
    mov edi, OFFSET outFileName
    mov ecx, MAXNAMESIZE
    call GetString
    mov outFileSize, eax

    ; display input file name
    mov esi, OFFSET InputFilenameDisplay
    mov edi, OFFSET inFileName
    call DisplayStrings

    ; display input file name
    mov esi, OFFSET OutputFilenameDisplay
    mov edi, OFFSET outFileName
    call DisplayStrings

    exit
main ENDP
X86 Assembly Language help implement a program with two procedures
create one procedure, called getString that
    receives:
        esi - the address of a prompt (asks the user for something)
        edi - the address of the buffer where to put the string (from the user)
        ecx - the size of the buffer
    returns:
        eax - number of char read
    have it restore the values of all register (except eax)

and create the second procedure that prints two strings, called DisplayStrings that
    receives:
        esi - the address of a prompt or description
        edi - the address the second string with some info
    returns: nothing
    have it restore the values of any register it uses

Use the following main procedure that calls getString twice, asking the user for
a filename for input and second time a filename for output
main then calls DisplayStrings, twice, to display the two filenames

INCLUDE Irvine32.inc

.data
    InputFilenamePrompt   BYTE "Please write the name of the file to read:",0
    OutputFilenamePrompt BYTE "Please Write the name of the file to write:",0
    InputFilenameDisplay BYTE "The input filename is: ",0
    OutputFilenameDisplay BYTE "The output filename is: ",0

    MAXNAMESIZE = 64
    inFileName   BYTE MAXNAMESIZE DUP(0)
    outFileName BYTE MAXNAMESIZE DUP(0)
    inFileSize   DWORD MAXNAMESIZE
    outFileSize DWORD MAXNAMESIZE



.code

main PROC
    ; get name for input file
    mov esi, OFFSET InputFilenamePrompt
    mov edi, OFFSET inFileName
    mov ecx, MAXNAMESIZE
    call GetString
    mov outFileSize, eax

    ; get name for output file
    mov esi, OFFSET OutputFilenamePrompt
    mov edi, OFFSET outFileName
    mov ecx, MAXNAMESIZE
    call GetString
    mov outFileSize, eax

    ; display input file name
    mov esi, OFFSET InputFilenameDisplay
    mov edi, OFFSET inFileName
    call DisplayStrings

    ; display input file name
    mov esi, OFFSET OutputFilenameDisplay
    mov edi, OFFSET outFileName
    call DisplayStrings

    exit
main ENDP
help implement a program with two procedures
create one procedure, called getString that
    receives:
        esi - the address of a prompt (asks the user for something)
        edi - the address of the buffer where to put the string (from the user)
        ecx - the size of the buffer
    returns:
        eax - number of char read
    have it restore the values of all register (except eax)

and create the second procedure that prints two strings, called DisplayStrings that
    receives:
        esi - the address of a prompt or description
        edi - the address the second string with some info
    returns: nothing
    have it restore the values of any register it uses

Use the following main procedure that calls getString twice, asking the user for
a filename for input and second time a filename for output
main then calls DisplayStrings, twice, to display the two filenames

INCLUDE Irvine32.inc

.data
    InputFilenamePrompt   BYTE "Please write the name of the file to read:",0
    OutputFilenamePrompt BYTE "Please Write the name of the file to write:",0
    InputFilenameDisplay BYTE "The input filename is: ",0
    OutputFilenameDisplay BYTE "The output filename is: ",0

    MAXNAMESIZE = 64
    inFileName   BYTE MAXNAMESIZE DUP(0)
    outFileName BYTE MAXNAMESIZE DUP(0)
    inFileSize   DWORD MAXNAMESIZE
    outFileSize DWORD MAXNAMESIZE



.code

main PROC
    ; get name for input file
    mov esi, OFFSET InputFilenamePrompt
    mov edi, OFFSET inFileName
    mov ecx, MAXNAMESIZE
    call GetString
    mov outFileSize, eax

    ; get name for output file
    mov esi, OFFSET OutputFilenamePrompt
    mov edi, OFFSET outFileName
    mov ecx, MAXNAMESIZE
    call GetString
    mov outFileSize, eax

    ; display input file name
    mov esi, OFFSET InputFilenameDisplay
    mov edi, OFFSET inFileName
    call DisplayStrings

    ; display input file name
    mov esi, OFFSET OutputFilenameDisplay
    mov edi, OFFSET outFileName
    call DisplayStrings

    exit
main ENDP

Explanation / Answer

getString:

; display the prompt, service code for syscall is 9

mov                 ah, 09h

lea                    dx, esi

int                    21h

;input string from keyboard

mov                 ah, 0Ah

lea                    dx, dsi

int                    21h

displayString:

; display prompt

mov                 ah, 09h

lea                    dx, esi

int                    21h

;display string

mov                 ah, 09h

lea                    dx, edi

int                    21h