我对汇编编程非常陌生,我在C中编写了一个函数,需要在汇编中调用另一个函数。看起来寄存器想要返回四个字符(字节)而不是一个,这正是我想要的。汇编程序和C编程linux -m32(从汇编程序中的寄存器中的字符字节)
忽略跳转后的代码,因为我只跳过这部分代码,直到我正确地工作。
这实际上应该是我自己的简化版本sprintf
的一部分在C 我删除了一些我的代码只是为了让事情工作。它应该返回第一个参数%
。所以,当我称之为C本汇编功能,我可以写(在这个例子中或%c
)printf("%s", res);
和它打印%
:
.globl printpercent
# Name: printpercent
# Synopsis: A simplified sprintf
# C-signature: int printpercent(unsigned char *res, unsigned char *format, ...);
# Registers: %eax: first argument
# %ebx: second argument
printpercent: # sprinter
pushl %ebp # start of
movl %esp, %ebp # function
movl 8(%ebp), %eax # first argument
movl 12(%ebp), %ebx # second argument
loop:
movb $37, %bl # lowest bits to %
movb %bl, %al
jmp exit
movb (%ebx), %dl #
cmp $0, %dl # Check if 0
je exit # if 0 -> exit
cmp $37, %dl # Check '%'
movb %dl, (%eax) # if it doesnt equal any above/or default
# add to register %eax
jmp loop # jump back to the start of the loop
exit:
popl %ebp # popping standard end of function
# 0-byte ?
ret # return
感谢,我想我现在解决它:) – 2013-05-05 14:33:14