assembler 
Author Message
 assembler

Hi There

I have recently tried to write some assembler procedures and functions.

I have to problems which I can not resolve.
If I have a function:

function one:byte; assembler;

How do I move a value to one.

In Pascal it would have been:  one := whatever;

e.g. mov one,ax

If you can give the 32-bit code so much the better.
e.g. db $66; mov one,ax
 where one is know a longint function.

Secondly how do I in assembler directly change values of call-by-reference
parameters.

e.g.
 procedure one(var A:byte); assembler;
asm
  mov A,123;
end;

Thankyou for your help.

Chaou
Heinrich

Check my web-site:
http://www.*-*-*.com/
Includes a complete TP tutoriul and more!



Wed, 18 Jun 1902 08:00:00 GMT  
 assembler

Quote:

> I have to problems which I can not resolve.
> If I have a function:

> function one:byte; assembler;

> How do I move a value to one.

> In pascal it would have been:  one := whatever;

> e.g. mov one,ax

Put the value to return in the ax-register:
al for 8-bit return type (byte)
ax for 16-bit return type (word)
eax for 32-bit (dx/ax in Turbo Pascal because of 16-bit restrictions)

function add_2(a: byte): byte; assembler;
asm
  mov al, a
  add al, 2
end;

This would return a+2.

Quote:
> If you can give the 32-bit code so much the better.
> e.g. db $66; mov one,ax
>  where one is know a longint function.

If you want to use 32-bit code, try a 32-bit compiler. I suggest Free
Pascal (http://www.freepascal.org/) because you don't need 'db $66'
there, you can use 'eax' and other assembler constructs that TP doesn't
know.
Under TP you have to return longints split up in 2 16-bit registers
(dx/ax).

Quote:
> Secondly how do I in assembler directly change values of call-by-reference
> parameters.

> e.g.
>  procedure one(var A:byte); assembler;
> asm
>   mov A,123;
> end;

This can't work because 'A' is the address of the variable A. So mov A,
123 won't work.

procedure onetwothree(var A: byte); assembler;
asm
  les di, a  { load address to es:di }
  mov byte ptr es:[di], 123
end;

Wolf



Wed, 18 Jun 1902 08:00:00 GMT  
 assembler

Quote:

> I have to problems which I can not resolve.
> If I have a function:

> function one:byte; assembler;

> How do I move a value to one.

> In pascal it would have been:  one := whatever;

> e.g. mov one,ax

> If you can give the 32-bit code so much the better.
> e.g. db $66; mov one,ax
>  where one is know a longint function.

You must know where the compiler expects the return value to be
returned. Generally, this is a register for numerical values or
a memory location for strings. Taken from the online help:

Result  | Returned in            | Comment
--------+------------------------+----------------------------
Ordinal | AL (8-bit values)      | Integer, Char, Boolean, and
        |                        | enumerated types
        | AX (16-bit values)     |
        | DX:AX  (32-bit values) |

Real    | DX:BX:AX               | Real type

8087    | ST(0) on the 8087's    | Single, Double, Extended,
        | register stack         | and Comp types

Pointer | DX:AX                  |

String  | The temporary location |

So, your function would have to look like this:

function one: byte; assembler;
asm
  mov al, 12
end;

It would return 12.

For strings, proceed as follows:

function one: string; assembler;
asm

  mov  byte ptr es:[di], length_of_string
  mov  byte ptr es:[di+1], first_character_of_string
  ...
end;

Quote:
> Secondly how do I in assembler directly change values of call-by-reference
> parameters.

> e.g.
>  procedure one(var A:byte); assembler;
> asm
>   mov A,123;
> end;

Call by reference parameters are in fact pointers. Load the address
that the pointer points to into the register pair es:di and write
to it:

procedure one(var a: byte); assembler;
asm
  les  di, a
  mov  byte ptr es:[di], 12
end;

a, that is the variable you passed as a parameter to the procedure,
will then contain the value 12.



Wed, 18 Jun 1902 08:00:00 GMT  
 assembler
Thankyou for all your response!

But there's one thing!
You can access 32-bit instructions in TP 7.0

try the following code:

var
  long:longint;

long := 1000;
asm
 db $66;mov ax,word ptr[long]
 db $66; shl ax,5
 db $66;mov word ptr [long],ax
end;

db $66 makes it 32-bit!

Anyway thanks you really helped me allot!!!
Chaou
Heinrich

Check my web-site:
http://homes.arealcity.com/Heinrichshomepage/
Includes a complete TP tutoriul and more!



Wed, 18 Jun 1902 08:00:00 GMT  
 assembler

Quote:
> Thankyou for all your response!

> But there's one thing!
> You can access 32-bit instructions in TP 7.0

Yes we know!

--
Jay

Jason Burgon - Author of Graphic Vision
New version 2 now available from:
http://www.jayman.demon.co.uk



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Using 386(+) opcodes in the builtin assembler

2. Using data from assembler

3. Using 386+ instructions & and the builtin assembler

4. including assembler-moduls in bp7-programs

5. Assembler

6. Assembler: Problem with using real values

7. TP6 code -> assembler

8. Accessing array from within the built-in assembler

9. Mouse Drivers in Pascal (possibly some assembler) ?

10. Assembler

11. FPC and assembler

12. pascal + assembler

 

 
Powered by phpBB® Forum Software