954,490 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

cant get ah = 0ah to work!

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

xellos
Newbie Poster
11 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

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

See if 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
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
 

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

xellos
Newbie Poster
11 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

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

Nathan Campos
Junior Poster
190 posts since Jul 2009
Reputation Points: 33
Solved Threads: 6
 

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.

wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
 

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.

kevincarroll
Newbie Poster
7 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 
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
NotNull
Posting Whiz in Training
211 posts since Oct 2008
Reputation Points: 39
Solved Threads: 21
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You