Printing out a simple string in a routine replacing a character in it

Started by Huskypaw, May 29, 2009, 09:25:37 PM

Previous topic - Next topic

Huskypaw

I'm sorry I have to say that your post didn't help me because my lack of intelligence maybe. But I found an example at emu8086 which I expanded to the following procedure:
;******************************************************
; procedure for reading a string from keyboard and
; cut off the control bytes to place it correctly into
; DS:DX.
; input: DS:DX
; output: DS:DX
; changed registers: AX, BX, CX
;******************************************************
readString PROC NEAR
push ax
push bx
push cx
mov ah,0Ah
int 21h
mov di, dx
xor bx,bx
mov bl,[di + 1]
mov byte ptr [di + bx + 2], '$'
mov cx,bx
xor bx,bx
transfer:
mov al, byte ptr [di + 2 + bx]
mov [di + bx], al
inc bx
cmp bx,cx
jle transfer
pop cx
pop bx
pop ax
ret
readString ENDP


You just have to pass the relative adress of the memory you want to store your string into by
mov dx, offset stringIWantToStoreMyInput
before
call readString.
Explanation:
After
mov ah,0Ah
int 21h

the first two bytes of the stored input are control bytes which the first from carries the length of the input (I don't know what's the second control byte for). Before cutting off the two control bytes I put a '$' at the end of the input to make a string out of it. In transfer finally I cut off the two control bytes by copying byte for byte beginning at the position of the first control byte.

I don't know if this is efficient though.. At least it works!

MichaelW

The first byte of the buffer "specifies the maximum number of characters, including the carriage return, to be copied to the buffer. This value, set by the program, must not exceed 255."

The second byte of the buffer "receives the actual number of characters copied to the buffer, not counting the carriage return. The function sets this value."
eschew obfuscation