在汇编AMD64,我调用fprintf但它一直无限循环 [英] In assembler AMD64, I call fprintf but it keeps looping infinitely

查看:371
本文介绍了在汇编AMD64,我调用fprintf但它一直无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个具有fprintf中,我只是不能把握的问题。也许你可以找到一个解决这个问题。

您看到的,当我调用fprintf它开始无限循环,没有很好的理由。
我不知道发生了什么事情在这里,所以也许你可以给我一只手。

  String_int:
    91分贝; [
    DB 37; %
    DB 115;I
    93分贝; ]
    DB 0; end_stringw_IN_ASCII:
    DB 119; W
    DB 0; end_string<有的code>    MOV RDI,FILE_LOCATION;
    MOV RSI,w_IN_ASCII;
    调用fopen;
    MOV R15,RAX;    CMP R15,0; (这个我可以肯定这不是一个NULL)
    JE .endProgram;    MOV RDI,R15;
    MOV RSI,String_int;
    MOV RDX,TO_PRINT_LOCATION;
    调用fprintf;这是我的code死亡    MOV RDI,R15;
    调用FCLOSE;.endProgram:
    RET


解决方案

在System V的AMD64 ABI,可变参数的功能期待可变参数在的实际数量。我没有看到你设置它。

I'm a having a problem with fprintf which I just can't grasp. Maybe you can find a solution to this problem.

You see, When I call fprintf it starts looping infinitely, for no good reason. I have no idea what's going here, so perhaps you can give me a hand.

String_int:
    db 91; "[" 
    db 37; "%"
    db 115;"i"
    db 93; "]" 
    db 0;  "end_string" 

w_IN_ASCII:
    db 119; "w" 
    db 0;  "end_string" 

<SOME CODE>

    mov rdi, FILE_LOCATION;
    mov rsi, w_IN_ASCII;
    call fopen;
    mov r15, rax;

    cmp r15, 0; (with this I can be sure it is not a NULL)
    je .endProgram;

    mov rdi, r15;
    mov rsi, String_int;
    mov rdx, TO_PRINT_LOCATION;
    call fprintf; this is where my code dies

    mov rdi, r15;
    call fclose;

.endProgram:
    ret

解决方案

In System V AMD64 ABI, variadic functions expect the actual number of variadic arguments in al. I don't see you setting it.

这篇关于在汇编AMD64,我调用fprintf但它一直无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆