CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Location
    Tennessee
    Posts
    46

    [RESOLVED] Read in an Integer?

    Hi, I am having trouble when I read in an integer from the keyboard and I try to display it to the screen back as the same integer. It pops out as an ASCII character. Am I doing this wrong or is there a way to read it as an integer and not a character, or do I need to convert it back? This program is using C calls. Thanks
    Code:
    ; Compiling this code for 32-bit use:
    ;    nasm -f elf file.asm
    ;    gcc -m32 -o file file.o
    ;
    ;~.~. Definitions for readability: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
            %define  SYS_EXIT   1
            %define  SYS_READ   3
            %define  SYS_WRITE  4
            %define  STDIN      0
            %define  STDOUT     1
            %define  STDERR     2
            %define  MAX_NUMBER   5000
    SECTION .data
    format: db "The number is %d." , 10
    SECTION .bss
    input: resd MAX_NUMBER
    SECTION .text
    extern printf
    global main
    main:
    nop
    GetInput:
            mov EAX, SYS_READ
            mov EBX, STDIN
            mov ECX, input
            int 80H
            mov DWORD[input + EAX - 1], 0
    Calculate:
            mov EAX, DWORD[input]
    Display:
            push EAX
            push format
            call printf
            add ESP, 8
            ret

  2. #2
    Join Date
    Oct 2011
    Location
    Tennessee
    Posts
    46

    Re: Read in an Integer?

    K I have solved this using scanf() C call thanks to all who were working on this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured