2015-05-14 79 views
1

im装配8086新的和即时通讯尝试实现一个计算器的程序集。装配打印一个简单的计数器

我需要统计从用户收到的操作次数,并在最后打印。 但每次我试图打印我的变量值时它打印:的134520956代替1. (我用gdb检查,我写道:MOV EAX [operator_count]和 EAX的值为1根据需要)

这是代码:

section .rodata 
INT_FORMAT: 
      DB "%d", 10, 0 

section .bss 
    operator_count: 
      resb 10 

main: 
mov [operator_count], dword 0 
; rest not relevant....... 

inc dword [operator_count] 
push operator_count     ;push string to stuck 
push INT_FORMAT 
call printf    
add esp, 4    ;remove pushed argument 

;exit normaly 

感谢您的帮助......

编辑: 现在工程:)

inc dword [operator_count] 
push dword [operator_count]     ;push string to stuck 
push INT_FORMAT 
call printf    
add esp, 8    ;remove pushed argument 
+3

'push operator_count'推送地址,而不是值。改为尝试'push dword [operator_count]'。 – Jester

+0

哈哈。 是的,它现在有效。 – lolu

+0

非常感谢! beah, – lolu

回答

1

push operator_count推送地址,而不是值。改为尝试push dword [operator_count]。 - Jester