lolu
lolu

Reputation: 370

Assembly printing a simple counter

im new in assembly 8086 and im trying to implement a calculator in assembly.

i am required to count the number of operation received from user, and print at the end. but every time i tried to print my variable value it prints : 134520956 instead of 1. ( i checked with gdb, I wrote: mov eax [operator_count] and the value of eax was 1 as required)

this is the code:

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

thanks for help...

edit: it works now :)

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

Upvotes: 1

Views: 719

Answers (1)

Armali
Armali

Reputation: 19375

push operator_count pushes the address, not the value. Try push dword [operator_count] instead. – Jester

Upvotes: 1

Related Questions