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:multiasm:papc:chapter_6_9 [2026/02/20 13:08] – [Dynamic memory management considerations] pczekalskien:multiasm:papc:chapter_6_9 [2026/05/13 09:06] (current) – [Programming in Assembler for Linux] ktokarz
Line 36: Line 36:
  
 <figure dynamicmemory> <figure dynamicmemory>
-{{:en:multiasm:papc:hll_and_assembler-dynamic_memory_allocation.drawio.png?600|}}+{{ :en:multiasm:papc:hll_and_assembler-dynamic_memory_allocation.drawio.png?600 | Dynamic Memory Allocation Model for Assembler Code Integration}}
 <caption>Dynamic Memory Allocation Model for Assembler Code Integration</caption> <caption>Dynamic Memory Allocation Model for Assembler Code Integration</caption>
 </figure> </figure>
Line 68: Line 68:
 Calling system functions, such as the system message box, requires understanding the arguments passed to them. As there is no direct assembler help, documentation of the Windows system API for C++ is helpful. Calling system functions, such as the system message box, requires understanding the arguments passed to them. As there is no direct assembler help, documentation of the Windows system API for C++ is helpful.
 Code below presents the necessary components of the assembler app to call system functions (library includes are configured on the project level): Code below presents the necessary components of the assembler app to call system functions (library includes are configured on the project level):
-<code adm>+<code asm>
 .data .data
 STD_INPUT_HANDLE = -10 STD_INPUT_HANDLE = -10
Line 132: Line 132:
 int main() int main()
 { {
- dllHandle = LoadLibrary(TEXT("AssemblerDll.dll")); +    dllHandle = LoadLibrary(TEXT("AssemblerDll.dll")); 
- if (!dllHandle) +    if (!dllHandle) 
-+    
- std::cerr << "Failed to load DLL library\n"; +        std::cerr << "Failed to load DLL library\n"; 
- return 1; +        return 1; 
-+    
- MyProc myAsmProcedure = (MyProc)GetProcAddress(dllHandle, "MyAsmProc"); +    MyProc myAsmProcedure = (MyProc)GetProcAddress(dllHandle, "MyAsmProc"); 
- if (!myAsmProcedure) +    if (!myAsmProcedure) 
-+    
- std::cerr << "Failed to find assembler procedure\n"; +        std::cerr << "Failed to find assembler procedure\n"; 
- FreeLibrary(dllHandle); +        FreeLibrary(dllHandle); 
- return 2; +        return 2; 
-+    
- std::cout << myAsmProcedure(); +    std::cout << myAsmProcedure(); 
- FreeLibrary(dllHandle); +    FreeLibrary(dllHandle); 
- return 0;+    return 0;
 } }
  
Line 247: Line 247:
 Assembler code exposes functions to the linker using the ''global'' directive. Without it, assembler functions remain "private" and cannot be called, so linking won't succeed if there is a reference to the function from the high-level language part of the code. The following code presents a dummy function that performs integer addition of two arguments. Directives "section" are optional in this example. Assembler code exposes functions to the linker using the ''global'' directive. Without it, assembler functions remain "private" and cannot be called, so linking won't succeed if there is a reference to the function from the high-level language part of the code. The following code presents a dummy function that performs integer addition of two arguments. Directives "section" are optional in this example.
  
-<code assembler asmfunc.asm>+<code asm asmfunc.asm>
 section .data section .data
 section .bss section .bss
Line 274: Line 274:
     std::cout << "Hello, Assembler!" << std::endl;     std::cout << "Hello, Assembler!" << std::endl;
     returnValue = addInAsm(a,b);     returnValue = addInAsm(a,b);
-    std::cout << "Sum of " << a << " and " << b << " is " << returnValue << std::endl;+    std::cout << "Sum of " << a << " and " << b << " is " << returnValue  
 +              << std::endl;
     return 0;     return 0;
 } }
 </code> </code>
en/multiasm/papc/chapter_6_9.1771585692.txt.gz · Last modified: by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0