C相同stdarg头文件

C相同stdarg头文件

本文介绍了大会,多个参数-m32 / Linux的(C相同stdarg头文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要解决这个问题,我的理解C和我仍然在议会的初学者,所以我有点坚持在这里一个小问题。

我在遇到一些麻烦把多个参数,也许算来,如果我应该做的,在我的组装code使用的格式参数。

尝试一些字节添加到许多参数的字符串。我知道如何把前两个参数的堆栈上,但第一次后,其他参数是格式(如%S,%D,%C等),第一个参数是,应该是变量i之一要写入。
在C语言中,标准的主要有说法计数器。我可能要在这里藏汉算参数!?我怎么能做到这一点,如果这是它是如何做?

  .globl minisprintf#名称:minisprintf
#剧情简介:一个简化的sprintf
#C-签名:INT minisprintf(无符号字符*资源,无符号字符*格式,...);
#寄存器:AL:查找字符
#%ECX:第一个参数,资源
#%EDX:第二个参数,ARGS
#minisprintf:#minisprintf    pushl%ebp的排名开始
    MOVL%ESP,EBP%#函数    MOVL 8(EBP%),ECX%#第一个参数
    MOVL 12(%EBP),EDX%#第二个参数
                                #其他参数
                                #检查字符串资源的最后一个字节


解决方案

可变参数函数是C的功能,所以你可能会被检查出提供最好的服务是如何的开放源代码实现的的va_start 的va_arg va_end用来的架构/ ABI你感兴趣的内容。

您不必为的printf 般的功能明确的参数个数,因为这些信息嵌入在格式字符串 - 一个可变参数的数量和类型期望由格式说明的数目和细节给出

您的将会的需要了解您的ABI的过程调用方面为pretty严重细节让这一切工作正常。例如,做浮点和整数参数去同一个堆栈,或者是一些在寄存器中传递?你需要什么尺寸,以促进类型,以确保您的的va_arg 相当于总能得到合适类型的正确的事在正确的时间?等等...

To solve this, I understand C, and I'm still a beginner in Assembly so I'm kinda stuck with a little problem here.

I'm having some trouble with taking multiple arguments, maybe count them if I should do that, and use the format arguments in my assembly code.

Trying to add some bytes to a string with many arguments. I know how to put the two first arguments on the stack, but the other arguments after the first is the format (like %s, %d, %c etc) and the first argument is the one that is supposed to be the variable i want to write to.In C, standard main has argument-counter. I might want to count the arguments here aswell!? How can I do that, if that's how It's done?

     .globl minisprintf

# Name:         minisprintf
# Synopsis:     A simplified sprintf
# C-signature:      int minisprintf(unsigned char *res, unsigned char *format, ...);
# Registers:        AL: for characters
#                 %ECX: first argument, res
#                 %EDX: second argument, args
#



minisprintf:                    # minisprintf

    pushl       %ebp            # start of
    movl        %esp, %ebp      # function

    movl        8(%ebp), %ecx   # first argument
    movl        12(%ebp), %edx  # second argument
                                # other arguments
                                # checking last byte of string res
解决方案

Variadic functions are a C feature, so you might be best served by checking out how an open-source implementation of va_start, va_arg, and va_end for the architecture/ABI you're interested in.

You don't need an explicit argument count for a printf-like function, because that information is embedded in the format string - the number and types of the variadic arguments to expect are given by the number and details of the format specifiers.

You will need to understand the procedure-call aspects of your ABI is pretty serious detail to get all of this working correctly. For example, do floating point and integer arguments go to the same stack, or are some passed in registers? What size do you need to promote types to to make sure that your va_arg equivalent always gets the right thing for the right type at the right time? And so on...

这篇关于大会,多个参数-m32 / Linux的(C相同stdarg头文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 12:03