-
November 12th, 2012, 07:53 PM
#1
[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
-
November 13th, 2012, 08:58 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|