Answer To: 1-) Please submit the solution of your final as Ms-word or PDF document 2-) Using Visual Studio...
Gaurav answered on Apr 13 2021
question 4.docx
1. Source Code:
.data
string byte "this is test string", 0
array dword 256 dup (0)
fmt byte "0x%02X %02d %02d %02d %02d %02d %02d %02d %02d %02d %02d %02d %02d %02d %02d %02d %02d", 10, 0
return byte 10, "Press Any Key to Exit . . .", 10, 0
.code
main PROC
push OFFSET array ; address of the table
push OFFSET string ; address of the string
call Get_frequencies ; call the procedure
mov ecx, 16 ; print the table in 16 x 16 word
mov eax, 0 ; starting index
print:
push eax
push ecx
push array[eax + 60]
push array[eax + 56]
push array[eax + 52]
push array[eax + 48]
push array[eax + 44]
push array[eax + 40]
push array[eax + 36]
push array[eax + 32]
push array[eax + 28]
push array[eax + 24]
push array[eax + 20]
push array[eax + 16]
push array[eax + 12]
push array[eax + 8]
push array[eax + 4]
push array[eax + 0] ; 16 double words
shr eax, 2
push eax
push OFFSET fmt ; format
call printf ; print
add esp, 72
pop ecx
pop eax
add eax, 64 ; increment the index by 16 dwords
loop print ; print all the 16 lines
push OFFSET return
call printf ; wait for the user to close the program
call _getch
push 0
call exit ; close the program
main ENDP
; Function that generates the character frequency table in a given array
; Input prameter - address of the string
; - address of the table
; return none
Get_frequencies PROC
push ebp
mov ebp, esp
push esi
push edi ; save the registers
mov esi, [ebp + 8] ; address of the string
mov edi, [ebp + 12] ; address of the table
mov eax, 0
lp:
mov al, [esi] ; load each byte
cmp al, 0 ; check if null character is reached i.e. end of the string
je done ; exit the loop if the null character is reached
inc DWORD PTR [edi + eax * 4] ; increment the particular character value
add esi, 1 ; increment the address pointer
jmp lp ; loop till the end
done:
pop edi
pop esi
mov esp, ebp
pop ebp ; restore the registers
ret ; return from the subroutine
Get_frequencies ENDP
END
2. Output:
question 3.docx
1. Source Code:
.data
string byte 128 dup(0)
prompt byte "Enter any string : ", 0
vowel dword 5 dup (0)
op_1 byte 10, "Total Number of Vowels in the String : %d", 10, 0
op_2 byte 10, 9, "A : %d", 10, 9, "E : %d", 10, 9, "I : %d", 10, 9, "O : %d", 10, 9, "U : %d", 10, 0
return byte 10, "Press Any Key to Exit . . .", 10, 0
.code
main PROC
push OFFSET prompt ; prompt the user to enter a string
call printf
add esp, 4
push OFFSET string ; read the input from the stdin
call gets
add esp, 4
mov eax, OFFSET string ; address of the string
lp:
mov bl, [eax] ; load each byte
cmp bl, 0 ; check if end of the string is reached
je done ; if reached exit the loop
add eax, 1 ; increment the address pointer
cmp bl, 'a' ; compare if it 'a'
je A ; if it is 'a' then jump to the A counter
cmp bl, 'A' ; compare if it 'A'
je A ; if it is 'A' then jump to the A counter
cmp bl, 'e' ; compare if it 'e'
je E ; if it is 'e' then jump to the E counter
cmp bl, 'E' ; compare if it 'E'
je E ; if it is 'E' then jump to the E counter
cmp bl, 'i' ; compare if it 'i'
je I ; if it is 'i' then jump to the I counter
cmp bl, 'I' ; compare if it 'I'
je I ; if it is 'I' then jump to the I counter
cmp bl, 'o' ; compare if it 'o'
je O ; if it is 'o' then jump to the O counter
cmp bl, 'O' ; compare if it 'O'
je O ; if it is 'O' then jump to the O counter
cmp bl, 'u' ; compare if it 'u'
je U ; if it is 'u' then jump to the U counter
cmp bl, 'U' ; compare if it 'U'
je U ; if it is 'U' then jump to the U counter
jmp lp ; loop
A:
add 0[vowel], 1 ; increment the counter of 'a'
jmp lp ; loop
E:
add 4[vowel], 1 ; increment the counter of 'e'
jmp lp ; loop
I:
add 8[vowel], 1 ; increment the counter of 'i'
jmp lp ; loop
O:
add 12[vowel], 1 ; increment the counter of 'o'
jmp lp ; loop
U:
add 16[vowel], 1 ; increment the counter of 'u'
jmp lp ; loop
done:
mov eax, 0[vowel]
add eax, 4[vowel]
add eax, 8[vowel]
add eax, 12[vowel]
add eax, 16[vowel] ; add all the counter value for a, e, i, o, u
push eax
push OFFSET op_1
call printf ; print the total number of vowels in the string
add esp, 8
push 16[vowel]
push 12[vowel]
push 8[vowel]
push 4[vowel]
push 0[vowel]
push OFFSET op_2
call printf ; print number of each vowel in the string
add esp, 24
push OFFSET return
call printf
add esp, 4 ; wait for the user to close the program
call _getch
push 0
call exit ; close the program
main ENDP
END
2. Output:
3. Description:
The Program uses gets function to read the input string which should be greater than 127 bytes longs. Then each byte is compared against the vowels both in capital and smaller letters. If match was found then appropriate variable is increment. Count of each vowel letter is held in separate memory location. At the end total number of vowels are calculated and printed out along with the individual count.
question 2.docx
1. Source Code:
.data
array dword 6 dup(0)
fmt byte "%d %d %d %d %d %d", 0
prompt byte "Enter any 6 Numbers : ", 0
op_1 byte 10, "Largest entered number is : %d", 10, 0
op_2 byte 10, "Smallest entered number is: %d", 10, 0
op_3 byte 10, "Large to Small: %d %d %d %d %d %d", 10, 0
op_4 byte 10, "Small to Large: %d %d %d %d %d %d", 10, 0
return byte 10, "Press Any key to exit . . .", 0
.code
main PROC
push OFFSET prompt ; prompt the user to enter the number
call printf
add esp, 4
push OFFSET 20[array] ; address of the 6th number
push OFFSET 16[array] ; address of the 5th number
push OFFSET 12[array] ; address of the 4th number
push OFFSET 8[array] ; address of the 3rd number
push OFFSET 4[array] ; address of the 2nd number
push OFFSET 0[array] ; address of the 1st number
push OFFSET fmt ; format for the scanf statement
call scanf ; call the function
add esp, 28 ; clear the memory allocated in the previous push statement
mov ecx, 5 ; number of iteration i.e. last index of the array
outerLoop:
push ecx ; push the value
mov eax, ecx ; index of the current element
innerLoop:
add ecx, -1 ; index of the previous element from the current element
mov ebx, array[ecx * 4] ; get the value
cmp array[eax * 4], ebx ; compare it against the current element
jg skip ; skip if current element is greater else swap the element
mov edx, array[eax * 4] ; copy the current element
mov array[ecx * 4], edx ; swap the elements
mov array[eax * 4], ebx
skip:
cmp ecx, 0 ; exit the loop if the first index of the array is reached
jge innerLoop
pop ecx ; pop the iteration value
loop outerLoop ; loop till the end of the array
push 20[array] ; address of the largest element in the array
push OFFSET op_1
call printf ; print the largest element
add esp, 8
push 0[array] ; address of the smallest element in the array
push OFFSET op_2
call printf ; print the smallest element
add esp, 8
push 0[array]
push 4[array]
push 8[array]
push 12[array]
push 16[array]
push 20[array]
push OFFSET op_3
call printf ; print the element in descending order
add esp, 28
push 20[array]
push 16[array]
push 12[array]
push 8[array]
push 4[array]
push 0[array]
push OFFSET op_4
call printf ; print the element in ascending order
add esp, 28
push OFFSET return ; wait for the user to close the program
call printf
add esp, 4
call _getch
push 0
call exit ; exit the program
main ENDP
END
2. Output:
3. Description:
The program uses a scanf function to read the 6 numbers in an array. Then the array is sorted out. Sorting taking a single element from the index zero or last element, compare it against all other elements and swap if smaller or larger respectively. Then the index is incremented or decremented and compare it with rest of its element and loops till all the elements are compared with each other and swapped appropriately. Resulting array will a sorted array from lowest value to largest value. Print the lowest value, which is first element in the array, and largest value last element, then print from lowest to largest and largest to lowest value.
question 1.docx
1. Source Code
.data
array dword 5 dup(0)
prompt byte "Enter the Five Numbers : ", 0
op_1 byte 10, "Sum of the Entered Number : %d", 10, 0
op_2 byte 10, "Division of entered digit number 4 by entered digit number two : %d", 10, 0
fmt byte "%d %d %d %d %d", 0
return byte 10, "Press any to exit . . .", 0
.code
main PROC
push OFFSET prompt
call printf
add esp, 4
push OFFSET 16[array] ; address of the 5th number
push OFFSET 12[array] ; address of the 4th number
push OFFSET 8[array] ; address of the 3rd number
push OFFSET 4[array] ; address of the 2nd number
push OFFSET 0[array] ; address of the 1st number
push OFFSET fmt ; format for the scanf statement
call scanf ; call the function
add esp, 20 ; clear the memory allocated in the previous push statement
mov eax, 0[array] ; sum = 1st number
add eax, 4[array] ; sum += 2nd number
add eax, 8[array] ; sum += 3rd number
add eax, 12[array] ; sum += 4th number
add eax, 16[array] ; sum += 5th number
push eax ; push the sum
push OFFSET op_1 ; address of the string
call printf ; print the result
add esp, 8 ; clear the memory allocated in the previous push statement
mov eax, 12[array] ; x = 4th number
mov edx, 0 ; clear edx for division
idiv 4[array] ; x = x/2nd number
push eax ; push the x
push OFFSET op_2 ; address of the string
call printf ; print the result
add esp, 8 ; clear the memory allocated in the previous push statement
push OFFSET return ; wait for the user to press any key to exit the program
call printf
add esp, 4
call _getch
push 0
call exit
main ENDP
END
2. Output:
3. Description:
Using Scanf function 5 Numbers are read from the stdin, address of the variable to hold the numbers are send via scanf argument and once the function returns the values will be stored in the respective variables. Then each variable is added together and the results are written out to the stdout. An array of size 5 is used to hold the number so accessing the 4th and 2nd number is simplified to an index number of 4th and 2nd location. Then values from 4th and 2nd numbers are divided and result is printed out.
Question.zip
Question/question_1/.vs/question_1/v14/.suo
Question/question_1/Debug/question_1.exe
Question/question_1/Debug/question_1.ilk
Question/question_1/Debug/question_1.pdb
Question/question_1/question_1.sln
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "question_1", "question_1\question_1.vcxproj", "{9840628A-1962-48CA-BC04-50B9F5885149}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9840628A-1962-48CA-BC04-50B9F5885149}.Debug|x64.ActiveCfg = Debug|x64
{9840628A-1962-48CA-BC04-50B9F5885149}.Debug|x64.Build.0 = Debug|x64
{9840628A-1962-48CA-BC04-50B9F5885149}.Debug|x86.ActiveCfg = Debug|Win32
{9840628A-1962-48CA-BC04-50B9F5885149}.Debug|x86.Build.0 = Debug|Win32
{9840628A-1962-48CA-BC04-50B9F5885149}.Release|x64.ActiveCfg = Release|x64
{9840628A-1962-48CA-BC04-50B9F5885149}.Release|x64.Build.0 = Release|x64
{9840628A-1962-48CA-BC04-50B9F5885149}.Release|x86.ActiveCfg = Release|Win32
{9840628A-1962-48CA-BC04-50B9F5885149}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Question/question_1/question_1.VC.db
Question/question_1/question_1/Debug/main.obj
Question/question_1/question_1/Debug/question_1.log
Assembling main.asm...
question_1.vcxproj -> D:\Visual Studio Workspace\Question\question_1\Debug\question_1.exe
question_1.vcxproj -> D:\Visual Studio Workspace\Question\question_1\Debug\question_1.pdb (Full PDB)
Question/question_1/question_1/Debug/question_1.tlog/link.command.1.tlog
^D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\QUESTION_1\DEBUG\MAIN.OBJ
/OUT:"D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\QUESTION_1.EXE" /INCREMENTAL /NOLOGO LIBUCRT.LIB LEGACY_STDIO_DEFINITIONS.LIB LIBVCRUNTIME.LIB LIBCMT.LIB KERNEL32.LIB USER32.LIB GDI32.LIB WINSPOOL.LIB COMDLG32.LIB ADVAPI32.LIB SHELL32.LIB OLE32.LIB OLEAUT32.LIB UUID.LIB ODBC32.LIB ODBCCP32.LIB /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\QUESTION_1.PDB" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\QUESTION_1.LIB" /MACHINE:X86 DEBUG\MAIN.OBJ
^D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\MAIN.OBJ
/OUT:"D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\DEBUG\QUESTION_1.EXE" /INCREMENTAL /NOLOGO LIBUCRT.LIB LEGACY_STDIO_DEFINITIONS.LIB LIBVCRUNTIME.LIB LIBCMT.LIB KERNEL32.LIB USER32.LIB GDI32.LIB WINSPOOL.LIB COMDLG32.LIB ADVAPI32.LIB SHELL32.LIB OLE32.LIB OLEAUT32.LIB UUID.LIB ODBC32.LIB ODBCCP32.LIB /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\DEBUG\QUESTION_1.PDB" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\DEBUG\QUESTION_1.LIB" /MACHINE:X86 DEBUG\MAIN.OBJ
Question/question_1/question_1/Debug/question_1.tlog/link.read.1.tlog
^D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\QUESTION_1\DEBUG\MAIN.OBJ
C:\WINDOWS\GLOBALIZATION\SORTING\SORTDEFAULT.NLS
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\LIB\10.0.10240.0\UCRT\X86\LIBUCRT.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\LEGACY_STDIO_DEFINITIONS.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\LIBVCRUNTIME.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\LIBCMT.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\KERNEL32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\USER32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\GDI32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\WINSPOOL.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\COMDLG32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\ADVAPI32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\SHELL32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\OLE32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\OLEAUT32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\UUID.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\ODBC32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\ODBCCP32.LIB
D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\QUESTION_1\DEBUG\MAIN.OBJ
C:\WINDOWS\SYSTEM32\TZRES.DLL
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\LEGACY_STDIO_WIDE_SPECIFIERS.LIB
^D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\MAIN.OBJ
C:\WINDOWS\GLOBALIZATION\SORTING\SORTDEFAULT.NLS
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\LIB\10.0.10240.0\UCRT\X86\LIBUCRT.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\LEGACY_STDIO_DEFINITIONS.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\LIBVCRUNTIME.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\LIBCMT.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\KERNEL32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\USER32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\GDI32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\WINSPOOL.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\COMDLG32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\ADVAPI32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\SHELL32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\OLE32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\OLEAUT32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\UUID.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\ODBC32.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\LIB\WINV6.3\UM\X86\ODBCCP32.LIB
D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\MAIN.OBJ
C:\WINDOWS\SYSTEM32\TZRES.DLL
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\LEGACY_STDIO_WIDE_SPECIFIERS.LIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\8.1\BIN\X86\RC.EXE
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\BIN\CVTRES.EXE
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\VC\BIN\MSPDBSRV.EXE
C:\WINDOWS\SYSTEM32\RSAENH.DLL
Question/question_1/question_1/Debug/question_1.tlog/link.write.1.tlog
^D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\QUESTION_1\DEBUG\MAIN.OBJ
D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\QUESTION_1.ILK
D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\QUESTION_1.EXE
D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\QUESTION_1.PDB
^D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\QUESTION_1\DEBUG\MAIN.OBJ
D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\DEBUG\QUESTION_1.ILK
D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\DEBUG\QUESTION_1.EXE
D:\VISUAL STUDIO WORKSPACE\QUESTION\QUESTION_1\DEBUG\QUESTION_1.PDB
Question/question_1/question_1/Debug/question_1.tlog/question_1.lastbuildstate
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
Debug|Win32|D:\Visual Studio Workspace\Question\question_1\|
Question/question_1/question_1/Debug/question_1.tlog/question_1.write.1u.tlog
^main.asm
D:\Visual Studio Workspace\Question\question_1\question_1\question_1\Debug\main.obj
^main.asm
D:\Visual Studio Workspace\Question\question_1\question_1\question_1\Debug\main.obj
^main.asm
D:\Visual Studio Workspace\Question\question_1\question_1\question_1\Debug\main.obj
^main.asm
D:\Visual Studio Workspace\Question\question_1\question_1\question_1\Debug\main.obj
^main.asm
D:\Visual Studio Workspace\Question\question_1\question_1\question_1\Debug\main.obj
^main.asm
D:\Visual Studio...