BASM = Borland/Codegear/Embarcadero's Built-In Assembler, the Delphi inline assembler
Questions tagged [basm]
50 questions
6
votes
0 answers
FPC BASM32 POP bug?
Another discrepancy between Delphi and FPC BASM:
program PopTest;
{$IFDEF FPC}
{$mode delphi}
{$asmmode intel}
{$ELSE}
{$APPTYPE CONSOLE}
{$ENDIF}
var
B: LongWord;
procedure Pop(A: LongWord; var B: LongWord);
asm
PUSH EAX
…

kludg
- 27,213
- 5
- 67
- 118
6
votes
1 answer
How can I obtain the address of internal System.pas functions?
I'm working on a JIT compiler, and trying to figure out how to output proper cleanup blocks for managed types such as strings.
The disassembly of the cleanup block for a function that has one local variable of type string looks like this:
0044333C…

Mason Wheeler
- 82,511
- 50
- 270
- 477
6
votes
2 answers
Assembly calls to System unit functions on FreePascal x64
I have some Delphi/assembly code that compiles and works fine (XE2) for Win32, Win64, and OSX 32. However, since I need it to work on Linux, I have been looking at compiling FPC versions of it (so far, Win32/64, Linux32/64).
By and large, it works…

PhiS
- 4,540
- 25
- 35
6
votes
3 answers
Porting Assembler x86 CPU ID code to AMD64
I have a problem. I have following x86 delphi code which is written in ASM. I need to port this to AMD64?
type
TCPUID = array[1..4] of Longint;
function GetCID : TCPUID; assembler; register;
asm
push ebx
push edi
mov edi, eax
mov …

Maxim
- 1,209
- 15
- 28
5
votes
1 answer
Delphi + Assembly array access
I am having a problem to access an element of an array in assembly(delphi).
The code is:
procedure TMaskBit.AllocBuffer;
begin
SetLength(DataIn, 6); //array of integer
DataIn[0] := 1 ;
DataIn[1] := 2 ;
DataIn[2] := 3 ;
…

p.magalhaes
- 7,595
- 10
- 53
- 108
5
votes
3 answers
Broadcast a byte value to all 16 XMM slots in Delphi ASM
This is easy in AVX with the VBROADCASTS command, or in SSE if the value were doubles or floats.
How do I broadcast a single 8-bit value to every slot in an XMM register in Delphi ASM?

IamIC
- 17,747
- 20
- 91
- 154
5
votes
2 answers
Delphi label and asm weirdness?
I written an asm function in Delphi 7 but it transforms my code to something else:
function f(x: Cardinal): Cardinal; register;
label err;
asm
not eax
mov edx,eax
shr edx, 1
and eax, edx
bsf ecx, eax
jz err
mov eax, 1
shl eax, cl
…

Egon
- 1,705
- 18
- 32
5
votes
3 answers
FLD instruction x64 bit
I have a little problem with FLD instruction in x64 bit ...
want to load Double value to the stack pointer FPU in st0 register, but it seem to be impossible.
In Delphi x32, I can use this code :
function DoSomething(X:Double):Double;
asm
FLD …

SMP3
- 71
- 1
- 6
5
votes
3 answers
How do I get the machine code of an assembly instruction known at compile time?
I want to be able to convert a single line of ASM into shellcode. I.E:
CALL EBX
How do I go about doing this, and also being able to properly convert this shellcode so that I can store it in a variable in a delphi application. I.E:
var…

Josh Line
- 625
- 3
- 13
- 27
5
votes
1 answer
POPCNT in Delphi XE/ XE2 64bit
How do I implement a count of 1-bits within a 16/32/64bit word using the very fast Intel POPCNT instruction, under Delphi XE or XE2? Is there a library routine giving direct access to this instruction? Can someone write a demo asm section…

user1423467
- 51
- 2
5
votes
2 answers
Delphi/ASM code incompatible with 64bit?
I have some sample source code for OpenGL, I wanted to compile a 64bit version (using Delphi XE2) but there's some ASM code which fails to compile, and I know nothing about ASM. Here's the code below, and I put the two error messages on the lines…

Jerry Dodge
- 26,858
- 31
- 155
- 327
5
votes
2 answers
Create class instance using Delphi inline assembler
What I would like to do is, using assembly, create a class instance, call one of it's methods and then free the instance.
I know I'm missing something very important and probably very simple, but I don't know what.
program Project2;
{$APPTYPE…
user497849
4
votes
2 answers
ASM/Delphi - Divide
I am trying to divide two numbers 50 and 5.
This is my code:
function Divide(Num1, Num2: Integer): Integer;
asm
MOV EAX, Num1
CDQ
MOV ECX, Num2
IDIV ECX
MOV @RESULT, ECX
end;
It gives me a DivisionByZeroException exception in…

nexno
- 429
- 8
- 26
4
votes
2 answers
Delphi Assembler/RTTI-gurus: Can I obtain the memory address and type info of the implied Result variable in a function?
Consider this typical code for method tracing (simplified for illustration):
type
IMethodTracer = interface
end;
TMethodTracer = class(TInterfacedObject, IMethodTracer)
private
FName: String;
FResultAddr: Pointer;
FResultType:…

Oliver Giesen
- 9,129
- 6
- 46
- 82
4
votes
1 answer
Delphi assembly calls
I'v been playing with some Delphi assemblies in IDA.
And I noticed a lot of system calls that I do not understand, and was unable finding any documentation about them.
For example: I noticed a lot of calls to the the unknown function LStrClr(void…

Michael
- 796
- 11
- 27