x86 - 使用stosb lodsb的Gas / AT& T / Linux问题

时间:2013-12-03 16:09:06

标签: assembly x86 gas att

我在一段时间后发布了一个问题,但我想我会开始一个新线程,因为代码完全改变了。我试图将字节字符串存储到malloc创建的内存地址中。从终端执行程序时,我得到:

Loaded into eax: 49

我一直在跟英特尔manual(pdf)完全一样(或至少我认为)。 Page 175通用寄存器字符串指令。

    .global main
.text
str: .string "Loaded into eax: %d\n"
one: .string "1"

main:
pushl   $4          #push size of malloc
call    malloc      #call malloc
popl    %ecx        #clear malloc size off of stack
movl    %eax, %edi  #move address to destination
movl    %edi, %ecx  #
movb    one, %al    #move a 1 into %al
stosb               #store the 1 in %al to the address in destination
movl    %ecx, %esi  #move address to source for lodsb
movl    $0, %eax     #clear eax register
lodsb               #load content of (%esi) into %eax
pushl   %eax        #push that content onto stack
pushl   $str        #push string format onto stack
call    printf      #call printf
popl    %ecx        #clear stack
popl    %ecx        #clear stack
end:

0 个答案:

没有答案