我已经用 c 编写了一个程序并将其转换为 arm 汇编,现在我在理解汇编代码中生成的一些指令时遇到了问题。C程序的一部分是:
#define MAX_DIGIT 1024
int main()
{
int fd[MAX_DIGIT];
int xLen = 0;
int sd[MAX_DIGIT];
int yLen = 0;
int result[6*MAX_DIGIT];
// Take input for two numbers
takeInput(fd, &xLen);
takeInput(sd, &yLen);
...
...
...
}
...
...
...
void takeInput(int digit[], int *length)
{
char c;
if((c=getchar()) != '\n' && *length <= MAX_DIGIT){
takeInput(digit, length);
digit[*length] = c - '0';
(*length)++;
}else return;
}
我已使用 gnu arm 工具链将此 c 代码转换为 arm 汇编代码。生成的汇编代码的一部分是:
main:
@ args = 0, pretend = 0, frame = 32788
@ frame_needed = 1, uses_anonymous_args = 0
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
sub sp, sp, #32768
sub sp, sp, #20 @Why subtracted 20?
mvn r3, #4096
sub r3, r3, #3
@What r3 storing and Why took NOT of r3 and again subtract 3 from it?
mov r2, #0
sub r0, fp, #12
str r2, [r0, r3]
mvn r3, #8192
sub r3, r3, #7
mov r2, #0
sub r1, fp, #12
str r2, [r1, r3]
sub r2, fp, #4096
sub r2, r2, #12
sub r3, fp, #4096
sub r3, r3, #12
sub r3, r3, #4
mov r0, r2
mov r1, r3
bl takeInput
sub r2, fp, #8192
sub r2, r2, #12
sub r2, r2, #4
sub r3, fp, #8192
sub r3, r3, #12
sub r3, r3, #8
mov r0, r2
mov r1, r3
bl takeInput
mvn r3, #32768
sub r3, r3, #11
mov r2, #1
sub ip, fp, #12
str r2, [ip, r3]
我在评论中的汇编代码本身中标记了我的点。谢谢。