public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: X86 Assembly Short Jump
       [not found] <OFC0797F7A.B235B087-ON48256E0C.00253ACE-48256E0C.0025D79A@diamond.philips.com>
@ 2003-12-30 13:56 ` Kris Lyon
  2003-12-30 15:35   ` Rupert Wood
  0 siblings, 1 reply; 3+ messages in thread
From: Kris Lyon @ 2003-12-30 13:56 UTC (permalink / raw)
  To: qinfeng.zhang; +Cc: gcc-help

I double checked the Intel documentation
(http://www.intel.com/design/pentiumiii/manuals/), and as far as I can
tell JMP is the only non-conditional jump instruction of this type.
Thanks for the suggestion though.  I just wanted to know if there was
something horribly obvious that I was doing wrong.  If anyone has
anymore suggestions... they'd be appreciated.

	-kris

-----Original Message-----
From: qinfeng.zhang@philips.com [mailto:qinfeng.zhang@philips.com] 
Sent: Tuesday, December 30, 2003 1:51 AM
To: goa@rogers.com
Cc: gcc-help@gcc.gnu.org; gcc-help-owner@gcc.gnu.org; goa@rogers.com
Subject: Re: X86 Assembly Short Jump


It seems that you should use another jump instruction.

I have the impression that there are several typy jump instructions in
x86 assembly.

For JMP, the destination address is a relative address. There should be
another jump

instruction, which has a absolute address as destination.


Anyway, I am not sure. You can refer the Intel doc.


Regards              /)/)
                    (-.-)
Qinfeng Zhang

Philips Research East Asia - Shanghai
Tel: (86-21) 6354 1088 Ext. 5356
Fax: (86-21) 6354 4954
Email: qinfeng.zhang@philips.com


 

 

                                                   To:
<gcc-help@gcc.gnu.org>

                                                   cc:
<goa@rogers.com>

                                                    (bcc: Qinfeng
Zhang/SHA/RESEARCH/PHILIPS)

                                                   Subject:    X86
Assembly Short Jump

               <goa@rogers.com>

                                                   Classification:

               Sent by:

               gcc-help-owner@gcc.gnu.o

               rg

 

               2003-12-30 11:46

 

 





I've having a problem using gcc's inline assembly on a Pentium 3 running
redhat linux:

I'm working inside a __asm__("."); block and I'd like to execute a short
(near relative) jump instruction.  It doesn't seem to work.  Instead, I
get a near jump to an absolute position, so I figure that I'm doing
something wrong.  If anyone could help, I'd appreciate it..

When the instruction is executed, eip is set to 0x02, instead of being
set to eip+2.  I looked at the disassembly in gdb and the op-code I
should be getting according to the Intel IA32 Instruction Set Reference
is "EB" but instead I'm instead getting "E9".

Again, any help would be appreciated.  Perhaps there's a better way to
jump to a relative position within an assembly block.

                         -kris


__asm__("
             .
             JMP 0x02          # Should add 0x02 to eip, but instead, it
sets
eip to 0x02.
             .
");








^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: X86 Assembly Short Jump
  2003-12-30 13:56 ` X86 Assembly Short Jump Kris Lyon
@ 2003-12-30 15:35   ` Rupert Wood
  0 siblings, 0 replies; 3+ messages in thread
From: Rupert Wood @ 2003-12-30 15:35 UTC (permalink / raw)
  To: 'Kris Lyon'; +Cc: gcc-help

Kris wrote:

> I just wanted to know if there was something horribly obvious that
> I was doing wrong.
:
> JMP 0x02 # Should add 0x02 to eip, but instead, it sets eip to 0x02.

Yes - the assembler syntax *always* accepts the absolute address, not the
relative address. As a programmer, you wouldn't want to have to dig out the
docs to count the size of your instructions just to enter a jump, would you?
You use absolute addresses and labels and let the assembler sort out all of
that for you.

I didn't answer earlier because I don't know enough about GCC's asm syntax
to tell you how to do what you want. In MASM you'd do something like

    label_here:
          jmp      label_here+2

or perhaps you'd have to throw in "offset" and a few square brackets - I
can't remember.

But I suspect you're trying to do some make-it-hard-to-disassemble trick.
i.e. something like

     00000   xx 03             jmp 00003
     00002   yy aa bb cc dd    mov eax, 0xddccbbaa

when it's really

     00000   xx 03             jmp 00003
     00002   yy                garbage
     00003   aa bb cc dd       call _printf

- that's the only circumstance I can think of where you'd want to enter your
own relative jump - in which case you'd always want to add the garbage byte
afterwards too. So you probably want to enter the bytes in the assembly
block as data, i.e. using "db xx 03 yy" or similar if you can.

Of course the real place to generate such a trick is when you convert the
RTL to output assembler so you can pick you garbage byte to maximise the
time before the accidental disassembly comes good again :-)

Rup.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* X86 Assembly Short Jump
@ 2003-12-30  3:44 goa
  0 siblings, 0 replies; 3+ messages in thread
From: goa @ 2003-12-30  3:44 UTC (permalink / raw)
  To: gcc-help; +Cc: goa

I've having a problem using gcc's inline assembly on a Pentium 3 running
redhat linux:

I'm working inside a __asm__("."); block and I'd like to execute a short
(near relative) jump instruction.  It doesn't seem to work.  Instead, I
get a near jump to an absolute position, so I figure that I'm doing
something wrong.  If anyone could help, I'd appreciate it..

When the instruction is executed, eip is set to 0x02, instead of being
set to eip+2.  I looked at the disassembly in gdb and the op-code I
should be getting according to the Intel IA32 Instruction Set Reference
is "EB" but instead I'm instead getting "E9".

Again, any help would be appreciated.  Perhaps there's a better way to
jump to a relative position within an assembly block.

		-kris


__asm__("
	.
	JMP 0x02	# Should add 0x02 to eip, but instead, it sets
eip to 0x02.
	.
");



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-12-30 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <OFC0797F7A.B235B087-ON48256E0C.00253ACE-48256E0C.0025D79A@diamond.philips.com>
2003-12-30 13:56 ` X86 Assembly Short Jump Kris Lyon
2003-12-30 15:35   ` Rupert Wood
2003-12-30  3:44 goa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).