Question

In: Computer Science

Assembly using x86 irvine (masm) Write a complete program that will input values for num1 ,num2,...

Assembly using x86 irvine (masm)

Write a complete program that will input values for num1 ,num2, and num3 and display the

value of the expression ( (num1 ^ 3) * num2 + 5 * ( num2 ^ 2) ) / num3.

assume that the user enters only numbers that are greater than zero and the calculation never exceed 4 bytes size.

Sample run:

num1 = 1

num2 = 2

num3 = 3

((num1 ^ 3) * num2 + 5 * ( num2 ^ 2)) / num3 = 7 R 1


Solutions

Expert Solution

_DATA SEGMENT

COMM ?OptionsStorage@?1??local_stdio_printf_options@@9@9:QWORD ; `_local_stdio_printf_options'::`2'::_OptionsStorage

COMM ?OptionsStorage@?1??local_stdio_scanf_options@@9@9:QWORD ; `_local_stdio_scanf_options'::`2'::_OptionsStorage

_DATA ENDS

_DATA SEGMENT

$SG8912 DB '%d', 00H

ORG $+1

$SG8913 DB '%d', 00H

ORG $+1

$SG8914 DB '%d', 00H

ORG $+1

$SG8915 DB '%d', 00H

_DATA ENDS

_num$ = -16 ; size = 4

_num3$ = -12 ; size = 4

_num1$ = -8 ; size = 4

_num2$ = -4 ; size = 4

_main PROC

push ebp

mov ebp, esp

sub esp, 16 ; 00000010H

lea eax, DWORD PTR _num1$[ebp]

push eax

push OFFSET $SG8912

call _scanf

add esp, 8

lea ecx, DWORD PTR _num2$[ebp]

push ecx

push OFFSET $SG8913

call _scanf

add esp, 8

lea edx, DWORD PTR _num3$[ebp]

push edx

push OFFSET $SG8914

call _scanf

add esp, 8

mov eax, DWORD PTR _num1$[ebp]

xor eax, 3

imul eax, DWORD PTR _num2$[ebp]

mov ecx, DWORD PTR _num2$[ebp]

xor ecx, 2

imul edx, ecx, 5

add eax, edx

cdq

idiv DWORD PTR _num3$[ebp]

mov DWORD PTR _num$[ebp], eax

mov eax, DWORD PTR _num$[ebp]

push eax

push OFFSET $SG8915

call _printf

add esp, 8

mov eax, 1

mov esp, ebp

pop ebp

ret 0

_main ENDP

___local_stdio_printf_options PROC ; COMDAT

push ebp

mov ebp, esp

mov eax, OFFSET ?OptionsStorage@?1??local_stdio_printf_options@@9@9 ; `_local_stdio_printf_options'::`2'::_OptionsStorage

pop ebp

ret 0

___local_stdio_printf_options ENDP

___local_stdio_scanf_options PROC ; COMDAT

push ebp

mov ebp, esp

mov eax, OFFSET ?OptionsStorage@?1??local_stdio_scanf_options@@9@9 ; `_local_stdio_scanf_options'::`2'::_OptionsStorage

pop ebp

ret 0

___local_stdio_scanf_options ENDP

__Stream$ = 8 ; size = 4

__Format$ = 12 ; size = 4

__Locale$ = 16 ; size = 4

__ArgList$ = 20 ; size = 4

__vfprintf_l PROC ; COMDAT

push ebp

mov ebp, esp

mov eax, DWORD PTR __ArgList$[ebp]

push eax

mov ecx, DWORD PTR __Locale$[ebp]

push ecx

mov edx, DWORD PTR __Format$[ebp]

push edx

mov eax, DWORD PTR __Stream$[ebp]

push eax

call ___local_stdio_printf_options

mov ecx, DWORD PTR [eax+4]

push ecx

mov edx, DWORD PTR [eax]

push edx

call ___stdio_common_vfprintf

add esp, 24 ; 00000018H

pop ebp

ret 0

__vfprintf_l ENDP

__Result$ = -8 ; size = 4

__ArgList$ = -4 ; size = 4

__Format$ = 8 ; size = 4

_printf PROC ; COMDAT

push ebp

mov ebp, esp

sub esp, 8

lea eax, DWORD PTR __Format$[ebp+4]

mov DWORD PTR __ArgList$[ebp], eax

mov ecx, DWORD PTR __ArgList$[ebp]

push ecx

push 0

mov edx, DWORD PTR __Format$[ebp]

push edx

push 1

call ___acrt_iob_func

add esp, 4

push eax

call __vfprintf_l

add esp, 16 ; 00000010H

mov DWORD PTR __Result$[ebp], eax

mov DWORD PTR __ArgList$[ebp], 0

mov eax, DWORD PTR __Result$[ebp]

mov esp, ebp

pop ebp

ret 0

_printf ENDP

__Stream$ = 8 ; size = 4

__Format$ = 12 ; size = 4

__Locale$ = 16 ; size = 4

__ArgList$ = 20 ; size = 4

__vfscanf_l PROC ; COMDAT

push ebp

mov ebp, esp

mov eax, DWORD PTR __ArgList$[ebp]

push eax

mov ecx, DWORD PTR __Locale$[ebp]

push ecx

mov edx, DWORD PTR __Format$[ebp]

push edx

mov eax, DWORD PTR __Stream$[ebp]

push eax

call ___local_stdio_scanf_options

mov ecx, DWORD PTR [eax+4]

push ecx

mov edx, DWORD PTR [eax]

push edx

call ___stdio_common_vfscanf

add esp, 24 ; 00000018H

pop ebp

ret 0

__vfscanf_l ENDP

__Result$ = -8 ; size = 4

__ArgList$ = -4 ; size = 4

__Format$ = 8 ; size = 4

_scanf PROC ; COMDAT

push ebp

mov ebp, esp

sub esp, 8

lea eax, DWORD PTR __Format$[ebp+4]

mov DWORD PTR __ArgList$[ebp], eax

mov ecx, DWORD PTR __ArgList$[ebp]

push ecx

push 0

mov edx, DWORD PTR __Format$[ebp]

push edx

push 0

call ___acrt_iob_func

add esp, 4

push eax

call __vfscanf_l

add esp, 16 ; 00000010H

mov DWORD PTR __Result$[ebp], eax

mov DWORD PTR __ArgList$[ebp], 0

mov eax, DWORD PTR __Result$[ebp]

mov esp, ebp

pop ebp

ret 0

_scanf ENDP


Related Solutions

Write an assembly program that lets the user to input only the word MASM and displays...
Write an assembly program that lets the user to input only the word MASM and displays invalid input for any other user inputs.
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a loop with indirect or indexed addressing to reverse the elements of an integer array in place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future. .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your...
Write an X86-series assembly language program that checks whether input string is palindrome or not. A...
Write an X86-series assembly language program that checks whether input string is palindrome or not. A palindrome is a word, number, phrase or any other sequence which reads the same backward as forward e.g. madam, racecar. Sample Execution: Please enter a String: redivider The string is a palindrome Another Sample Execution: Please enter a String: abracadabra The string is not a palindrome
Write an assembly language program to calculate score = (num1 + num2) /2 i.e input two...
Write an assembly language program to calculate score = (num1 + num2) /2 i.e input two numbers num 1 and num 2 and divide it by 2 to display score.Test your program for the Pep/9 computer.
X86 Assembly MASM Questions below ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the...
X86 Assembly MASM Questions below ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the APPROPRIATE places at the end ;;;;; of the file as indicated. ;;;;; Q2: Write the directive to bring in the IO library           ;;;;; Q3: Create a constant called DAYS_PER_WEEK and initialize it to 5 ;;;;;     Create a constant called WEEKS_PER_YEAR and initialize it to 49 ;;;;; Q4: Create a constant called DAYS_PER_YEAR by using DAYS_PER_WEEK and ;;;;;     WEEKS_PER_YEAR (of Q3) in an...
ASSEMBLY X86, using VISUAL STUDIOS 2019 Please follow ALL directions! Write a program that calculates and...
ASSEMBLY X86, using VISUAL STUDIOS 2019 Please follow ALL directions! Write a program that calculates and printout the first 6 Fibonacci numbers.   Fibonacci sequence is described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). (sequence 0 1 1 2 3 5 8 13 21 34 ...) Have your program print out "The first six numbers in the Fibonacci Sequence are". Then the numbers should be neatly printed out, with...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
Assembly Language for x86 processors You are to write a program which should first ask for...
Assembly Language for x86 processors You are to write a program which should first ask for 4 random numbers from 0-20 (user will inpute these numbers in no preset order). Input these 5 numbers in variables called num1, num2, num3, num4, and num5. When done, your program should sort these numbers (you will use lots of conditions to check order). num1 should contain smallest number while num5 should contain the biggest. display the contents of num1 through num5 on the...
Using x86 assembly language, create a flowchart and write an example of code that will sort...
Using x86 assembly language, create a flowchart and write an example of code that will sort 2 arrays of unsigned doubleword integers in ascending order and output the largest element in each array. Any sorting procedure can be used, but this procedure must be called twice for each array. The first time it is called, the first array should be sorted and the second time it is called, the second array must be sorted. As well as outputting which is...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT