Gcc inline ASM, set EBX to char array address using LEA

Luca D'Amico

I'm trying to convert an inline asm code form VS to GCC (AT&T).. the original code is this one:

char mystr[] = "Hello world";
_asm mov eax,0
_asm lea ebx, [mystr]

Here is my attempt to convert that code in gcc at&t syntax:

char mystr[] = "Hello world";
asm("mov $0,%%eax\n"
    "leal (%0),%%ebx\n"
    : : "r"(mystr));

This code doesn't seems to work, any idea why ? Thank you very much

Luca D'Amico

This code seems to works:

char* mystr = "Hello world";

asm("mov $0,%%eax\n"
    "leal (%0),%%ebx"
    ::"b"(mystr));

I've changed char mystr[] to char* mystr, and "r" with "b".. If somebody know what "b" does exactly, please let me know... many thanks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Branch to an address using GCC inline ARM asm

From Dev

GCC inline asm with aapcs

From Dev

gcc inline asm not compiling

From Dev

Why does GCC put a no-op push/pop when using int foo asm("ebx") to pin a var to a register?

From Dev

Gcc Inline ASM input variable

From Dev

Inline asm in GCC, specifying offset by expression

From Dev

gcc arm __asm inline passing constant in parameter

From Dev

gcc inline asm bug - argument ignored

From Dev

gcc incorrectly reusing registers in inline asm

From Dev

GCC inline - push address, not its value to stack

From Dev

GCC inline - push address, not its value to stack

From Dev

gcc inline asm jump to a label with crossing throwing an exception

From Dev

Avoid flushing registers on memory access (gcc inline asm)

From Dev

Avoid flushing registers on memory access (gcc inline asm)

From Dev

Call scanf in X64 gcc inline asm

From Dev

using char * in C (GCC)

From Dev

Inline Assembly lea with arrays

From Dev

How do I get address of class member function by asm in GCC?

From Dev

ASM space optimization: EAX vs EBX

From Dev

constexpr char array with GCC and clang

From Dev

constexpr char array with GCC and clang

From Dev

Unexpected output for address of char array

From Dev

Assembly - inline asm - copy from one array to another?

From Dev

Set exact size of char array using dynamic memory allocation

From Dev

assembly lea: invalid effective address

From Dev

Using base pointer register in C++ inline asm

From Dev

Using condition flags as GNU C inline asm outputs

From Dev

Get variable address using inline assembly

From Dev

Gcc inline assembly what does "'asm' operand has impossible constraints" mean?

Related Related

HotTag

Archive