So, I was trying to re-create the CMD command "set /p", where it prompts the user to type text, and is ended by a carriage return.

Upon trying this, however, I found that a word (dw) will only hold the last thing passed to it. You can type "abcdefg", but the word will only hold the value "g".

What I'm trying to ask is, would there be a way to make it store everything typed, like.. create a string out of a series of characters?

I'm using NASM16 under a windows operating system.

[org 0100h]
%include "Library.asm"

[section .text]

START:
input 16	;Check if it's enter
je ENDLINE	;If equal, end the line
mov [store],al	;Mov AL's value into a variable
string store	;Display the variable
jmp START

ENDLINE:
string eol	;End the line
jmp START




[section .data]

store dw 0, "$"
eol db " ", 13, 10, "$"

...I found that a word (dw) will only hold the last thing passed to it. You can type "abcdefg", but the word will only hold the value "g"...

Right. store will always refer to the same memory location, so every time you write to it, whatever value was there is overwritten by the new value.

...What I'm trying to ask is, would there be a way to make it store everything typed, like.. create a string out of a series of characters?

As long as store only points at a single location, no.

What you want is a series of storage locations, with store pointing at the start... instead of dw 0 , do something like times 100 dw 0 . Then all you need is another variable to hold the address in which to store the next input character. Start it out pointing at store , and every time you read a character, load it into the location at the address of store plus the value of the variable, then increment the variable. That way all of the input characters are saved at different locations, and you have all of them.

Additional thoughts:

You don't have infinite space to keep recording characters, so you'll have to decide how much space to reserve and what happens if someone types more characters before they hit the carriage return.

Instead of defining store as a series of 0 bytes, try filling it with '$' --that way, no matter how many characters get typed in, there's always '$' after what was typed, so you get the string terminator for free. If you do it that way, you'll need one more '$' than your maximum character count; always save one for the end of the string.

Character values are coming in al , an 8-bit register, but you're using dw for storage, which is 16 bits... Maybe your Library.asm is looking for 16-bit characters, but if it isn't, consider db instead.

As to storing multiple things in a variable,
a word is really two contiguous bytes:

albl dw 0
;same as
albl2 db 0, 0

and can hold two asci values.
If we reserve room for an array of bytes:

albl2 times 64 db 0

albl2 is a label which represents a 16-bit offset, and
we can use it to index into the array, or pass
it as a parameter to 21/3F for example:

mov cx, 64
mov dx, albl2
mov bx, 0
mov ah, 0x3f
int 0x21

Great! You've really been helping me out on my projects, I really appreciate it. :)
I'll re-post my code once I get this setup correctly, but here is what I have as of now, try using ALT-NUMPAD ascii codes on it, I was surprised that those worked so easily.
As always, I am using my own library.. So you may see a few things you do not recognize.

[org 0100h]
%include "Library.asm"

[section .text]

START:
input 13		;Check if it's enter
je ENDLINE		;If equal, end the line
cmp al,1bh		;Check if ESCAPE
je exitall		;If it is, exit with errorlevel of 0
cmp al,8		;Check if BACKSPACE is pressed
je BACKSPACE		;Display ASCII character 8 if it is
mov [store1],al		;Mov AL's value into a variable
string store1		;Display the variable
jmp START

BACKSPACE:
mov dx,8h		;ASCII char 8 = backspace (Move cursor back one)
mov ah,02h		;Function 02h, display ASCII character
int 21h			;Call DOS to display it
string blank		;Display a " "

;This will move it back one place, for a proper effect
mov dx,8h		;ASCII char 8 = backspace (Move cursor back one)
mov ah,02h		;Function 02h, display ASCII character
int 21h			;Call DOS to display it
jmp START


ENDLINE:
string endline		;End the line
jmp START

exitall:
exit 0			;Exit with ERRORLEVEL of 0




[section .data]

store1 db 0, "$"
blank db " ", "$"
endline db " ", 13, 10, "$"

And I suppose it would be of benefit to post my library too.

;===========================================
;string - displays the string passed as an argument
;===========================================
%macro string 1
xor dx,dx
xor ah,ah
mov dx,%1		;Move the passed string into DX
mov ah,9		;Function 09h, display string
int 21h			;Call DOS

%endmacro
;===========================================



;===========================================
;exit - exits with passed errorlevel
;===========================================
%macro exit 1
mov  AH,4CH		;Terminate process DOS service
mov  AL,%1		;Pass this value back to ERRORLEVEL
int  21H		;Call DOS to exit

%endmacro



;===========================================
;input - asks for keyboard input and compares al for the key passed
;===========================================
%macro input 1
mov ah,0	;Keyboard input function
int 16h		;Call BIOS
cmp al,%1	;Compare AL for key passed	

%endmacro

;==========
;INPUT2 - asks for a keypress WITHOUT comparing AL
%macro keypress 0
mov ah,0	;Keyboard input function
int 16h		;Call BIOS

%endmacro



;===========================================
;arg - Gets the argument and passes it to DX
;===========================================
%macro arg 0
xor bx, bx 		;Zero out BX
mov bl, [cs:0x80]	;Get Command Tail Length
mov byte [bx+0x81],'$'	;Place a $ on command tail
mov bx, 0x82		;place offset of command tail in BX.
mov dx,bx		;Move offset into DX

%endmacro




;===========================================
;write - writes the string passed into DX
;Caller must pass:
;String or value into DX
;===========================================
%macro write 0
mov ah,9		;Function 9, display string
int 21h			;Call DOS to display it

%endmacro


;===========================================
;position - positions cursor
;===========================================
%macro position 2
mov dl,%1		;New X parameter
mov dh,%2		;New Y parameter
mov ah,02h		;VIDEO service 2: position cursor
mov bh,0		;Stay with display page 0
int 10h			;Call VIDEO

%endmacro

Edited 7 Years Ago by Goalatio: n/a

This question has already been answered. Start a new discussion instead.