我有以下汇编代码:
间接1.s
.section .data
t1:
.long 5
.section .text
.globl _start
_start:
movl $t1, %ecx #we are passing the address to %ecx
movl $5, %eax #we are passing value 5 to %eax
movl (%ecx), %ebx #Using indirect addressing mode we are getting the value from t1 and passing it to ebx
addl %eax, %ebx # add the values in %eax, %ebx and store it in %ebx
movl $1, %eax # call exit program
int $0x80 # Call Master Bruce Wayne
当上面的程序运行时,我得到了预期的值 10
[ashok@localhost asm-32]$ as indirect1.s -gstabs+ -o indirect1.o
[ashok@localhost asm-32]$ ld indirect1.o -o indirect1
[ashok@localhost asm-32]$ ./indirect1
[ashok@localhost asm-32]$ echo $?
10
修改上述程序以消除 %ecx 寄存器:
间接2.s
.section .data
t1:
.long 5
.section .text
.globl _start
_start:
movl $t1, %ebx # we are passing the address to %ebx
movl $5, %eax # we are passing value 5 to %eax
addl %eax, (%ebx) # add the values in %eax, %ebx and store it in %ebx
movl $1, %eax # call exit program
int $0x80 # Call Master Bruce Wayne
当我运行上述程序时,我没有得到预期的输出,即 10,而且我似乎得到了存储在 %ebx 中的地址
[ashok@localhost asm-32]$ as indirect2.s -gstabs+ -o indirect2.o
[ashok@localhost asm-32]$ ld indirect2.o -o indirect2
[ashok@localhost asm-32]$ ./indirect2
[ashok@localhost asm-32]$ echo $?
136
我在indirect2.s 程序中做错了什么。