当前程序接受命令行参数并将它们打印到屏幕上,用 gcc 编译。堆栈包含指向接收到的参数的地址。我需要转换两个参数,将它们相加并打印结果。
我试过通过像这样取消引用寄存器来添加值:
movl (%edi), %edi
addl %edi, (%esi)
我也试过减去“0”来转换字符串
sub "0", (%esi)
我的部分代码是:
printLoop:
movl 12(%ebp), %esi # Get **argv pointer to the vector table
movl (%esi,%ebx,4), %esi # Use the pointer to indirectly load the address of the
# next command line argument. %ebx is the index
incl %ebx
movl 12(%ebp), %edi
movl (%edi, %ebx, 4), %edi #pointer to next arg in edi?
#sub "0", (%esi)
movl (%edi), %edi # don't work
addl %edi, (%esi) # don't work
call printString # print the null terminated command line argument
movl $newLine, %esi # go to the next line
call printString # prints the arg
我也试过在
%edx
中保存第二个arg的值然后添加,它不起作用。