News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Add to String Content?

Started by paulfaz, October 27, 2006, 03:44:11 PM

Previous topic - Next topic

paulfaz

Hi All, im back again!!!

Ive got another issue now... and google has failed me this time again.

Im attempting to write an ASM version of the old DoS "copy con" command, where you can write stuff in the console and output it to a file etc...

So far written my own procedures for dealing with backspaces and ctrl+z...

Because im using INT 16h and Function 00h to read a single key at a time, im waiting for a carriage return, and if its anything other, then jumping back to the beggining and getting another keypress..

During this phase, i want to store what is typed in a variable or register and have no idea how to do it, or where to start.  If possible i would like some assistance on this...

For example in VB, i would do something to the effect of a=a & "r"

This is what ive got so far....




_get_keybinput proc

getchar:
MOV AH, 00h ;Get Next Char from Keyboard
INT 16h

MOV DL, AL ;Save input into DL
MOV AH, 02h ;Print to Screen
CMP DL, 1Ah ;Check for CTRL+Z
JE _exit_dos
CMP DL, 0Dh ;Check for Enter
JE return
INT 21h
CMP DL, 08h ;Check for Backspace
JE backspace
JMP getchar

return:
RET

backspace:
MOV AH, 0Fh ;Function to Get Page
INT 10h ;Get Current Page
MOV pge, BH ;Store the current Page in pge

MOV AH, 03h ;Get XX,YY Cursor Position
MOV BH, pge ;Use previously stored Page
INT 10h

SUB DL, 1
MOV yy, DH ;Store the Y co-ord in yy
MOV xx, DL ;Store the x co-ord in xx

MOV AH, 02h ;Print a NULL char to the screen
MOV DL, 00h ;00h = NULL
INT 21h ;Execute

MOV AH, 02h ;Set Cursor pos
MOV BH, pge
MOV DL, xx
MOV DH, yy
ADD DL, 1
INT 10h
JMP getchar ;Jump Back to receiving Chars


_get_keybinput endp



_exit_dos proc
XOR DX, DX
MOV AH, 4ch
INT 21h
_exit_dos endp



During the getchar: operation i want to load each char into a string, ive seen a couple of bits of code, whilst the poster has been explaining something completely differint that just confuse me greatly...


MichaelW

If a 253 character limit were acceptable (allowing one character for ^Z and one for the terminating CR), this would be much easier to do with the Buffered Input function. When the function returned the input string would be in the buffer starting at offset 2.

To answer your question, to load each character into a string one simple method would be to load the starting offset address of the string buffer into DI, then for each character use STOSB to store the character in AL to the buffer. Or, instead of STOSB you could use:

mov [di], al
inc di
eschew obfuscation

eek

I was thinking the same thing.
The keyboard buffer will hold your string.

mov ah,0A
int 21

or you can use int16 to write onscreen via stosw and check the input for things like ENTER

input1
int 16
cmp al,0D          ;<-look for ENTER
ifz-jmp Fopen     ;conditional jump
mov ah,0F
stosw               ;prints at ES:DI and increments DI
jmp input1

paulfaz

Excellent guys, many thanks for your help.

I went with the stosb, as its a function ive not used yet... took me a while to get it going like, but it does the trick...

Cheers.

Whats the activity like on here aswel? i couldnt seem to find a decent ASM forum, apart from this, but although you lot av responded to my issues there doesnt seem to be a lot of posts?

lol, i can soon sort that out... stay tuned for my next issue.

eek

I get the impression that us 16bit guys are minority freaks, there isnt much around really.

A cross-dressing forum would probably get more activity, but I think there are quite a few lurkers for this stuff.