内联汇编FreeBSD中的gettimeofday

内联汇编FreeBSD中的gettimeofday

本文介绍了内联汇编FreeBSD中的gettimeofday的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 对不起,我的英语.
  2. 感谢每个答案.

我在C和内联汇编中有以下代码,它们应该执行函数调用:int gettimeofday(struct timeval * tp,struct timezone * tzp);

I've got a following code in C and inline assembly which should do the call of function: int gettimeofday(struct timeval *tp, struct timezone *tzp);

val = (struct timeval*)malloc(sizeof(struct timeval));
zone = (struct timezone*)malloc(sizeof(struct timezone));

__asm__("push $0;"
        "push %2;"
        "push %1;"
        "movl $116, %%eax;"
        "int $0x80;"
        :"=r"(val)
        :"r"(val),"r"(zone)
        :"%eax");

问题是,我不知道为什么需要使用这行"push $ 0;" ,而我的老师说,我的论证顺序不正确,这很幸运可以.

The problem is, that I don't know why I need to have this line "push $0;" and my teacher said, that my arguments are not in correct order and it's just luck that it works.

如何更改此代码以使其正确?为什么会有"push $ 0;" (如果以某种方式正确)?

How should I change this code to make it correct? Why is there "push $0;" if is it somehow correct?

推荐答案

因此,感谢 Daniel Kamil Kozar ,我发现删除malloc-s的问题.我的老师对命令的处理是正确的,但是它也在malloc-s中.Malloc只是用垃圾"给内存,所以calloc可以.我将zone设置为零值,并且可以将 push $ 0; 移到其他2下.

So, thanks to Daniel Kamil Kozar I found the problem deleting malloc-s. My teacher was bit right with order, but it was in malloc-s too. Malloc is just giving memory with "garbage", so calloc would be okay. I set zone to zero values and i could move push $0; under other 2.

这篇关于内联汇编FreeBSD中的gettimeofday的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:00