Order Now  +1 678 648 4277 

Concatenate two strings using an external procedure in x86 assembly assignment help

The assignment deals with writing a program that concatenates two strings using x86 assembly. Our x86 assignment helpers have created a program that reads two strings from the user and calls a procedure to make the concatenation. The result is printed on the screen. The string concatenation procedure receives the two string arguments on the stack and returns the concatenated string.

X86 External Procedures for String Concatenation

;--------------------------------------------------------- ; Program that uses the procedure strCat to concatenate two strings ; ; Author: xxxxxxxxx ; Date: 11/17/2018 ;--------------------------------------------------------- INCLUDE Irvine32.inc EXTERN strCat:PROC ; declare the external strCat subroutine .data prompt DB "Enter a string", 10, 0 string1 DB 200 DUP(0) ; space to save first string and concatenation string2 DB 100 DUP(0) ; space to save second string .code main PROC mov edx, OFFSET prompt ; print prompt for first string call WriteString mov edx, OFFSET string1 ; read first string and save it in the string1 space mov ecx, 100 ; read at most 100 characters call ReadString mov edx, OFFSET prompt ; print prompt for second string call WriteString mov edx, OFFSET string2 ; read second string and save it in the string2 space mov ecx, 100 ; read at most 100 characters call ReadString push OFFSET string2 ; pass second string on the stack as second argument to strCat push OFFSET string1 ; pass first string on the stack as first argument to strCat call strCat ; concatenate using strCat mov edx, OFFSET string1; print the concatenated string, which is saved in string1 call WriteString call CrLf ; print a new line call WaitMsg ; wait for the user to press a key exit ; exit the program main ENDP END main ;--------------------------------------------------------- ; strCat: Concatenates two strings, receives the addresses ; for the two strings on the stack ; ; Author: xxxxxxxxx ; Date: 11/17/2018 ;--------------------------------------------------------- INCLUDE Irvine32.inc .code PUBLIC strCat strCat PROC C push ebp ; save ebp on the stack mov ebp, esp ; load stack frame address in ebp push esi ; save esi contents on the stack push edi ; save edi contents on the stack mov edi, [ebp + 8] ; load first string pointer in edi endStrLoop: mov al, [edi] ; load a character from the first string cmp al, 0 ; see if we reached the end of the string je endFound ; if we reached the end, terminate the loop inc edi ; else, advance to next char in string jmp endStrLoop ; repeat to find end of string endFound: mov esi, [ebp + 12] ; load second string pointer in edi catLoop: mov al, [esi] ; load a character from the second string mov [edi], al ; save the char at the end of the first string cmp al, 0 ; see if we reached the end of the string je endCat ; if so, we have concatenated the strings, end loop inc esi ; else, advance to next character in second string inc edi ; and advance to next space at end of first string jmp catLoop ; repeat to concatenate next character endCat: pop edi ; restore prevoius value of edi pop esi ; restore prevoius value of esi pop ebp ; restore ebp stack frame ret 8 ; return to the main procedure, pop arguments strCat ENDP END