我正在学习计算机基础课程,尝试理解汇编代码,并在C语言中创建了一个"hello world "程序并编译为汇编代码。我知道"mov r0,r3"将数据从寄存器3移动到寄存器0。但是,我该如何确定r3的值是多少呢?
以下是我正在使用的汇编代码:
.arch armv6
.eabi_attribute 27, 3
.eabi_attribute 28, 1
.fpu vfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 6
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "hello.c"
.section .rodata
.align 2
.LC0:
.ascii "Hello World\000"
.text
.align 2
.global main
.type main, %function
main:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 1, uses_anonymous_args = 0
stmfd sp!, {fp, lr}
add fp, sp, #4
ldr r0, .L2
bl printf
mov r0, r3
ldmfd sp!, {fp, pc}
.L3:
.align 2
.L2:
.word .LC0
.size main, .-main
.ident "GCC: (Raspbian 4.9.2-10) 4.9.2"
.section .note.GNU-stack,"",%progbits
以下是我的C代码:
// Hello World program in C
#include<stdio.h>
main()
{
printf("Hello World");
}
x=y
这样的 C 语句时,你如何确定 y 的值?这里也是同样的道理。 - n. m.r3
的用法。 - Margaret Bloomr3
具有从main()
返回的返回值,并且被放入r0
中。没有显式返回的main()
具有隐含的return 0
。但在OP的示例中,不能保证r3
包含0 - 也许他正在使用一个早于C99的编译器,因此它只返回任意值? - Michael Burr