whats wrong with my code?

.model small
.stack
.data

buffer db 10,?, 10 dup(' ')

.code

main proc

mov dx, offset buffer
mov ah, 0ah
int 21h

xor bx,bx

mov bl, buffer[1]
mov buffer[bx+2], '$'
mov dx, offset buffer + 2
mov ah,09
int 21h
ret

mov ah,4ch
int 21h

main endp
end main

Recommended Answers

All 6 Replies

You aren't saying what's happening, and you aren't mentioning your toolset.

See if <buffer> is in its own segment or sitting at 0100h in the code instruction pointer path!

buffer db 10,?, 10 dup(' ')

	; Get Buffered Keyboard input
	mov dx, offset buffer
	mov ah, 0ah   ; Command Buffered Keyboard Input
	int 21h      ; DOS interrupt
          ; 0:bufsize, 1:char count, 2...N buffer

	xor bx,bx
	mov bl, buffer[1]

;	mov buffer[bx+2], '$'
	mov buffer[bx+1], '$'    ; Replace carriage return with terminator

	mov dx, offset buffer + 2
	mov ah,09
	int 21h
;;;;	ret

	mov ah,4ch
	int 21h
commented: Nice to see someone with knowledge of ASM +27

sorry im using masm32 ml to asamble link16 to link

i can type something but when i hit enter the proc exits and does not
show the typed text

Hello xelos,
Please, surround your code with the code tags, like this: [ code=asm ] [ /code ] , but without the spaces.
This is just to understand better your code, put highlighting and be more organized.

Thanks,
Nathan Paulino Campos

Just to be safe, move the data below the code! You're using the newer MASM32 (which I don't like, I still use MASM) with a 16-bit linker which implies you're making 16-bit Real Mode code.

I've used masm32 only for debugin stuff, I usually assemble my own code so I can have it be more efficient, even though its a time waster.

I looked at what you got, there's nothing wrong with it, so i debugged it, and I saw that the values of the DS and CS when the program was loaded are different, and when I assembled it with the linker, it sticks both the code section and the data section together, so the address being loaded into the DX register was pointing to the wrong data,

Try sticking this in before you start:

mov ax,cs
mov ds,ax

also, it looks like you are not giving your program a time where it will wait to show you the result, you might want to add a keyboard wait after you have the string displayed back like:

mov ah,00h
int 16h

I tried it, it worked, but it may look like it doesn't do any thing, because the string that is typed into the buffer is cleared from the screen after it is inputted, so it looks as though nothing really happens, but its working.

bits 16
org 100h

jmp start
buf db 32,0
times 32 db 0
start:
mov dx,buf
mov ah,0ah ;you called function 0ah correctly
int 21h
;you terminated the string and used function 09h correctly
mov bl,[buf+1]
xor bh,bh
mov byte [bx+buf+2],24h
mov dx,buf+2
mov ah,09
int 21h
int 20h
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.