具体过程如下所示:
二 使用x64汇编调用c语言printf函数代码内容
x64_call_function.asm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| ;x64_call_function includelib ucrt.lib includelib legacy_stdio_definitions.lib
extern printf:proc
.data String db 'HelloWorld',0 Format db '%s',0 .code main proc sub rsp,28h lea rdx,String lea rcx,Format call printf add rsp,28h ret main endp end
|
三 使用x64汇编调用c语言printf函数循环打印代码内容
x64_call_function_loop.asm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| ;x64_call_function_loop.asm includelib ucrt.lib includelib legacy_stdio_definitions.lib
extern printf:proc
.data Format db 'how you doing ',0
.code main proc sub rsp,28h xor rsi,rsi xor rbx,rbx mov rsi,64h mov rbx,0 jmp loopN LoopC: inc rbx loopN: mov rdx,rbx lea rcx,Format call printf cmp rsi,rbx jae LoopC add rsp,28h ret main endp end
|
扩展:
汇编语言中常量0DH和0AH在ASCII码表中分别表示回车和换行控制字符,其作用相当于c语言中的”\n”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| ;x64_printf_line_feed.asm includelib ucrt.lib includelib legacy_stdio_definitions.lib
extern printf:proc
.data String db 'how you doing',0 Caption db 'Caption',0 line_feed db "line feed on later",0dh,0ah
.code main proc sub rsp,28h
lea rcx,line_feed call printf lea rcx,String call printf
add rsp,28h ret main endp end
|