NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nobody on February 07, 2008, 01:07:01 AM
-
Hey all,
Trying to use the Dos I/O function to read console input character by character. I have reserved a buffer using resb and I am trying to read characters into my buffer and then outputting. Any pointers on what I am doing wrong or how to achieve my goal will be appreciated. Here is a snip of my code.:
_main:
mov dx, [buffer]
mov si, dx ; point to input buffer
L1: mov ah, 1
int 21h
cmp al, 0Dh ; check for CR
je L2
mov [si], al ; store the character
inc si ; increment buffer pointer
loop L1
L2: mov BYTE [si], '$' ;insert null terminator
inc si ; increment buffer pointer
mov BYTE [si], 0Dh ; insert carriage return
L3: mov ah, 9
mov edx, buffer ; load buffer into edx
int 21h ; output buffer
When running this program I see error:
The NTVDM CPU has encountered an illegal instruction.
CS:022e IP:00df OP:ff ff 1e ff ff
Thanks in advance for any assistance.
-
The problem is in the second line:
_main:
mov dx, [buffer] ; <== This line will load DX with the first 32-bits stored at the address of "buffer".
mov si, dx ; point to input buffer
Change it to:
mov dx,buffer
then you are storing the address. The address you are loading into dx and si (ie the value stored at buffer) is probably in an area of memory that you don't have access to, in which case this will fix the problem.
Debs