raised exception class EAccessViolation with message
'Access violation at address 0044d38c in module
'SHAPE.EXE' Read of address FFFFFFFF'. Process stoped.
I am using Delphi 4.0 Standard. Thanks from Michael Pell
function UpperCase(TestString: String): String;
begin
asm
PUSH DS
CLD
LDS SI,TestString
LES DI,@Result
LODSB
STOSB
XOR AX,AX
XCHG AX,CX
JCXZ @3
@1:
LODSB
CMP AL,'a'
JB @2
CMP AL,'z'
JA @2
SUB AL,20h
@2:
STOSB
LOOP @1
@3:
POP DS
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
var
TestString : String;
begin
TestString := 'a';
Edit2.Text := UpperCase(TestString);
end;
But if you still want to do it here a few hints, opcode like stosb,lodsb use
the 32 bits version of si and di meaning esi, edi. Also, segment registers
are fixed and are normally never changed inside a process, there's no need
since offsets are 32 bits and allow access to 4GB of flat memory space.
Also, string under delphi are dynamically allocated and reference counted
object, so what you're doing in this method won't work with them, you will
have to use shortstring if you want to do it like you were in turbo pascal.
Here how the code would look like for shortstring:
function UpperCase (const TestString: ShortString): ShortString; assembler;
asm
cld
push esi // Delphi doc say that esi,edi,ebp,esp must be preserved
push edi
mov esi,eax // TestString ptr is passed in edx
mov edi,edx // Result ptr is passed in eax
xor eax,eax
lodsb
stosb
mov ecx,eax
jcxz @3
@1:
lodsb
cmp al,'a'
jb @2
cmp al,'z'
ja @2
sub al,20h
@2:
stosb
loop @1
@3:
pop edi
pop esi
end;
procedure TForm2.Button1Click(Sender: TObject);
var
TestString : shortString;
begin
TestString := 'a';
Edit2.Text := UpperCase(TestString);
end;
But it's not efficient since Edit2.text expect a string not a shortstring
(delphi compiler will generate code to create a string from a shortstring
automatically) You can see the code generated if you put a breakpoint and
press ctrl-alt-c if you want and trace the code from there.
I agree for VB I don't touch that shit, and you're right, delphi/pascal is
more user friendly then C/C++ and have some functionality that I would like
to have in C++ (imo C need another update, C++ is getting old, they should
take note of java), but object pascal also lack a lot of features that C++
have, imo borland is pretty cheap when it come the time to enhance it's OP
compiler. But even with all it's limitations and probrems I'm not aware of
anything that's nicer then delphi. (It's a little bit sad :(
For an assembler, well few peoples code in assembly these days, the market
for it is so small that I doubt any big software company would take the risk
to invest time and money it would take to create one. But the inline
assembler in delphi is useful.
> While I'm sure this is possible with Delphi's string routines
> It seems like it might be easier in assembler using scans and
> stos
Not sure if it's gonna be easier. But feel free to have fun with it :)
. The thought of 32 bit assembler and no messing with
> segments is also very exciting -to me anyway-.
:)
> Thanks again for the help.
No problem.
> I think USENET is the most exciting thing to come to
> computing since the GUI. Sincerely, Michael Pell
Hum, it's useful, but imo it's not very good, most news server keep messages
and thread only for short period of time and there's not that many peoples
in it. Messages board can be better sometime, but good ones are rare. Let
say that the internet is good, but a little bit of order would be nice (I'm
a dreamer :)
Have fun with delphi :)
.386 Asm which is what Delphi32 supports is a damn sight easier than
.286 Asm - as one does not have to worry about segments.
However since the .486 certain simple instructions run significantly
faster than the more complex ones like REP MOVSB
This means that 'Noddy' assembler is far more efficient than hand
crafted ASM - and Delphi's optimizing Assembler knows all about this,
so in many cases it is hard to beat pure Delphi code.
Sadly it means that inline ASM is only really useful for operations
that 'de-obfuscate' code
Go to groups.google.com, to search archives that are remarkably
complete (the old dejanews.com archives are there, as well as newer
and older stuff).
Duncan Murdoch
The fact that microprocessors are "so damned fast" nowadays, and getting
faster, is also a consideration. (At fifty million ops per second,
nobody can hear you scream.)
>J French wrote:
>
> <snip>
>
> .386 Asm which is what Delphi32 supports is a damn sight easier than