FPC 3.2.2 - Assembler call Assembler Routine - with nostackframe - how to ? lazarus / 21-General ---------------------------------------------------------------------- paule32 · 2025-04-14 15:37 The given assembler function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function foo(var s: buf): longint; assembler; nostackframe;asm  how can I call a external "bar" function with the "buf" parameter to a similar: function, to "not" lose or overwrite the stack ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function bar(var s: buf): longint; assembler; nostackframe;asm ---------------------------------------------------------------------- Thaddy · 2025-04-14 16:31 How would you handle the stack allocation for s then? Manually? ---------------------------------------------------------------------- ALLIGATOR · 2025-04-14 17:01 Unfinished example for Windows x64. Maybe someone will complete and further develop the example Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program app;{$asmmode intel} type  buf = array [0..9] of dword; function bar(var s: buf): longint; assembler; nostackframe;asm  mov dword ptr [rcx], 33end; function foo(var s: buf): longint; assembler; nostackframe;asm  sub rsp, 8  mov [rsp], rcx   // ...  mov rcx, [rsp]  call bar  // ...   add rsp, 8end; var  b: buf; begin  b[0]:=7;  WriteLn(b[0]);  foo(b);  WriteLn(b[0]);  ReadLn;end. ---------------------------------------------------------------------- paule32 · 2025-04-14 17:07 I don't realy have much knowledge about Assembly. I only know x86 Assembly, when I would call a Routine, I have to "puish" the register in Stack-Reverse calling convention (C / C++) to give the Parameters for the calling Routine. But I don't thinking/know if the Stack is destroyed when I "push ebp  mov ebp, esp"... This is for x86. And I working in x64 Windows 11 Mode. There is a totally new concept of calling Routines, where I not firm in. And as I saw "nostackframe" I could simply do a "call bar" - but I am not in this knowledge. Because there is not only a "call bar" - I have to give a Parameter from one source to the next ... Please sorry for my English - it is bad, I know - but I don't know how to describe my Problem better... I will do my best to learn and proof it. ---------------------------------------------------------------------- paule32 · 2025-04-14 19:10 can I simply call "call bar" in foo ? so a call through ... ? ---------------------------------------------------------------------- H₂SO₄ · 2025-04-15 05:00 nostackframe  simply prevents the compiler from managing local variables for you (including "invisible" temporaries). If you try to declare local variables in a  nostackframe  procedure, you'll get an error. In older x86 (32-bit) calling conventions, all arguments were pushed onto the stack like you described, but that is no longer the case: all major modern calling conventions (x86-64) pass the first few parameters in registers (Windows uses  rcx, rdx, r8, r9  while Linux uses  rdi, rsi, rdx, rcx, r8, r9). This improves performance, but it also means that parameters must be manually stored somewhere in non- leaf functions (aka functions that call other functions, like your example). @ALLIGATOR's response is what you need to do - manually allocate & deallocate stack space by moving the stack pointer (if you decide to add more parameters you must pay attention to stack alignment, though). ---------------------------------------------------------------------- Thaddy · 2025-04-15 05:45 Yes that example, while unfinished is good. You are right about alignment when setting up de stack manually as in the second function.