0

I want be able to print a number using the following asm program but I am unable to and on running it, I do not get 3 as an expected output, why?

section .data
        count equ 3

section .text
        global _start

_start:
        mov eax,4
        mov ebx,1
        mov ecx,count
        mov edx,1
        int 80h

        mov eax,1
        int 80h 

Pawan Nirpal
  • 565
  • 1
  • 12
  • 29

2 Answers2

1
 count equ 3

Because count was defined being an equ, count in your program represents the value 3 and nothing more.

Now the api call that you use for printing expects in ECX the address in memory where you have stored the number 3.
You should use the following that reserves in the .data section room for a byte with the ASCII value for the digit that displays as 3:

section .data
        count db "3"

section .text
        global _start

_start:
        mov eax,4
        mov ebx,1
        mov ecx,count
        mov edx,1
        int 80h

        mov eax,1
        int 80h
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
0

This is because you are passing the number 3, not a pointer to the character "3".

This is a link to an ascii table: https://www.asciitable.com/

Here's a similar stack article: How to print a single ASCII char?

vitsoft
  • 5,515
  • 1
  • 18
  • 31
ecmgs
  • 1