No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s1:apl:lab:lab2
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:s1:apl:lab:lab2 [2024/11/25 11:51] – [Ustawienie zależności w rozwiązaniu] ktokarz | en:edu:zmitac:s1:apl:lab:lab2 [2024/11/26 13:26] (current) – [Laboratory2] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| + | ===== Laboratory | ||
| + | Configuration of the Visual Studio Community 2019 for dll libraries written in MASM. | ||
| ===== Creating the project with dll library written in assembler ===== | ===== Creating the project with dll library written in assembler ===== | ||
| Line 5: | Line 7: | ||
| In the beginning, we can create a project in which the main program will be written in HLL (High-Level Language) like C++, and the library written in assembler will be linked dynamically (dll). | In the beginning, we can create a project in which the main program will be written in HLL (High-Level Language) like C++, and the library written in assembler will be linked dynamically (dll). | ||
| <note tip> | <note tip> | ||
| - | < | + | < |
| ==== Creating of the new project ==== | ==== Creating of the new project ==== | ||
| During this laboratory, we'll show how to create and use dll (dynamically linked library) written in assembler in that application written in C++ | During this laboratory, we'll show how to create and use dll (dynamically linked library) written in assembler in that application written in C++ | ||
| Line 53: | Line 55: | ||
| <note tip>Once this dependency is set, when you compile a project or program written in C++, the assembler file will also be recompiled automatically.</ | <note tip>Once this dependency is set, when you compile a project or program written in C++, the assembler file will also be recompiled automatically.</ | ||
| - | ==== Zamiana biblioteki z C++ na asemblerową | + | ==== Changing the type from a C++ library to an assembler one ==== |
| - | Najpierw należy usunąć automatycznie utworzone pliki projektu zgodnego z C++. W tym celu wystarczy zaznaczyć wskazane pliki nagłówkowe i źródłowe, a następnie prawy klawisz myszy i wybrać „Usuń” bądź też kliknąć | + | First, you need to remove the automatically created |
| {{ : | {{ : | ||
| - | Dla biblioteki konieczne jest dostosowanie kompilacji jako plik asemblerowy | + | For the library, it is necessary to customize the compilation as an MASM assembler file. To do this, right-click the library project and select "Build dependencies" from the list, then "Build customization". |
| {{ : | {{ : | ||
| Line 64: | Line 66: | ||
| {{ : | {{ : | ||
| - | W nowo otwartym oknie zaznaczamy „masm” i potwierdzamy nasz wybór „OK”. | + | In the newly opened window, select "masm" and confirm our selection with "OK". |
| {{ : | {{ : | ||
| - | Kolejnym krokiem jest dodanie do biblioteki plików źródłowego w asemblerze oraz pliku definicji. Aby to zrobić ponownie klikamy prawym przyciskiem myszy na bibliotekę | + | The next step is to add the source files in the assembler and the definition file to the library. To do this, right-click on the " |
| {{ : | {{ : | ||
| - | Czynność tę powtarzamy dwukrotnie wybierając za każdym razem "Narzędzie" | + | We repeat this operation twice, each time selecting |
| {{ : | {{ : | ||
| - | <note tip>Przy wykonaniu czynności zgodnie z podaną uprzednio kolejnością, z dużym prawdopodobieństwem krok przedstawiony na kolejnym rysunku nie będzie konieczny.</ | + | <note tip>If you perform the activities in the order given above, it is highly likely that the step shown in the next figure will not be necessary.</ |
| - | Aby kompilator wiedział, że stworzony plik asemblerowy jest skojarzony z MASM, należy wskazać jego typ. Krok ten jest niezbędny gdy wykorzystujemy plik źródłowy | + | In order for the compiler to know that the created assembler file is associated with MASM, its type must be indicated. This step is necessary when we use a C++ source file and only change its extension to *.asm. |
| {{ : | {{ : | ||
| - | ==== Ustawienie trybu kompilacji | + | ==== Setting the compilation mode ==== |
| - | Kompilacja powinna przebiegać w trybie | + | Compilation should be done in 64-bit mode (x64). To do this, set this mode in the solution options. Right-click on our solution and select "Properties". |
| - | Klikamy prawym przyciskiem myszy na nasze rozwiązanie i wybieramy „Właściwości” (Properties). | + | |
| {{ : | {{ : | ||
| Line 92: | Line 93: | ||
| {{ : | {{ : | ||
| - | W nowo otwartym oknie przechodzimy na zakładkę „Właściwości konfiguracji” -> „Konfiguracja” (Configuration properties -> Configuration) na następnie klikamy w „Menedżer konfiguracji” (Configuration manager). | + | In the newly opened window, go to the "Configuration properties" |
| {{ : | {{ : | ||
| - | W nowym oknie wskazujemy wszędzie | + | In the new window, we indicate the x64 platform |
| {{ : | {{ : | ||
| Line 104: | Line 105: | ||
| {{ : | {{ : | ||
| - | Po wszystkim upewniamy się raz jeszcze, że wszędzie wskazana platforma to x64 i zamykamy okno. | + | After that, we make sure once again that the platform indicated everywhere is x64 and close the window. The " |
| - | W głównym pasku menu Visual Studio powinna automatycznie ustawić się opcja " | + | |
| {{ : | {{ : | ||
| - | ==== Końcowa konfiguracja biblioteki asemblerowej | + | ==== Final setup of the assembly library |
| - | Przystępujemy do konfiguracji biblioteki. W tym celu klikamy prawym przycskiem myszy na bibliotece i wybieramy „Właściwości” (Properties). | + | We proceed to configure the library. To do this, right-click on the library and select "Properties". |
| {{ : | {{ : | ||
| Line 117: | Line 117: | ||
| {{ : | {{ : | ||
| - | W otwartym nowo oknie przechodzimy do „Konsolidator” -> „Dane wejściowe” (Linker -> Input) i w polu „Plik definicji modułu” (Module definition file) wpisujemy nazwę naszego pliku „*.def”. W naszym przypadku | + | In the newly opened window, go to "Linker" |
| {{ : | {{ : | ||
| - | Końcowym krokiem konfiguracji jest wyłączenie punktu wejścia | + | The final step in the configuration is to disable the library entry point. To do this, go to the "Linker" |
| {{ : | {{ : | ||
| - | <note tip>Biblioteka | + | <note tip>A dll library, unlike a main program, does not have a starting point (address) that the operating |
| - | ===== Wykorzystanie biblioteki | + | ===== Using a dll library written in assembler |
| - | ==== Biblioteka asemblerowa | + | ==== dll library written in assembler |
| - | Biblioteka | + | |
| + | The dll library contains functions that can be used in other programs. The first version of our library will provide one function that returns | ||
| < | < | ||
| Line 140: | Line 141: | ||
| </ | </ | ||
| - | Z plikiem kodu programu nierozerwalnie związany jest plik definicji | + | The program code file is inextricably linked to the definition file (JaDll.def). |
| < | < | ||
| Line 147: | Line 148: | ||
| </ | </ | ||
| - | Często chcemy wykorzystać przekazane do funkcji parametry. Przypomnijmy, | + | We often want to use the parameters passed to the function. Recall that in the 64-bit calling convention, the first four parameters are placed directly in the processor registers. The details were provided during lectures and are described in the instructions for the first lab exercise. Thus, two integer-type parameters are placed in the RCX and RDX registers. A function that returns the sum of two integer arguments would look like this. |
| < | < | ||
| Line 159: | Line 160: | ||
| </ | </ | ||
| - | Argumenty typu zmiennoprzecinkowego należy przekazać przez rejestry | + | Floating point arguments should be passed through registers |
| < | < | ||
| Line 169: | Line 170: | ||
| ... | ... | ||
| </ | </ | ||
| - | ==== Odwołanie do biblioteki | + | ==== Calling functions in dll from C++ program |
| - | Aby program | + | In order for a program |
| - | - Przygotować typ funkcji zgodny z jej późniejszym wywołaniem, | + | - Prepare the type of the function that is compatible with its later call, |
| - | - Załadować bibliotekę funkcją | + | - Load the library using the LoadLibrary |
| - | - Odczytać aktualny adres interesującej nas funkcji wywołując | + | - Read the current address of the function of interest to us by calling |
| - | - Użyć funkcji odwołując się do jej adresu. | + | - Use the function by referring to its address. |
| - | Przykładowy kod mógłby wyglądać tak: | + | The sample code could look like this: |
| < | < | ||
| Line 192: | Line 193: | ||
| </ | </ | ||
| - | Użycie funkcji z parametrami wymaga nieco zmodyfikowanych definicji typu. Należy także zwrócić uwagę na typ wartości zwracanej przez funkcję. Pamiętać należy, że w przypadku liczb zmiennoprzecinkowych, | + | Using a function with parameters requires slightly modified type definitions. You should also pay attention to the type of the value returned by the function. Remember that in the case of floating-point numbers, the size of the XMM0, XMM1 registers is 64 bits. This corresponds |
| < | < | ||
| Line 201: | Line 202: | ||
| </ | </ | ||
| - | ==== Zadanie do zrealizowania w ramach laboratorium | + | ==== Task to be completed in the laboratory |
| - | Należy napisać bibliotekę | + | You should write a DLL in assembler and a C++ program that demonstrates how the DLL works.\\ |
| - | **Biblioteka | + | **The DLL** should provide functions that perform and return the result of basic arithmetic calculations |
| - | **Program w C++** ma wywoływać wszystkie funkcje przekazując przykładowe wartości parametrów i wyświetlić wyniki na ekranie. Nie jest wymagany interfejs użytkownika | + | **The C++ program** should call all functions, pass sample parameter values, and display the results on the screen. No input user interface is required |
| + | |||
| + | ==== For the report ==== | ||
| + | Include the code of your C++ file and assembler source file WITH COMMENTS. Also, add a screenshot of the window with the results displayed. | ||
en/edu/zmitac/s1/apl/lab/lab2.1732531870.txt.gz · Last modified: by ktokarz
