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:33] – [Ćwiczenie 2: Instalacja środowiska Visual Studio Community 2019 i konfiguracja do tworzenia bibliotek dll napisanych w MASM.] ktokarz | en:edu:zmitac:s1:apl:lab:lab2 [2024/11/26 13:26] (current) – [Laboratory2] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | ===== Instalacja | + | ===== Laboratory 2 ===== |
| + | Configuration of the Visual Studio Community 2019 for dll libraries written in MASM. | ||
| - | Rozpoczynamy od ściągnięcia instalatora ze strony [[https:// | + | ===== Creating the project with dll library written in assembler ===== |
| - | {{ : | + | In the beginning, we can create a project in which the main program |
| - | + | <note tip>Creation of libraries written in assembly language, with functions called from the application written in a chosen high-level language is currently the most common assembler use.</ | |
| - | Po uruchomieniu instalatora wybieramy opcje .NET desktop development oraz Desktop development with C++ i rozpoczynamy instalację. | + | < |
| - | + | ==== 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++ |
| - | + | We start by creating a new C++ project. | |
| - | Instalacja przebiegnie automatycznie. | + | |
| - | + | ||
| - | {{ : | + | |
| - | + | ||
| - | Po zainstalowaniu, przy pierwszym uruchomieniu środowiska, | + | |
| - | + | ||
| - | {{ : | + | |
| - | + | ||
| - | ===== Utworzenie projektu z asemblerową biblioteką DLL ===== | + | |
| - | + | ||
| - | Po zainstalowaniu możemy utworzyć projekt, w którym główny | + | |
| - | <note tip>Tworzenie bibliotek w asemblerze, wywoływanych z programów stworzonych w wybranym języku wysokiego poziomu (HLL) jest obecnie najczęstszym wykorzystaniem języka asemblerowego.</ | + | |
| - | < | + | |
| - | ==== Utworzenie nowego projektu | + | |
| - | W tym ćwiczeniu zajmiemy się dołączeniem biblioteki | + | |
| - | Konfigurację rozpoczynamy od utworzenia nowego projektu w języku | + | |
| {{ : | {{ : | ||
| - | Utworzymy aplikację konsolową, napisaną w języku | + | We'll create the console application, written in C++, for execution in the Windows |
| {{ : | {{ : | ||
| - | Aby utworzyć projekt należy go nazwać. Dla tego projektu proponujemy nazwę | + | We need to define that name for the project. We suggest the name " |
| {{ : | {{ : | ||
| - | <note tip>Na tym etapie zostanie utworzone rozwiązanie zawierające projekt z szablonem programu | + | <note tip>At this stage the solution will be created including the project with the C++ program template.</ |
| - | ==== Dodanie do rozwiązania części asemblerowej | + | ==== Adding the assembly part to the solution |
| - | Aby w naszym rozwiązaniu dodać bibliotekę napisaną w asemblerze, dodajemy do solucji nowy projekt. Klikając prawym klawiszem myszy na rozwiązaniu wybieramy dodaj (add) nowy projekt (new project). | + | To add a library written in assembler to our solution, we add a new project to the solution. Right-click on the solution and select |
| {{ : | {{ : | ||
| Line 47: | Line 32: | ||
| {{ : | {{ : | ||
| - | Nasz nowy projekt asemblerowy tworzymy jako projekt biblioteki (library) zgodny z C++, pracujący pod kontrolą systemu operacyjnego | + | We create our new assembler project as a C++ compatible library project, running under the Windows |
| {{ : | {{ : | ||
| - | Nazywamy pojekt np. " | + | We name the project e.g. " |
| {{ : | {{ : | ||
| - | <note tip>Obie części naszego rozwiązania będą umieszczone jako podfoldery w jednym folderze o nazwie zgodniej z nazwą rozwiązania, w naszym przypadku | + | <note tip>Both parts of our solution will be placed as subfolders in one folder named according to the name of the solution, in our case " |
| - | ==== Ustawienie zależności w rozwiązaniu | + | ==== Setting dependencies in the solution |
| - | Następnym krokiem jest ustawienie zależności projektu w taki sposób, aby kompilacja aplikacji konsolowej w C++ wymuszała automatycznie kompilację biblioteki asemblerowej. W tym celu należy kliknąć prawym klawiszem myszy na projekt konsolowy | + | The next step is to set up the project dependencies so that compiling the C++ console application automatically forces the assembly library to be compiled. To do this, right-click on the C++ console project, select the "Build dependencies" menu, and then select "Project dependencies". |
| {{ : | {{ : | ||
| Line 64: | Line 49: | ||
| {{ : | {{ : | ||
| - | W nowo otwartym oknie zaznaczamy naszą bibliotekę | + | In the newly opened window, select our " |
| {{ : | {{ : | ||
| - | <note tip>Po ustawieniu tej zależności, przy kompialcji projektu lub programu napisanego w C++ automatycznie zostanie także przekompilowany plik asemblerowy.</ | + | <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 81: | 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 109: | 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 121: | 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 134: | 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 157: | 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 164: | 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 176: | Line 160: | ||
| </ | </ | ||
| - | Argumenty typu zmiennoprzecinkowego należy przekazać przez rejestry | + | Floating point arguments should be passed through registers |
| < | < | ||
| Line 186: | 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 209: | 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 218: | 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.1732530826.txt.gz · Last modified: by ktokarz
