在SPARC装配参数的printf格式说明? [英] printf format specifier in SPARC assembly argument?

查看:201
本文介绍了在SPARC装配参数的printf格式说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让这款C与SPARC汇编等价的:

How do you get the equivalent of this C with SPARC assembly:

printf( "Hello, my name is %s.\n", name );

使用函数原型:

void printName( const char* msg, const char* name )

,其中味精是你好,我的名字为%s \\ N。

where msg is "Hello, my name is %s.\n".

我知道我可以定义你好,我的名字为%s \\ N与.asciz数据段,而不必第一个参数味精,但有没有办法将字符串传递到汇编函数那会在它%的标识符?可一个char *甚至采取在格式标识符?我试过以下,但我得到一个核心转储。

I know that I can define "Hello, my name is %s.\n" in the data segment with .asciz without having the first argument msg, but is there a way to pass a string into an assembly function that would have a %s identifier in it? Can a char* even take in a format identifier? I've tried the following but I get a core dump.

用C 函数调用:

char * msg = "Hello, my name is %s.\n";
char * name = "Foo";

printName( msg, name );

大会:

mov %i0, %o0
mov %i1, %o1
call printf, 2
nop

也许我不能正确地接近函数原型?

Maybe I'm not approaching the function prototype correctly?

推荐答案

我其实不安静知道你做错了,但下面的程序工作,因为它应该:

I am actually not quiet sure what you are doing wrong, but the following program works as it should:

        .data
s0:     .asciz  "foo %s\n"
s1:     .asciz  "bar"
        .text
        .global main
main:
        save    %sp, -96, %sp
        set     s0, %o0
        set     s1, %o1
        call    prtnam
        nop
        ret
        restore
prtnam:
        save    %sp, -96, %sp
        mov     %i0, %o0
        call    printf
        mov     %i1, %o1
        ret
        restore

关于参数的传递,少数像这样在寄存器中传递的参数。

Regarding the passing of arguments, a small number of arguments like this are passed in registers.

这篇关于在SPARC装配参数的printf格式说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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