我有这个计算一些素数的汇编代码:
#include <stdio.h>
int main() {
char format[] = "%d\t";
_asm{
mov ebx, 1000
mov ecx, 1
jmp start_while1
incrementare1:
add ecx, 1
start_while1:
cmp ecx, ebx
jge end_while1
mov edi, 2
mov esi, 0
jmp start_while2
incrementare2:
add edi, 1
start_while2:
cmp edi, ecx
jge end_while2
mov eax, ecx
xor edx, edx
div edi
test edx, edx
jnz incrementare2
mov esi, 1
end_while2:
test esi, esi
jnz incrementare1
push ecx
lea ecx, format
push ecx
call printf
pop ecx
pop ecx
jmp incrementare1
end_while1:
nop
}
return 0;
}
它工作正常,但我还想在 asm 中声明“格式”字符串,而不是在 C 代码中。我曾尝试添加类似 format db "%d\t", 0
的内容,但没有成功。
最佳答案
如果一切都失败了,总会有丑陋的方式:
format_minus_1:
mov ecx,0x00096425 ; '%', 'd', '\t', '\0' in little-endian format
lea ecx,format_minus_1 + 1 ; skip past the "mov ecx" opcode
push ecx
call printf
关于c - 在汇编中声明一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14488269/