Ассемблер в FP

Вопросы программирования на Free Pascal, использования компилятора и утилит.

Модератор: Модераторы

Ассемблер в FP

Сообщение vkos » 10.06.2007 21:10:00

Подскажите, пожалуйста, как использовать регистры в программе на FP? А то есть ассемблерный и FP код, а как их связать непонятно.
vkos
незнакомец
 
Сообщения: 3
Зарегистрирован: 10.06.2007 19:14:20

Сообщение Alexander » 10.06.2007 21:21:24

Код: Выделить всё
{$ASMMODE INTEL}

  var
      i, ii : LongInt;

begin

asm
push eax
mov eax, 777
mov i, eax
dec eax
mov eax, i
mov ii, eax
pop eax
end;

WriteLn(i,' ',ii);

end.
Аватара пользователя
Alexander
энтузиаст
 
Сообщения: 821
Зарегистрирован: 18.12.2005 19:10:00
Откуда: оттуда

Сообщение vkos » 10.06.2007 21:47:54

Спасибо
vkos
незнакомец
 
Сообщения: 3
Зарегистрирован: 10.06.2007 19:14:20

Сообщение Cheb » 11.06.2007 03:48:22

Только лучше ещё добавлять pushf/popf. А то глюков не оберёшься, на собственной шкуре узнал.
Аватара пользователя
Cheb
энтузиаст
 
Сообщения: 994
Зарегистрирован: 06.06.2005 15:54:34

Сообщение Replicator » 11.06.2007 17:14:59

Так есть же способ автоматизтровать попы и пуши:
Код: Выделить всё
Signaling changed registers
When the compiler uses variables, it sometimes stores them, or the result of some calculations, in
the processor registers. If you insert assembler code in your program that modifies the processor
registers, then this may interfere with the compiler’s idea about the registers. To avoid this problem,
Free Pascal allows you to tell the compiler which registers have changed in an asm block. The
compiler will then save and reload these registers if it was using them. Telling the compiler which
registers have changed is done by specifying a set of register names behind an assembly block, as
follows:
asm
...
end [’R1’, ... ,’Rn’];
Here R1 to Rn are the names of the registers you modify in your assembly code.
As an example:
asm
movl BP,%eax
movl 4(%eax),%eax
movl %eax,__RESULT
end [’EAX’];
This example tells the compiler that the EAX register was modified.
For assembler routines, i.e., routines that are written completely in assembler, the ABI of the processor
& platform must be respected, i.e. the routine itself must know what registers to save and what
not. The method described above doesn’t apply there.
The only thing the compiler does, is create a minimal stack frame if needed (e.g. when variables are
declared). All the rest is up to the programmer.

Т.е. код будет таким:
Код: Выделить всё
{$ASMMODE INTEL}
  var
      i, ii : LongInt;
begin
  asm
    mov eax, 777
    mov i, eax
    dec eax
    mov eax, i
    mov ii, eax
  end ['EAX'];

  WriteLn(i,' ',ii);
end.
Replicator
постоялец
 
Сообщения: 154
Зарегистрирован: 30.04.2006 17:14:45
Откуда: Outer Heaven


Вернуться в Free Pascal Compiler

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 6

Рейтинг@Mail.ru