Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help copying inputed string to a table

Status
Not open for further replies.

cb00

Programmer
Nov 8, 2002
2
0
0
US
TITLE Sort names entered from terminal (bsort.asm)

.MODEL small
.STACK 256

INCLUDE macs.inc

.DATA

nameprm label byte ;name prm list:
maxlen db 21 ; max length of name
namelen db ? ; # of char's entered
namefld db 21 dup(' '),'$' ; name & delimiter
; for displaying
crlf db 13, 10, '$'
end_addr dw ?
prompt db 'Name? ','$'
count db 0
name_tbl db 30 dup(20 dup(' ')) ; name table
name_sav db 20 dup(?), 13,10,'$'
did_excg db 0

.CODE

;---------------------------------------------------------
; the MAIN procedure

main proc
mov ax,@data ;init segment regs
mov ds,ax
mov es,ax
cld
lea di,name_tbl
ClearScreen
mov dx,0000
SetCur
mloop:
call name_in ;input name
cmp namelen,0 ;name entered?
jz @@30 ; if not goto sort
cmp count,30 ;30 names entered?
je @@30 ; if so goto sort
call sto_name ;store entered name in tbl
jmp mloop
@@30:
ClearScreen
mov dx,0000
SetCur
cmp count,1 ;one or no names entered?
jbe mexit ;if yes , then exit
call bsort
call dis_names ;display sorted names
mexit:
mov ah,4ch
int 21h
main endp ;end main procedure


im suppose to write the procedures for this.. but i cant figure out how to write the sto_name proc.. all i know is im suppose to use the rep movsw command please give me some hints if you can
 
i forgot to give you what i have so far

name_in proc ;input name

;ClearScreen
mov ah,09
mov dx, offset prompt
int 21h
mov ah,0ah
mov dx,offset nameprm
int 21h
ret

name_in endp

sto_name proc

mov cx, namelen
add di, count
lea si, namefld
rep movsb
add count,1
ret
sto_name endp

exchange proc

mov did_excg,1
ret
exchange endp

bsort proc

@@10: lea si,end_addr
@@20: mov did_excg,0
lea di, name_tbl
@@30: repe cmpsb
call exchange
inc di
cmp di,si
jne @@30
cmp did_excg,1
je @@20
ret

; if (table entry > next entry)
; exchange entries
; set did_exchg to 1
; increment for next entry in table
; if (at end of table)
; if (did_exchg) jump to @@20
; else end of sort
; else jump to @@30


bsort endp

dis_names proc
lea si,name_tbl
mov count,0
ClearScreen
L1:
mov cx,20
lea di,name_sav
rep movsb
add si,cx
mov ah,09
mov dx, [di]
int 21h
ret
dis_names endp
end main

the bubsort, exchange, dis_play procedures are all wrong since i cant get sto_name to work correctly.. so could anyone tell me why mov cx, namelen and add di,count gives me an error?
 
Because namelen and count are BYTES. cx and di are WORDS. You're trying to stretch a BYTE into a WORD which you are not allowed to unless you have a very good explanation to the processor. Go figure.

Do it this way:
xor ch,ch
mov cl,count
add di,cx
mov cl,namelen

or better:
movzx cx,count
add di,cx
movzx cx,namelen

How sure are you that the register di is not changed whenever you call ClearScreen, or call Int21h? Better make sure that di is preserved or even weirder things will happen.

"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top