Hi everyone,

got a slight problem. trying to make a program that takes the users input and puts it into a string untill it detects a CR character then outputs the string, i've made a start but i'm at a dead end on what to do.

BITS 16                 ;Set code generation to 16 bit mode
ORG 0x0100;
SECTION .text;



MAIN:
%include 'STDIO.asm'

mov bx , offset Array ;store start of array in bx
call Getch ;read in first character to register

while1: 
cmp DL, 0dh ;while character is not equal to cr
je Next
mov byte ptr [bx], DL ;assign the value of DL to position bx in the array
inc bx; increment bx
call Getch;read in next character to DL register
jmp while1

Next:

mov bx , offset Array ;set bx to the start of Array
while2:
cmp byte ptr[bx] , 0dh;while character is not equal to cr
je Exit
mov DL , byte ptr[bx]; set DL to be equal to the value at BX in the array
call Putch ; puts the character in DL onto the screen
inc BX 
jmp while2

Exit:
	MOV AH,04Ch	; Select exit function
	MOV AL,00	; Return 0
	INT 21h		; Call the interrupt to exit

SECTION .bss
Array resb (20*1)

thanks in advance for any help

-Midi

Recommended Answers

All 2 Replies

EDIT:

Using NASM with the 80x86

I get this error

"Comma or End of Line Expected" on these lines

mov bx , offset Array ;store start of array in bx

mov byte ptr [bx], DL ;assign the value of DL to position bx in the array

mov bx , offset Array ;set bx to the start of Array

cmp byte ptr[bx] , 0dh;while character is not equal to cr

mov DL , byte ptr[bx]; set DL to be equal to the value at BX in the array

well i have written the program in tasm and it works fine .
the programmin stlye is a bit different but i guess u can undestand

.model small
.stack 40
.data

str1 db 50 dup('$')
msg db 10,13, 'enter the str1ing : $'
disp db 10,13, 'displaying the str1ing : $'

.code

mov ax,@data
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
 lea si,str1    ; making si to hold the starting address
xor cx,cx    ; clearing cx register


lp:
mov ah , 01h   ; the first two lines are to read from keyyboard
int 21h
cmp al 0dh    ; compares until we press enter character
jz stop
mov [si] , al    ; if enter key  is not pressed contents are stored in
inc si              ; string and si is incremented
inc cx
jmp lp

stop:
lea dx , disp  
mov ah,09h
int 21h
lea si , str1

lpz:
mov dl , [si]
mov ah , 02h   ; the first two lines displays the data
int 21h
inc si
dec cx
jnz lpz
mov ah,4ch
int 21h

end

i guess this should do the trick .

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.