--- /dev/null
+.text
+.global printf
+.global asm_main
+
+asm_main:
+#rdi = asm code
+0:
+ mov %rdi, %rsi
+1:
+ movb (%rdi), %al
+
+ cmpb $32, %al
+ je 2f
+
+ cmpb $44, %al
+ je 3f
+
+ cmpb $10, %al
+ je 4f
+
+ test %al, %al
+ je 5f
+
+ inc %rdi
+ jmp 1b
+
+2:#before ' ' is opcode
+3:#before ',' is operand 1
+4:#before '\n' is operand 2
+ movb $0, (%rdi)
+
+ push %rdi
+ mov %rsi, %rdi
+ mov $0, %eax
+ call printf
+ pop %rdi
+
+ inc %rdi
+ jmp 0b
+5:
+ ret
int asm_strcmp (const char* s1, const char* s2);
int asm_strncmp(const char* s1, const char* s2, int n);
+int asm_main(const char* asm_code);
+
int main(int argc, char* argv[])
{
if (argc < 4) {
return -1;
}
+ printf("' ':%d, ',':%d\n", ' ', ',');
+
printf("strcmp: %d, strncmp: %d\n",
asm_strcmp (argv[1], argv[2]),
asm_strncmp(argv[1], argv[2], atoi(argv[3])));
+
+ char asm_code[] = "mov rax,rdx\n";
+
+ int i;
+ for (i = 0; i < sizeof(asm_code); i++)
+ printf("asm_code[%d]: %d\n", i, asm_code[i]);
+ asm_main(asm_code);
return 0;
}