View Single Post
Old May 19th, 2006, 4:32 PM   #27
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>jmp calc
There's no need for this unless you're jumping over something. Since calc is the next thing in the source, execution will fall through to it without your help.

>jnz calc
jne would make your intentions more obvious.

>add save,10
This doesn't make sense.

>mov al,00
You forgot the int 21h to terminate your program.

One big issue is the infinite loop you're going to cause by entering strings longer than two characters. Since you test the loop condition at the bottom, after you copy to save, entering something like 123 will actually cause '1', '2', 3', 10 to be written to memory. That erases the last '$', and 09h will just keep going until it finds a '$' somewhere else in memory. So you need to use a top testing loop to avoid writing the carriage return to save:
save db 4 dup '$'

start:
	mov	di,0

    calc:
	mov	ah,01
	int	21h
	cmp	al,13		; Test for CR first
	je	show
	mov	[save+di],al
	inc	di
	jmp	calc

    show:
	mov	ah,02h
	mov	dl,10
	int	21h

	; Display the result
	mov	ah,09h
	mov	dx,save
	int	21h

    fini:
	mov	ah,4CH
	mov	al,0
	int	21h
An alternative since a top testing loop uses an extra jump instruction, one at the top and one at the bottom, you can move that extra jump outside of the loop by using a bottom testing loop with a condition part:
save db 4 dup '$'

start:
	mov	di,0
	jmp	compare

    calc:
	mov	[save+di],al
	inc	di

    compare:
	mov	ah,01
	int	21h
	cmp	al,13
	jne	calc

    show:
	mov	ah,02h
	mov	dl,10
	int	21h

	; Display the result
	mov	ah,09h
	mov	dx,save
	int	21h

    fini:
	mov	ah,4CH
	mov	al,0
	int	21h
That's slightly more efficient, but it's also harder to follow.

>do you do as a career Narue?
I'm a professional programmer, yes. I tend to use assembly more than many programmers, but most of my work is in C and C++.
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote