【发布时间】:2013-04-28 18:54:21
【问题描述】:
我对汇编编程很陌生,我用 C 语言编写了一个函数,它需要在汇编中调用另一个函数。似乎寄存器想要返回四个字符(字节)而不是一个,这就是我想要的。
跳转后忽略代码,因为我跳转只是为了跳过这部分代码,直到我让它正常工作。
这实际上应该是我自己的 C 语言简化版 sprintf 的一部分。
我删除了一些代码只是为了让事情正常工作。它应该返回带有% 的第一个参数。所以,当我在 C 中调用这个汇编函数时,我可以写 printf("%s", res);(或在本例中为 %c)并打印 %:
.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
【问题讨论】:
标签: c linux assembly cpu-registers