i have the assembly for the max. can someone change the variables of it and make
ID: 3762272 • Letter: I
Question
i have the assembly for the max. can someone change the variables of it and make it min. I mean, the assembly for finding the min of the flaoting points. Please!!!
.686
.model flat
.code
_max PROC ;name of fucntion
start:
push ebp ; save caller frame pointer
mov ebp, esp ; establish current frame pointer
mov ebx, [ebp+8] ; store address of first array element into ebx
mov ecx, [ebp+12] ; store the size of array into ecx
xor edx, edx ; initialize loop counter edx to zero
fld dword ptr[ebx] ; load first array element arrary onto st(0)
inc edx ; increment loop counter in edx
loopMax:
fld dword ptr[ebx+edx*4] ; load next array element onto st(1)
fcom st(1) ; compare st(0) with st(1)
fstsw ax ; copy the Status Word containing the result to AX
fwait ; insure the previous instruction is completed
sahf ; transfer the condition codes to the CPU's flag register
ja lookNext ; if st(0) > st(1) jump to lookNext to continue with next array element
fcomp ; pop st(0) because new maximum is in st(1)
; after pop, the new max is again in st(0)
lookNext:
inc edx ; increment counter in edx
cmp ecx, edx ; compare array size in ecx with loop counter in edx
jg loopMax ; if ecx > edx then jump to loopMax
pop ebp ; restore caller frame pointer
ret ; return contents of st(0)
_max ENDP
end
Explanation / Answer
The source code of the subf2 function
Now, we will focus on the source code briefly. The
first two directives are described earlier. The function prolog is
implemented with the following assembly commands:
They initialize the EBP
register to the stack address to gain access to the variables.
Computation is done with the mathematical coprocessor’s commands, and
the result is returned at the top of the coprocessor stack ST (0):
The last two commands reset the stack and exit the function. Note that the ret command has no parameters according to the _cdecl convention.
Now you should obtain an object module of the main C++
.NET program and add it to the project. The object module can be
generated with either of two methods: with the stand-alone compiler of
the MASM 6.14 package or with the assembler of the Visual C++ .NET
environment.
Here is a description of each of these two variants.
As noted earlier, when you use the MASM 6.14
stand-alone compiler, you can obtain an object module with the
following command line
The max and min assembly functions
We will not dissect the source code of these functions
because you encountered similar examples earlier. Put the object code
of these functions to the minimax.lib library. To do this, execute the following commands:
Create a solution consisting of two projects. The first project should be a dynamic link library (name it USING_IMPDLL_STANDARD.dll). Modify the source code of the library template generated by the Application Wizard as shown in Listing 7.22.
Listing 7.22: The USING_IMPDLL_STANDARD dynamic link library
For everything to work well, the minimax.lib standard library should be among the project files. The references to this library’s functions are defined as follows:
In addition, the sub2f function should be declared as external with the dllexport
attribute. After you compile the project, you will obtain a DLL and an
import library. Link the DLL project to another project that will
demonstrate the use of the minimax.lib standard library and the DLL. The source code of this application is shown in Listing 7.23.
Listing 7.23: The source code of an application that uses assembly functions of a standard library and DLL
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.