No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s1:apl:lab:lab3
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:lab3 [2024/11/27 14:53] – [The aim of the exercise] ktokarz | en:edu:zmitac:s1:apl:lab:lab3 [2024/12/03 14:40] (current) – [Tasks to be done during laboratory] ktokarz | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| ===== The example code ===== | ===== The example code ===== | ||
| - | The following code is divided into two parts. The C++ part calls the functions in a dynamically linked library. One function, called | + | The following code is divided into two parts. The C++ part calls the functions in a dynamically linked library. DLL contains three different functions copying the content of the source string to three destination strings using different addressing modes. One function, called |
| - | C++ file | + | The strings are defined inside the DLL. |
| - | < | + | **C++ file** |
| + | |||
| + | < | ||
| #include < | #include < | ||
| #include < | #include < | ||
| Line 21: | Line 23: | ||
| std::cout << "Hello World!\n"; | std::cout << "Hello World!\n"; | ||
| dllHandle = LoadLibrary(TEXT(" | dllHandle = LoadLibrary(TEXT(" | ||
| - | | + | |
| + | MyProc Copy_base = (MyProc)GetProcAddress(dllHandle, | ||
| + | MyProc Copy_index = (MyProc)GetProcAddress(dllHandle, | ||
| + | MyProc Copy_disp = (MyProc)GetProcAddress(dllHandle, | ||
| - | | + | |
| - | | + | |
| - | + | | |
| - | | + | |
| - | printf(" | + | |
| - | printf(" | + | |
| } | } | ||
| </ | </ | ||
| - | Assembler dll file. | + | **Assembler dll file.** |
| < | < | ||
| - | ; | ||
| - | ; | ||
| - | ; | ||
| .data | .data | ||
| - | DataString | + | SourceDataString |
| + | DestinBaseString DB ' | ||
| + | DestinIndexString DB ' | ||
| + | DestinDisplString DB ' | ||
| .code | .code | ||
| - | ; | + | |
| - | ; Procedure to find the character in a string | + | ; |
| - | ; No input parameters, result is 1 if character found, 0 otherwise | + | ; This function uses base addressing mode |
| - | ; | + | ; |
| - | FindChar_1 | + | CopyString_base |
| - | PUSH RSI | + | PUSH RSI ; RSI, RDI are non-volatile registers |
| - | LEA RSI, DataString | + | PUSH RDI |
| - | | + | LEA RSI, SourceDataString |
| - | Check_End: | + | |
| - | CMP BYTE PTR [RSI], | + | MOV AL, 0FFH |
| - | JE Not_Find | + | Copy_Loop: |
| - | | + | CMP BYTE PTR [RSI], |
| - | | + | JE String_End |
| - | ADD RSI, 1 | + | |
| - | | + | |
| - | Got_Equal: | + | ADD RSI, 1 |
| - | MOV DL, [RSI] ; load found char into DL | + | |
| - | JMP Done | + | JMP Copy_Loop |
| - | Not_Find: | + | String_End: |
| - | | + | |
| POP RSI | POP RSI | ||
| - | RET ; return | + | RET |
| - | Done: | + | CopyString_base ENDP ; end of CopyString_base |
| - | MOV RAX,1 ; character found | + | |
| + | ; | ||
| + | ; This function uses base + index addressing mode | ||
| + | ; | ||
| + | CopyString_base_index PROC | ||
| + | PUSH RSI ; RSI, RDI are non-volatile registers | ||
| + | PUSH RDI | ||
| + | LEA RSI, SourceDataString | ||
| + | LEA RDI, DestinIndexString | ||
| + | MOV AL, 0FFH | ||
| + | XOR RCX, RCX ; | ||
| + | Copy_Loop: | ||
| + | CMP BYTE PTR [RSI+RCX], AL ; is it the end of a string (special | ||
| + | JE String_End | ||
| + | MOV AH, [RSI+RCX] | ||
| + | MOV [RDI+RCX], AH ; put it into destination string | ||
| + | ADD RCX, 1 ; increment index register | ||
| + | JMP Copy_Loop | ||
| + | String_End: | ||
| + | POP RDI | ||
| POP RSI | POP RSI | ||
| - | RET ; return form procedure | + | RET |
| - | FindChar_1 | + | CopyString_base_index |
| - | ; | ||
| - | ; | ||
| - | ; No input parameters, result is the time (number of processor ticks) | ||
| ; | ; | ||
| - | ReadTime_1 PROC | + | ; This function uses base addressing mode with displacement |
| - | | + | ;**************************************************************************** |
| - | MOV RCX,RAX | + | CopyString_base_disp PROC |
| - | CALL FindChar_1 | + | ; Calcucate |
| + | Address_difference EQU DestinDisplString - SourceDataString | ||
| - | | + | |
| - | | + | |
| + | MOV AL, 0FFH | ||
| + | Copy_Loop: | ||
| + | CMP BYTE PTR [RSI], AL ; is it the end of a string (special character FF)? | ||
| + | JE String_End | ||
| + | MOV AH, [RSI] | ||
| + | MOV [RSI+Address_difference], | ||
| + | ADD RSI, 1 ; increment index register | ||
| + | JMP Copy_Loop | ||
| + | String_End: | ||
| + | POP RSI | ||
| + | RET | ||
| + | CopyString_base_disp ENDP ; end of CopyString_base_disp | ||
| - | RET | + | ;**************************************************************************** |
| - | ReadTime_1 ENDP | + | |
| END | END | ||
| - | ; | ||
| - | End of the file | ||
| - | ; | ||
| </ | </ | ||
| + | *def file* | ||
| + | < | ||
| + | LIBRARY JaAsm | ||
| + | EXPORTS CopyString_base | ||
| + | EXPORTS CopyString_base_index | ||
| + | EXPORTS CopyString_base_disp | ||
| + | </ | ||
| ===== Tasks to be done during laboratory ===== | ===== Tasks to be done during laboratory ===== | ||
| - | - Compile the example code and observe its behaviour. Set the breakpoint at the beginning of the code and see how the contents of the registers change with every loop pass. | + | 1. Compile the example code and observe its behaviour. Set the breakpoint at the beginning of the code and see how the contents of the registers change with every loop pass.\\ |
| - | - Make the function more universal: define | + | 2. Observe |
| - | - Rewrite | + | 3. Write the version of the assembler function which copies the source to a destination string using chosen string instruction with repetition (use REP prefix). |
| - | - Compare execution time for scalar | + | ===== For the report ===== |
| + | 1. Put in the report a screenshot of the window | ||
| + | 2. Explain differences in addressing modes used in the functions. Explain what is the result | ||
| + | < | ||
| + | Address_difference EQU DestinDisplString | ||
| + | </ | ||
| + | 3. Include the code of your new function written in assembler WITH COMMENTS. Also, add a screenshot of the window with the results displayed | ||
| + | |||
en/edu/zmitac/s1/apl/lab/lab3.1732715633.txt.gz · Last modified: by ktokarz
