# Board index » delphi » Re: Could someone help with this function

## Re: Could someone help with this function

2006-04-14 01:37:01 AM
delphi255
"Wilbert van Leijen" <XXXX@XXXXX.COM>writes
##### Quote

"Jon Springs" <jspringsATjontandsheDOTorg>schreef in bericht
news:443dacc5

>mov @Result,ax <<<<<<<< error

Just remove this line. An integer result is expected to be in the AX
register.

>end;
>end;
>
My understanding is that the the instruction is setting the return value of
the function. If I remove it then the result would be indeterminate wouldn't
it?
Thanks,
-----Jon-----

## Re: Could someone help with this function

Jon Springs writes:
##### Quote
I used to be quite good at Z80 asm, but haven't had the time or need to get
up to speed on x86.

The following function (used to change directory), compiled fine BP 7 but
Delphi 7 emits an error:
Of course it does. You're feeding it 16-bit assembler code and Delphi 7 is
a 32-bit compiler !!! You might have some luck with Delphi 1, though...
##### Quote

Operand size mismatch

function LFNChDir(DirName : string) : Integer;
begin
asm
push ds
push ss
pop ds
lea si,DirName
mov bl,[si]
xor bh,bh {bx = length}
inc si {si points to first actual character}
mov byte ptr [bx+si],0 {null-terminate}
mov dx,si
mov ax,$713B stc int$21
jc @Error
xor ax,ax
@Error:
pop ds
mov @Result,ax <<<<<<<< error
end;
end;

TIA

-----Jon-----

--
Arthur Hoornweg
including the "antispam" part. I had to take this measure to
counteract unsollicited mail.)

## Re: Could someone help with this function

message news:XXXX@XXXXX.COM...
##### Quote
>
>This code works when compiled with Borland Pascal 7.
>
>I amd lazy and work in DOS a lot and have lots of directories. This
>code is part of a little 'go' program that maintains a list of
>shortcuts and associated directories, i.e 'xx d:\aa\bb\cc\xx'.
>
>'go xx' would change to drive d: and chdir to directory aa\bb\cc\xx.
>Saves lots of typing.
>
>Just wanted to finally remove BPC.exe (16-bit compiler), but I can
>live with it.

You don't need any assembly to do this. A simple call to ChDir will do.

Actually you don't even need a compiler to do this. A simple batch file
will also work and is easier to maintain if your list of preferences
changes.

--
The Fastcode Project: www.fastcodeproject.org/
Except that the chdir is not sticky. When the go command is executed, sy 'go
aa' where 'aa' equates to 'c:\bb\ad' and I amd in 'd:\ee\ff', first the
drive is not changed and second, after execution, I am back in 'd:\ee\ff'. I
want to be left in 'c:\bb\ad'.
-----Jon-----

## Re: Could someone help with this function

Arthur,
I am trying to translate the 16-bit to 32-bit. If this can not e done, I'll
just keep BPC around for this one little utility.
-----Jon-----
"Arthur Hoornweg" <XXXX@XXXXX.COM>writes
##### Quote
Jon Springs writes:

>I used to be quite good at Z80 asm, but haven't had the time or need to
>get up to speed on x86.
>
>The following function (used to change directory), compiled fine BP 7 but
>Delphi 7 emits an error:

Of course it does. You're feeding it 16-bit assembler code and Delphi 7 is
a 32-bit compiler !!! You might have some luck with Delphi 1, though...

>
>Operand size mismatch
>
>function LFNChDir(DirName : string) : Integer;
>begin
>asm
>push ds
>push ss
>pop ds
>lea si,DirName
>mov bl,[si]
>xor bh,bh {bx = length}
>inc si {si points to first actual character}
>mov byte ptr [bx+si],0 {null-terminate}
>mov dx,si
>mov ax,$713B >stc >int$21
>jc @Error
>xor ax,ax
>@Error:
>pop ds
>mov @Result,ax <<<<<<<< error
>end;
>end;
>
>TIA
>
>-----Jon-----
>
>

--
Arthur Hoornweg

including the "antispam" part. I had to take this measure to
counteract unsollicited mail.)

## Re: Could someone help with this function

Jon Springs writes:
##### Quote
The following function (used to change directory), compiled fine BP 7 but
Delphi 7 emits an error:

Operand size mismatch

function LFNChDir(DirName : string) : Integer;
[snip]
mov @Result,ax <<<<<<<< error
Integer is 32 bit on Win32. Use the movzx instruction instead of mov.

## Re: Could someone help with this function

""Henrick Hellström [StreamSec]"" <XXXX@XXXXX.COM>writes
##### Quote
Jon Springs writes:
>The following function (used to change directory), compiled fine BP 7 but
>Delphi 7 emits an error:
>
>Operand size mismatch
>
>function LFNChDir(DirName : string) : Integer;
[snip]
>mov @Result,ax <<<<<<<< error

Integer is 32 bit on Win32. Use the movzx instruction instead of mov.
Henrick,
Yes, I realize Win32 has 32-bit integers, and thanks for giving me the
instruction to use. Unfortunately, I still get the same error. Is ax a
16-bit register? Is there a way to promote it?
Thanks,
-----Jon-----

## Re: Could someone help with this function

Jon Springs writes:
##### Quote
""Henrick Hellstrvm [StreamSec]"" <XXXX@XXXXX.COM>wrote in
message news:443ea669$XXXX@XXXXX.COM... >Jon Springs writes: >>The following function (used to change directory), compiled fine >>BP 7 but Delphi 7 emits an error: >> >>Operand size mismatch >> >>function LFNChDir(DirName : string) : Integer; >[snip] >>mov @Result,ax <<<<<<<< error > >Integer is 32 bit on Win32. Use the movzx instruction instead of >mov. Henrick, Yes, I realize Win32 has 32-bit integers, and thanks for giving me the instruction to use. Unfortunately, I still get the same error. Is ax a 16-bit register? Is there a way to promote it? Thanks, -----Jon----- EAX, EBX, ECX, EDX, ESI, and EDI are (some of) the 32-bit registers. I think the "E" stands for Extended. HTH, Glynn -- "It is high time that the ideal of success should be replaced by the ideal of service." (Albert Einstein). ## Re: Could someone help with this function Jon Springs writes: ##### Quote Yes, I realize Win32 has 32-bit integers, and thanks for giving me the instruction to use. Unfortunately, I still get the same error. Is ax a 16-bit register? Is there a way to promote it? I think it is easier to simply change the result type to Word or SmallInt. ## Re: Could someone help with this function "Glynn Owen" <XXXX@XXXXX.COM>writes ##### Quote Jon Springs writes: >""Henrick Hellstrvm [StreamSec]"" <XXXX@XXXXX.COM>wrote in >message news:443ea669$XXXX@XXXXX.COM...
>>Jon Springs writes:
>>>The following function (used to change directory), compiled fine
>>>BP 7 but Delphi 7 emits an error:
>>>
>>>Operand size mismatch
>>>
>>>function LFNChDir(DirName : string) : Integer;
>>[snip]
>>>mov @Result,ax <<<<<<<< error
>>
>>Integer is 32 bit on Win32. Use the movzx instruction instead of
>>mov.
>
>Henrick,
>
>Yes, I realize Win32 has 32-bit integers, and thanks for giving me
>the instruction to use. Unfortunately, I still get the same error. Is
>ax a 16-bit register? Is there a way to promote it?
>
>Thanks,
>
>-----Jon-----

EAX, EBX, ECX, EDX, ESI, and EDI are (some of) the 32-bit registers. I
think the "E" stands for Extended.

HTH, Glynn

--
"It is high time that the ideal of success should be replaced by the
ideal of service." (Albert Einstein).
Glenn,
Does that mean that EAX is mapped to AX as a 32-bit register containing the
same value as AX and I simply return the EAX value?
Sorry to be so dense here, but I haven't gotten the hang of x86 assembly yet
(I can still remember some Univac 1050-II, Burroughs B-263 and IBM System
360 code though ;-) ).
-----Jon-----

## Re: Could someone help with this function

Jon Springs writes:
##### Quote
Does that mean that EAX is mapped to AX as a 32-bit register containing the
same value as AX and I simply return the EAX value?
No, AX is the lower 16 bits of EAX. This means that if you set AX and
then later use EAX, the upper 16 bits of EAX will be undefined.

## Re: Could someone help with this function

Jon Springs writes:
##### Quote
"Glynn Owen" <XXXX@XXXXX.COM>writes
news:443ee333$XXXX@XXXXX.COM... >Jon Springs writes: > >>""Henrick Hellstrvm [StreamSec]"" <XXXX@XXXXX.COM>wrote in >>message news:443ea669$XXXX@XXXXX.COM...
>>>Jon Springs writes:
>>>>The following function (used to change directory), compiled fine
>>>>BP 7 but Delphi 7 emits an error:
>>>>
>>>>Operand size mismatch
>>>>
>>>>function LFNChDir(DirName : string) : Integer;
>>>[snip]
>>>>mov @Result,ax <<<<<<<< error
>>>
>>>Integer is 32 bit on Win32. Use the movzx instruction instead of
>>>mov.
>>
>>Henrick,
>>
>>Yes, I realize Win32 has 32-bit integers, and thanks for giving me
>>the instruction to use. Unfortunately, I still get the same
>>error. Is ax a 16-bit register? Is there a way to promote it?
>>
>>Thanks,
>>
>>-----Jon-----
>
>EAX, EBX, ECX, EDX, ESI, and EDI are (some of) the 32-bit
>registers. I think the "E" stands for Extended.
>
>HTH, Glynn
>
>-- "It is high time that the ideal of success should be replaced
>by the ideal of service." (Albert Einstein).

Glenn,

Does that mean that EAX is mapped to AX as a 32-bit register
containing the same value as AX and I simply return the EAX value?

Sorry to be so dense here, but I haven't gotten the hang of x86
assembly yet (I can still remember some Univac 1050-II, Burroughs
B-263 and IBM System 360 code though ;-) ).

-----Jon-----
You should probably show your code to the BASM group, tell them you
need help in rewriting it for a 32-bit processor.
HTH, Glynn
--
"It is high time that the ideal of success should be replaced by the
ideal of service." (Albert Einstein).

## Re: Could someone help with this function

##### Quote
You should probably show your code to the BASM group, tell them you
need help in rewriting it for a 32-bit processor.

HTH, Glynn
Glenn,
I have a thread going there as well.
Thanks for your replies, really appreciate all help.
-----Jon-----

## Re: Could someone help with this function

##### Quote
Thanks for your replies, really appreciate all help.
Well this is a non-technical group, so what exactly do you expect?
Oliver Townshend

## Re: Could someone help with this function

"Oliver Townshend" <oliveratzipdotcomdotau>writes
##### Quote
>Thanks for your replies, really appreciate all help.

Well this is a non-technical group, so what exactly do you expect?

Oliver Townshend
Oliver,
I asked for help, admitted I was in the wrong group, got replies anyway,
responded to those and basically signed off and I get your interjection.
Having reviewed the respondents to my request, I notice you to be absent
from any participation.
{*word*81} off!
-----Jon-----

## Re: Could someone help with this function

"Jon Springs" <jspringsATjontandsheDOTorg>writes:
##### Quote
>Well this is a non-technical group, so what exactly do you expect?
>Oliver Townshend
Having reviewed the respondents to my request, I notice you to be absent
from any participation.
{*word*81} off!
-----Jon-----
Nutter.