Forum > General
Call SetLength from assembler block
LemonParty:
Let's say we have a function:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TPointers = array of Pointer;function F1: TPointers; assembler;asm {how to set the size of Result here?}end;
runewalsh:
Rule of thumb: if you don’t know how to do that, don’t use assembler — you won’t do anything useful with it anyway.
Write a helper function that calls SetLength, and call it with call.
LemonParty:
I test with this program (Windows):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TPointers = array of Pointer; function SetLen(Arr: TPointers; Len: SizeInt): TPointers;begin SetLength(Arr, Len); Result:= Arr;end; function F1: TPointers;assembler;{ nostackframe; }asm mov rcx,0 mov rdx,5 call SetLenend; var Arr: TPointers;begin Arr:= F1; Writeln(Length(Arr));end. SIGSEGV occurs after call SetLen line. What I missing?
runewalsh:
Implement your F1 function in Pascal, set a breakpoint inside it, run it, and look at the disassembly (Ctrl-Alt-D in Lazarus).
LemonParty:
That is a correct instructions:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function F1: TPointers;assembler;nostackframe;asm mov r8d,5 xor edx,edx call SetLenend;But I do not uderstand why r8 and rdx. rdx is the second argument in calling convention and r8 is the third one (rcx is the first one). Somewhy the first argument is omitted.
Navigation
[0] Message Index
[#] Next page