Code:

#include <stdio.h>

int main()
{
  char Hello[]={  /*My start offset 100*/
       0xeb,0x14, /*jmp 112*/
       0x48, /*dec ax='H'*/
       0x65, /*db 65='e'*/
       0x6c, /*db 6c='l'*/
       0x6c, /*db 6c='l'*/
       0x6f, /*db 6f='o'*/
       0x20,0x43,0x65, /*and [bp+di+65],al=' ''C''e'*/
       0x6d, /*db 6d='m'*/
       0x65, /*db 65='e'*/
       0x74,0x65, /*jz 0173='t''e'*/
       0x63,/*db 63='c'*/
       0x68, /*db 68='h'*/
       0x24,0x00, /*and al,00*/
       0xba,0x02,0x01, /*mov dx,0102*/
       0xb4,0x09, /*mov ah,09*/
       0xcd,0x21, /*int 21*/
       0x6c, /*db 6c*/
       0x69, /*db 69*/
       0x20,0x74,0x61 /*and [si+61],dh*/
       };
       Hello;
  getchar();   
  return 0;
}

I want to "Hello Cemetech" in gcc with use x86asm.Thank u for ur helps.
Let me throw you this: http://ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
Hmm.But i want to write with ascii codes.Without inline asm.
Helo wrote:
Hmm.But i want to write with ascii codes.Without inline asm.


Well, that's honestly just incredibly stupid. It's a waste of time, and has really no advantage over using the mnemonics. Either way, you should be using the asm/__asm__ gcc macros.
Ashbad's advice is good. As far as what you posted (I have nothing to say on the machine code itself, because I can't be bothered to examine it closely), the Hello; statement is nonsense.

You might be able to cast the array to a function pointer..:

Code:
((void (*)())Hello)();

The C specification says calling the result of a cast to a function pointer is undefined. In some versions of GCC this will simply invoke abort (and who knows what other compilers will do- they're allowed to insert code that invokes rm -rf / as far as the standard says), so you really shouldn't do this. Use inline assembly. I think this will work (but there's still really no excuse for embedding machine code in your source):

Code:
__asm__("\tcall _Hello");
@Ashbad If you are looking this incredibly stupid to attend C,C++.Everybody can attend AS,C#,Java??Ashbaaaaaaddddd.Ashhhhhbaaaadddd.Ashhbaaaaddd.You don't annoy a man:)
Helo wrote:
@Ashbad If you are looking this incredibly stupid to attend C,C++.Everybody can attend AS,C#,Java??Ashbaaaaaaddddd.Ashhhhhbaaaadddd.Ashhbaaaaddd.You don't annoy a man:)


Erm, what?
What is Erm?
Okay, a few quick notes:

For one thing, don't use character arrays for constant strings...

GAS has the ascii directive for a reason. Use it. That horrible looking mess of an array becomes


Code:
.ascii "Hello Cemetech$\0"


when you use it. Also, Int 21/AH 09 requires the character '$' to terminate the string. You forgot both that and the null character (which should always be included in strings).

Finally, use the mnemonics if you're going to type them out in the comments anyway.

PS: I think the print routine you're calling also requires some additional data about the message to print in the e*x registers.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement