Recent

Author Topic: How to assign a value to a static variable?  (Read 4483 times)

beria

  • Jr. Member
  • **
  • Posts: 70
How to assign a value to a static variable?
« on: February 21, 2017, 09:51:03 pm »
TVal = object
  public
    Er: longint; static;


movl $0,  TVal.er
movl   $0,__Self.Er
movl   $0,Er
movl $0,er(%esi)
movl $0,TVal.er(%esi)
Does not work



Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: How to assign a value to a static variable?
« Reply #1 on: February 21, 2017, 09:58:20 pm »
I do not use assembler, but you need to read http://wiki.lazarus.freepascal.org/Assembler_and_ABI_Resources and use 'asm' and 'end' to enclose the asm code.

beria

  • Jr. Member
  • **
  • Posts: 70
Re: How to assign a value to a static variable?
« Reply #2 on: February 21, 2017, 11:37:32 pm »
I do not use assembler, but you need to read http://wiki.lazarus.freepascal.org/Assembler_and_ABI_Resources and use 'asm' and 'end' to enclose the asm code.

You are not right. I have no problem with writing in assembly language x86 / x86-64 for FPC, despite the severe limitations of obvious errors in it. I have a strong problem with how to apply it to a static variable, that is, that without the use of a parameter @Self I found nowhere else like it for ATT syntax, but was looking for a long time.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to assign a value to a static variable?
« Reply #3 on: February 22, 2017, 12:42:18 am »
I can give you link to doc only: http://www.freepascal.org/docs-html/3.0.0/ref/refse29.html.
Maybe class var or {$static on} directive will work for you
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

beria

  • Jr. Member
  • **
  • Posts: 70
Re: How to assign a value to a static variable?
« Reply #4 on: February 22, 2017, 01:10:31 am »
I can give you link to doc only: http://www.freepascal.org/docs-html/3.0.0/ref/refse29.html.
Maybe class var or {$static on} directive will work for you

Alas, does not help ..... I'm starting to think that he had met a compiler error because movl $0, __ Self.Er broadcast instead  "movl $0, (the address of a static variable) in  mov $0x0,%eax  - eax register overwriting the value where the usually the output value of the function
p.s. : Sorry for the English - Google ...

pps:
I solved the problem in the wrong way ..

type
  TVal = object
  public
     Error: longword; static;
......
end;
     
var
  Er : longword absolute TVal.Error;

movl $0, Er   <- Ok


The question is open - how to solve it properly?
                       




« Last Edit: February 22, 2017, 06:14:49 am by beria »

Thaddy

  • Hero Member
  • *****
  • Posts: 14391
  • Sensorship about opinions does not belong here.
Re: How to assign a value to a static variable?
« Reply #5 on: February 22, 2017, 06:42:14 am »
You are still being put on the wrong foot. See my reply in the similar issue you opened. (Bad habit, btw....)
Simply writing it first in Pascal and then compile with -a will give you an *.s file which contains the assembler the compiler generates.
Then you will see how to do it... You will also see that you can't improve on the compiler for such simple assignments by using asm.
In the other thread is an example for you to try.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

beria

  • Jr. Member
  • **
  • Posts: 70
Re: How to assign a value to a static variable?
« Reply #6 on: February 22, 2017, 07:26:33 am »
Simply writing it first in Pascal and then compile with -a will give you an *.s file which contains the assembler the compiler generates.

And that will give me sight of the fact that the FPC team generated movl and address of a static variable, which will be the one when the next compilation? I know this is so. Moreover, not all assembly design that I use have analogues in Pascal, as well as many of the algorithms they use.
In this case, the way everything is easier, but what do you restore an assembler listing of ...
movl $ 0, U_ $P$PROJECT _ $$ __ static_tval_ERROR
I myself know that U_ $P$PROJECT _ $$ __ static_tval_ERROR - converted TVar.Error variable name, but describe it as part of the syntax ....

This is the question !!!

 

TinyPortal © 2005-2018