x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 4563
Number of posts: 16029

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need help with inline assembly in C code Posted by LanguidLegend on 7 Apr 2011 at 2:41 PM
Hi everyone, I'm new to this site and hope you might be able to help me out?
So I've been given an assignment to produce this output:
% ./hw3b foo
slow foo but foo sure
% ./hw3b XYZ123
slow XYZ123 but XYZ123 sure
% ./hw3b 'stinky junk'
slow stinky junk but stinky junk sure

using asm to insert the word/phrase, and only these libraries: stdlib.h, stdio.h, & string.h.
I've already done most of the the C coding (shown below) I think, but I'm stuck on the asm assembler code insertion.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
 
char word[] = "here and there";
int sz;
int wordsz;
char *arg;
char *result;
 
int main(int argc, char* argv[]) {
   if (argc != 2) {
     printf("Usage: %s takes one string argument.\n", argv[0]);
     exit(1);
   }
 
   sz = strlen(argv[1]) + 1;
   arg = malloc(sz);
   strcpy(arg, argv[1]);
   wordsz = strlen(word) + 1;
   result = malloc(sz * wordsz);
 
   __asm__("\n\
     \*In here will be a loop which will use iter
       to iterate one char (byte) at a time.
       When it comes upon a space char it will exit
       to the print statement, but when it comes
       upon a newline, it will ret and exit*\
");
   //I'm thinkin of something like this, where temp_save is there
   //to save the index of the beginning of the last word to
   //provide a range ([temp_save,iter]) for strncpy()
   //So essentially this will copy the correct range out of word
   //and append it (followed by the keyword arg) onto result
   strcat(result,"%s %s",strncpy(result,word+temp_save,iter),arg);
   temp_save=iter;
 
   __asm__("\n\
     \*If newline delimiter not reached, return to
       previous loop*\
");
   printf("%s\n", result);
   return 0;
}



Herein lies my issue: how can I detect a space (' ') char using assembly?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.