Recent

Author Topic: How to use jmp jne... (jumps) in asm code  (Read 6585 times)

ciammaruca

  • New Member
  • *
  • Posts: 20
How to use jmp jne... (jumps) in asm code
« on: November 01, 2014, 07:03:47 am »
hi again,
i'm in linux ubuntu; following:
http://forum.lazarus.freepascal.org/index.php/topic,25414.msg154291.html#msg154291
or
http://khangnote.blogspot.it/2011/04/use-assembly-in-virtual-pascal.html
i use prefix @ to jumps (like: jmp @ex) but it does not work:
for the local point i have:
Error: Unrecognized opcode
and for the instruction:
Error: Assembler syntax error in operand

which prefix i have to use for jumps?

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: How to use jmp jne... (jumps) in asm code
« Reply #1 on: November 01, 2014, 02:25:31 pm »
It's possible there are some specific conditions relative to the linux version of FPC, but just in case ...

Have you added a ':' character (i.e. colon character) at the end of your label ? Like '@ex:', to take your own sample.

For me, this is working without any problem for instance (but for the windows version of FPC):
Code: [Select]
{$asmmode intel}

function IsNull(value: integer): boolean;
begin
  asm
    mov     eax, value
    test    eax, eax
    jne     @notnull
    mov     result, true
    jmp     @finished
@notnull:
    mov     result, false
@finished:
  end;
end;
« Last Edit: November 01, 2014, 02:31:24 pm by ChrisF »

ciammaruca

  • New Member
  • *
  • Posts: 20
Re: How to use jmp jne... (jumps) in asm code
« Reply #2 on: November 01, 2014, 04:37:26 pm »
hi,
yes, inserted colon character, but no, does not work in my ubuntu!!
Yes, if in win works there should be "some specific conditions relative to the linux version of FPC".
So strange!!

Laksen

  • Hero Member
  • *****
  • Posts: 743
    • J-Software
Re: How to use jmp jne... (jumps) in asm code
« Reply #3 on: November 01, 2014, 04:43:22 pm »
Isn't it because x86_64 only supports at&t and mode?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to use jmp jne... (jumps) in asm code
« Reply #4 on: November 01, 2014, 07:08:41 pm »
hi,
yes, inserted colon character, but no, does not work in my ubuntu!!
Yes, if in win works there should be "some specific conditions relative to the linux version of FPC".
So strange!!
No, it's the way you use (your configuration, etc.)
Isn't it because x86_64 only supports at&t and mode?
ChrisF's code compiles fine in x86_64-linux, though the logic seems inverted. asmmode works for intel processor, regardless of bitness.

lagprogramming

  • Sr. Member
  • ****
  • Posts: 406
Re: How to use jmp jne... (jumps) in asm code
« Reply #5 on: November 01, 2014, 08:04:39 pm »
Are you looking for something like this?!

Code: [Select]
procedure q_constref_int64(constref x,c:int64;out localresult:int64);assembler;register;nostackframe;
label one,two;
asm
movq (%rsi),%rax
cmpq (%rdi),%rax
jne one
movq $1,(%rdx)
jmp two
nop
one:
movq $0,(%rdx)
two:
end;

ciammaruca

  • New Member
  • *
  • Posts: 20
[SOLVED] Re: How to use jmp jne... (jumps) in asm code
« Reply #6 on: November 02, 2014, 12:03:10 am »
thanks,
"label" declaration is needed, before asm code. Now in my ubuntu jmp & his friends work fine!
mille grazie

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: How to use jmp jne... (jumps) in asm code
« Reply #7 on: November 02, 2014, 03:18:56 am »
This code is using the AT&T syntax.

So either x86_64 linux supports only this mode (i.e. not the intel mode) as indicated by Laksen, or you've not declared the intel mode before your assembly code.

If this is the first case, I'm just a bit surprised that no error message is raised during the compilation. One could expect that if the intel mode is selected and not compatible with the target, an error should be displayed.

 

TinyPortal © 2005-2018