User Tools

Site Tools


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.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:edu:zmitac:s1:apl:lab:lab2 [2024/11/25 11:57] – [Ustawienie trybu kompilacji] ktokarzen:edu:zmitac:s1:apl:lab:lab2 [2024/11/26 13:26] (current) – [Laboratory2] ktokarz
Line 1: Line 1:
-====== Lab 2: Configuration of the Visual Studio Community 2019 for dll libraries written in MASM. ======+====== Programming in Assembler Laboratory ====== 
 +===== Laboratory 2 ===== 
 +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 107: Line 109:
 {{ :pl:edu:zmitac:n1z:ja:x64_step7.jpg?800 |}} {{ :pl:edu:zmitac:n1z:ja:x64_step7.jpg?800 |}}
  
-==== 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".
  
 {{ :pl:edu:zmitac:n1z:ja:config_dll_step1.jpg?800 |}} {{ :pl:edu:zmitac:n1z:ja:config_dll_step1.jpg?800 |}}
Line 115: Line 117:
 {{ :pl:edu:zmitac:n1z:ja:config_dll_step2.jpg?800 |}} {{ :pl:edu:zmitac:n1z:ja:config_dll_step2.jpg?800 |}}
  
-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 "JaDll.def". Wpis potwierdzamy.+In the newly opened window, go to "Linker" -> "Input" and in the "Module definition file" field, enter the name of our file "*.def". In our case, "JaDll.def". Confirm the entry.
  
 {{ :pl:edu:zmitac:n1z:ja:config_dll_step3.jpg?800 |}} {{ :pl:edu:zmitac:n1z:ja:config_dll_step3.jpg?800 |}}
  
-Końcowym krokiem konfiguracji jest wyłączenie punktu wejścia do biblioteki. W tym celu w zakładce "Konsolidator" (Linker) przechodzimy do opcji "Zaawansowane" (Advanced) i w polu „Brak punktu wejścia” (No entry point) wybieramy opcję „Tak (/NOENTRY)”. Zapisujemy wprowadzone ustawienia i zamykamy okno.+The final step in the configuration is to disable the library entry point. To do this, go to the "Linker" tab and select "Advanced" and select "Yes (/NOENTRY)" in the "No entry point" field. Save the settings and close the window.
  
 {{ :pl:edu:zmitac:n1z:ja:config_dll_step4.jpg?800 |}} {{ :pl:edu:zmitac:n1z:ja:config_dll_step4.jpg?800 |}}
  
-<note tip>Biblioteka dll, w przeciwieństwie do programu głównego, nie ma punktu (adresu) startowego, który wykorzystuje system operacyjny do uruchomienia programu. Udostępnia jedynie zestaw funkcji dla innych programów.</note>+<note tip>A dll library, unlike a main program, does not have a starting point (address) that the operating system uses to start the program. It only provides a set of functions for other programs.</note>
  
-===== Wykorzystanie biblioteki dll napisanej w asemblerze ===== +===== Using a dll library written in assembler ===== 
-==== Biblioteka asemblerowa dll ==== +==== dll library written in assembler ==== 
-Biblioteka dll zawiera funkcje, które można użyć w innych programach. Pierwsza wersja naszej biblioteki będzie udostępniała jedną funkcję, zwracającą stałą wartość. Wartość tę następnie odczytamy w pliku C++. Przykładowa zawartość pliku asemblerowego (JaDll.asm) może wyglądać następująco.+ 
 +The dll library contains functions that can be used in other programs. The first version of our library will provide one function that returns a constant value. We will then read this value in a C++ file. An example of the assembly file (JaDll.asm) may look like this.
  
 <code> <code>
Line 138: Line 141:
 </code> </code>
  
-Z plikiem kodu programu nierozerwalnie związany jest plik definicji (JaDll.def). Plik taki musi zawierać nazwę biblioteki DLL jako agrument dyrektywy LIBRARY, oraz listę nazw funkcji dostępnych dla innych modułów poprzedzonych dyrektywą EXPORTS. Aby nasza funkcja MyProc była widziana przez program C++ musimy ją zadeklarować jako eksportowaną. Plik JaDll.def w naszym projekcie może wyglądać następująco.+The program code file is inextricably linked to the definition file (JaDll.def). Such a file must contain the name of the DLL library as an argument of the LIBRARY directive, and a list of function names available to other modules preceded by the EXPORTS directive. In order for our MyProc function to be seen by the C++ program, we must declare it as exported. The JaDll.def file in our project may look like this.
  
 <code> <code>
Line 145: Line 148:
 </code> </code>
  
-Często chcemy wykorzystać przekazane do funkcji parametry. Przypomnijmy, że w 64-bitowej konwencji wywołań pierwsze cztery parametry są umieszczane bezpośrednio w rejestrach procesora. Szczegóły są opisane w  [[pl:edu:zmitac:n1z:ja:lab1#powtorka_z_teoriifunkcje_i_ich_wywolywanie_z_poziomu_assemblera|instrukcji do pierwszego ćwiczenia]]. I tak, dwa parametry typu całkowitego są umieszczone w rejestrach RCX i RDX. Funkcja, któa zwraca sumę dwóch argmentów całkowitych wyglądałaby w następujący sposób.+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.
  
 <code> <code>
Line 157: Line 160:
 </code> </code>
  
-Argumenty typu zmiennoprzecinkowego należy przekazać przez rejestry XMM0 i XMM1, a wynik zwrócić przez XMM0. Oczywiście należy użyć instrukcji rozszerzeń MMX/SSE.+Floating point arguments should be passed through registers XMM0 and XMM1, and the result should be returned through XMM0. Of course, the MMX/SSE extension instructions should be used.
  
 <code> <code>
Line 167: Line 170:
 ... ...
 </code> </code>
-==== Odwołanie do biblioteki dll z programu C++ ====+==== Calling functions in dll from C++ program ====
  
-Aby program napisany w C++ mógł wykorzystać funkcję z biblioteki należy wykonać kilka kroków. +In order for a program written in C++ to use a function from a library, several steps must be performed. 
-  - 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ą LoadLibrary uzyskując jednocześnie jej uchwyt, +- Load the library using the LoadLibrary function while obtaining its handle, 
-  - Odczytać aktualny adres interesującej nas funkcji wywołując GetProcAddress, +- Read the current address of the function of interest to us by calling GetProcAddress, 
-  - 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:
  
 <code> <code>
Line 190: Line 193:
 </code> </code>
  
-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, rozmiar rejestrów XMM0, XMM1 to 64 bity. Odpowiada to wartości zmiennoprzecinkowej podwójnej precyzji, czyli w języku C++ typowi "double".+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 to a double-precision floating-point value, or in C++ to the type "double".
  
 <code> <code>
Line 199: Line 202:
 </code> </code>
  
-==== Zadanie do zrealizowania w ramach laboratorium ==== +==== Task to be completed in the laboratory ==== 
-Należy napisać bibliotekę DLL w asemblerze i program w C++ demonstrujący działanie tej biblioteki.\\ +You should write a DLL in assembler and a C++ program that demonstrates how the DLL works.\\ 
-**Biblioteka DLL** ma udostępniać funkcje wykonujące i zwracające wynik podstawowych obliczeń arytmetycznych (dodawanie, odejmowanie, mnożenie i dzielenie) na parach liczb przekazanych jako parametry ich wywołania. Funkcje powinny mieć wersję stało- i zmiennoprzecinkową (w sumie osiem funkcji).\\ +**The DLL** should provide functions that perform and return the result of basic arithmetic calculations (addition, subtraction, multiplication, and division) on pairs of numbers passed as parameters to their call. The functions should have fixed- and floating-point versions (eight functions in total).\\ 
-**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 - wartości do obliczeń mogą być umieszczone w kodzie programu.+**The C++ program** should call all functions, pass sample parameter values, and display the results on the screen. No input user interface is required - the values ​​for calculations can be placed in the program code. 
 + 
 +==== 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.1732532278.txt.gz · Last modified: by ktokarz