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
% ./hw4b foo
here foo and foo there
% ./hw4b ABC123
here ABC123 and ABC123 there
% ./hw4b 'where is'
here where is and where is there
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\
movl sz, %eax\n\
");
printf("%s\n", result);
return 0;
}
What I'm stuck on is the actual separating/parsing of the word(s) (delimited by the space ' ' character).. I mean I know that %eax can hold a long word (4 bytes), but if I recall correctly, single chars take up 1 byte each, so there is no register which can hold the entirety of word, nevermind result.
Any help would be greatly appreciated!
Thank you