Complete the following Assembly Language code to create a Pig Latin \"silly\" St
ID: 3804948 • Letter: C
Question
Complete the following Assembly Language code to create a Pig Latin "silly" String by writing two procedures CreateSillyStr and addConvertedWord.
Given an input_str consisting of: "This sentence will be converted to silly string "
you will produce a converted string of: "hisTay entencesay illway ebay onvertedcay otay illysay tringsay"
Guidelines:
You should include Irvine32.inc.
Your procedures should NOT use INVOKE or any advanced procedure calling techniques. You must explicity deal with all registers used in the procedure, and you must assume that you need to protect all registers that could possibly be used in main, whether they are used or not.
However, in the two procedures that you write, you CANNOT use any procedures from Irvine32.inc.
In addConvertedWord you must use movsb and rep.
In addConvertedWord, you should find the length of the current output_str, and find the length of converted_word, as part of your implementation.
Given Code:
INCLUDE Irvine32.inc
.data
input_str BYTE "This sentence will be converted to silly string ",0
output_str BYTE 100 DUP(0),0
word_to_convert BYTE ?
converted_word BYTE 103 DUP(?),0
index_into_input_str DWORD 0
.code
main proc
headOfLoop:
mov eax,OFFSET input_str
add eax,index_into_input_str
cmp BYTE PTR [eax],0
je writeSillyStr
push OFFSET input_str
push OFFSET word_to_convert
push OFFSET index_into_input_str
;-----------------------------------------------------------------------------------------
; 1. remove any space characters at beginning of current input_str
; 2. copy first word of current input_str to word_to_convert stopping at end of string
; or first space character. If all that is left in input_str prior to
; calling removeChars are spaces and termination character or just termination character
; then word_to_convert pointer will point at termination character at end of removeChars
;-----------------------------------------------------------------------------------------
call removeChars
add ebp,12
;-----------------------------------------------------------------------------------------
; make word "silly" by:
; 1. putting first character of word_to_convert on end of word
; 2. adding ay to end of word
;
; first character of word_to_convert is NOT erased, it is just ignored by using
; converted_word hereafter
;-----------------------------------------------------------------------------------------
call createSillyStr ; <<<<<<<<<<< CALL TO createSillyStr and clean up GOES HERE >>>>>>>>>>>>>>
;------------------------------------------------------------------------------------------
; add converted_word to the end of the output string. converted_word already has first
; character of word_to_convert removed. if word_to_convert was empty, then
; converted_word will also be empty.
;------------------------------------------------------------------------------------------
call addConvertedWord ; <<<<<<<<<<<< CALL TO addConvertedWord and clean up GOES HERE >>>>>>>>>>>>
jmp headOfLoop
writeSillyStr:
mov edx,OFFSET output_str
call WriteString
invoke ExitProcess,0
main endp
removeChars PROC
push ebp
mov ebp, esp
push esi
push edi
push eax
push edx
push ecx
mov edx,[ebp + 8]
mov edi,[ebp + 12]
mov esi,[ebp + 16]
mov ecx,[edx]
add esi,[edx]
headOfEraseBlanks:
cmp BYTE PTR [esi],0
je exitProc
cmp BYTE PTR [esi],' '
jne deleteAndInsert2
inc esi
inc ecx
jmp headOfEraseBlanks
deleteAndInsert1:
cmp BYTE PTR [esi],0
je exitProc
cmp BYTE PTR [esi],' '
je exitProc
deleteAndInsert2:
mov al,BYTE PTR [esi]
mov BYTE PTR [edi],al
inc esi
inc edi
inc ecx
jmp deleteAndInsert1
exitProc:
mov BYTE PTR [edi],0
mov [edx],ecx
pop ecx
pop edx
pop eax
pop edi
pop esi
pop ebp
ret
removeChars ENDP
createSillyStr PROC; <<<<<<<<<<<<< CODE FOR createSillyStr GOES HERE >>>>>>>>>>>>>>>>>>>
createSillyStr ENDP
addConvertedWord PROC; <<<<<<<<<<<<< CODE FOR addConvertedWord GOES HERE >>>>>>>>>>>>>>>>>
addConvertedWord ENDP
end main
Explanation / Answer
data
input_str BYTE "This sentence will be converted to silly string ",0
output_str BYTE 100 DUP(0),0
word_to_convert BYTE ?
converted_word BYTE 103 DUP(?),0
index_into_input_str DWORD 0
.code
main proc
headOfLoop:
mov eax,OFFSET input_str
add eax,index_into_input_str
cmp BYTE PTR [eax],0
je writeSillyStr
push OFFSET input_str
push OFFSET word_to_convert
push OFFSET index_into_input_str
;-----------------------------------------------------------------------------------------
; 1. remove any space characters at beginning of current input_str
; 2. copy first word of current input_str to word_to_convert stopping at end of string
; or first space character. If all that is left in input_str prior to
; calling removeChars are spaces and termination character or just termination character
; then word_to_convert pointer will point at termination character at end of removeChars
;-----------------------------------------------------------------------------------------
call removeChars
add ebp,12
call addConvertedWord ; CALL TO addConvertedWord and clean up GOES HERE
jmp headOfLoop
writeSillyStr:
mov edx,OFFSET output_str
call WriteString
invoke ExitProcess,0
main endp
removeChars PROC
push ebp
mov ebp, esp
push esi
push edi
push eax
push edx
push ecx
mov edx,[ebp + 8]
mov edi,[ebp + 12]
mov esi,[ebp + 16]
mov ecx,[edx]
add esi,[edx]
headOfEraseBlanks:
cmp BYTE PTR [esi],0
je exitProc
cmp BYTE PTR [esi],' '
jne deleteAndInsert2
inc esi
inc ecx
jmp headOfEraseBlanks
deleteAndInsert1:
cmp BYTE PTR [esi],0
je exitProc
cmp BYTE PTR [esi],' '
je exitProc
deleteAndInsert2:
mov al,BYTE PTR [esi]
mov BYTE PTR [edi],al
inc esi
inc edi
inc ecx
jmp deleteAndInsert1
exitProc:
mov BYTE PTR [edi],0
mov [edx],ecx
pop ecx
pop edx
pop eax
pop edi
pop esi
pop ebp
ret
removeChars ENDP
createSillyStr PROC;
createSillyStr ENDP
addConvertedWord ENDP
end main