0
我正在嘗試在程序集lang中編寫腳本。從給定的字符串打印帶有子字符串的單詞。 例如:程序集查找包含給定字符串中子字符串的字
char* a="hello world lol asdf";
char* b="lo";
char buffer[100];
和印刷的話是:
「你好笑」
我在ANSI C寫的程序爲:
#include <stdio.h>
#include <string.h>
int main(){
char *s = "hello bencsss trololo molo";
char *b ="lo";
char bufor[100];
int i, j=0,k=0,c=0,l=0;
for(i=0;i<strlen(s);i++){
if(s[i]==' ') k=i+1;
if(b[j]==s[i]){
j++;
if(j==strlen(b)-1){
while(s[k]!=' ' && k<(strlen(s))){
bufor[c]=s[k];
c++;
k++;
}
bufor[c]=' ';
c++;
k=i;
}
}
else{
j=0;
}
}
printf("%s",bufor);
return 0;
}
和這裏是我寫到目前爲止在asm:
#include <stdio.h>
int main(){
//short int y;
char *s = "hello world!\n";
char *b ="lo";
char bufor[100];
asm volatile(
".intel_syntax noprefix;"
"mov eax,%0;" //16
"push eax;"
"mov eax,%1;" //12
"push eax;"
"mov eax,%2;" //8
"call zadanie1;"
"jmp end;"
"zadanie1:"
"push eax;"
"push ebp;" //4
"mov ebp,esp;"
"push ebx;"
"push ecx;"
"push edx;"
"mov ebx,[esp+16];"
"reset:"
"mov eax,[esp+12];"
"jmp word;"
"space:"
"mov [si],ebx;"
"jmp forward;"
"word:"
"mov dl,[ebx];"
"mov dh,[eax];"
"cmp dl,' ';"
"je space;"
"forward:"
"cmp dl,dh;"
"inc ebx;"
"jz reset;"
"inc eax;"
"cmp dh,'0';"
"je buff;"
"jmp word;"
"buff:"
"mov [ecx,esp+8];"
"inc ecx;"
"loop:"
"mov dh,[ecx];"
"mov [si],dh"
"cmp dh,' ';"
"je reset;"
"inc ecx;"
"inc si;"
"end:"
".att_syntax prefix;"
:
:"r"(s), "r"(b),"r"(bufor)
:"eax"
);
asm可能寫錯了,它還沒有完成,我仍然在這種語言newbe所以..
好吧...我可以得到任何文字或建議或什麼如何使這個程序在ASM,請? 花了我3天的時間寫這個到目前爲止...現在我不知道如何使它實際工作。
乾杯!