Jump to content
a13x4nd7u

Ajutor in C++ cu asm

Recommended Posts

Salut,

Pana acum foloseam Windows XP, dar de curand am hotarat sa imi pun Linux. Am vazut ca ceea ce facusem in Windows cu asamblare nu mergea si pe Linux.

Aveam pentru Windows functia:


char getch(void)
{

char chx=0;

asm {
mov ah,0
int 16h
mov [chx],al
}

if(chx == 0)
{
asm {
mov ah,10
int 16h
mov [chx],al
}
}

return chx;
}

Cu ce ar trebui sa inlocuiesc "asm { ... }" in cele 2 locuri pentru ca acest cod sa mearga pe Linux?

Multumesc anticipat.

Link to comment
Share on other sites

Cand am vrut sa fac asta asa a fost demult. Tin minte ca am cautat pe google si chiar am citit acel articol care nu ajuta deloc daca stii asamblare Intel.

Asamblarea inline a lui gcc respectiv g++ este AT&T, si nu Intel.

Ca sa imbini C/C++ cu asamblare Intel (acum am aflat) pe Linux poti folosi nasm sau gas (doar compilarea), gcc sau g++ doar compilarea, si dupa aia le legi cu ld.

Cu gcc / g++ compillezi sursa C/C++:

gcc -c -o obiect_c.o sursa.c

g++ -c -o obiect_cpp.o sursa.cpp

Cu nasm compilezi sursa asm:

nasm -f aout sursa.asm -o obiect_asm.o

Cu ld legi cele 2 obiecte create:

ld -o executabil obiect_asm.o obiect_c.o

sau

ld -o executabil obiect_asm.o obiect_cpp.o

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...