我是 80386 汇编语言的新手。目前正在努力完成一项学校作业,要求用汇编语言编写一个将在 ac 程序中调用的函数。
extern int count(char *string, char c);
我想我知道应该如何做到这一点,但仍在努力选择正确的指令(指令以“b”、“w”或“l”结尾),也许还有“正确”的寄存器,我知道有一些为某些目的而保留的。
.text
.global count
count:
pushl %ebp # set up stack frame
movl %esp,%ebp # save %esp in %ebp
subl $12, %esp # automatic variables
movl $0, %eax # initialize %eax to 0
movl 8(%ebp), %esi # pointer to s
movb 12(%ebp), %bh # pointer to c
check:
movb (%esi), %bl # move the first char in s to %bl
cmp 0, %bl # if the char is \0 …Run Code Online (Sandbox Code Playgroud)