How to temporarily store values in a row in assembly?
Question
I'm making a 16-bit real mode operating system and I want to pass commands that the user types in. I can do input but I'm not sure how to store the resulting string so that it can later be parsed. Is there a better way than just putting each character onto the stack and then pop and reverse them when they want to be used?
My main loop:
mainLoop:
mov bx, s_PROMPT
call printStr ; print the 'MOOS> ' prompt
inputLoop:
call getKeyPress ; wait for the user to press a key
call printChar ; print the pressed key so the user can
; see what they've typed
push bl???
cmp bl, 0xD ; 0xD = 13 = ASCII code for enter
jne inputLoop ; go to inputLoop if does not equal enter
call newLine
jmp mainLoop
The operating system is called MOOS by the way.
Thanks to anyone who can help.
Solution
Your stack looks like this aftereach push:
00: 's' - Assume that here starts your string by pusing each char
01: 't'
02: 'r'
03: 'i'
04: 'n'
05: 'g'
06: - Here is your stackpointer after the string has been completed.
So you simply store the current stackpointer somewhere (here it is 0). Either count the length while your are pusing chars, or subtract the current stack from your saved value to get the length, and copy it somewhere. You might need to add a 0 byte or store the length along with the string, depending on how your strings are organized. Of course you can also use the string directly without the need to copy it.
After you are done with it, just reset the stack pointer to the original value 0
and you are done.