i want to copy a string from a register (SI), into another register (DI). But, before copying i need to scan the string for blanc space. If there is more than 1 blanc spaces (SI), i need to replace all blanc spaces with one space and put in DI.
I don't have experience with assembly, but all what i do is:

.model small
sir1 db 'String   with   more    spaces', '$'
sir2 db ? 

	mov ax,@data
	mov ds,ax
	mov es,ax
	mov si,offset sir1
	mov di,offset sir2
        mov bx,0
	mov cx,30
		cmp [si],20h ;comparing with blanc character		
		inc bx
		cmp bx,2 ;if here is more than one blan
		je tru ;if it's equal, jump tu "tru" label.
		mov di,[si]-1 ;substract one blanc
		mov di,[si]
		inc si
		inc di
		loop e1

	mov dx,offset sir2
	mov ah,09
	int 21h
	mov ah,4ch
	int 21h
end s

Where is my mistake?
Please provide me with some advice or help.

8 Years
Discussion Span
Last Post by NotNull

> je tru ;
tru immediately follows, so it does nothing in effect.
Besides, don't you want >= 2 ?

> sir2 db ?
IIRC, this only reserves 1 byte, not a string.


This code will copy a source string whose offset is placed in the SI register,
and will be copied to the string at the offset in the DI register,
removing any double blanks.
Here's how to do it:

.MODEL tiny

string db 'Jackal  Hex  Digit  Hunt$'
string2 db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

org 100h
mov SI,offset string    ; The offset of the first byte of both strings 
                                ; are put in SI & DI
mov DI,offset string2
mov DL,[SI]               ; Copies the byte of the source string into the DL register
cmp DL,024h              ; Checks for ending dollar sign in source string here.
je exit_prog
cmp DL,020h              ; Check for space character
je blank_chk
mov [DI],DL               ; Move byte from source string into the 
                                 ; destination string
inc SI                         ; Increment to the next byte of the source string
inc DI                         ; Increment to the next byte of the destination string
jmp copy_loop

mov DL,[SI+1]           ; Get the byte at the source string offset plus 1
cmp DL,020h              ; Check if space
jne copy_next             ; If not continue the copy process
inc SI                        ; Otherwise increment the offset of the 
                                ; source string one byte forward
jmp copy_loop

mov [DI],024h               ; Add dollar sign to the end of the destination string
mov DX,offset string2     ; Move the offset of its first byte into DX
mov AH,09h                   ; Output the new string with function AH=09h of INT 21h
int 021h
int 020h                      ; Exit

end start

A string is a contiguous array of bytes.
Each byte has its own address, which will lie at contiguous addresses
one after another, in sequential order.

When you have a string of five bytes:
'A' 'B' 'C' 'D' 'E' ; These letters represent ASCII values
1 2 3 4 5 ; Psuedo addresses

The offset of this string will be 1,
and incrementing it by 3 will take you to the fourth byte which contains the ASCII
value of 'D'

An offset is a value to a computer, you must tell the processor to treat this value
as an address.

mov AL,024h
mov SI,offset string ; moves the actual value which represents the offset of the
; string
mov [SI],AL ; moves a byte into the memoray location pointed by SI
; DS : SI
inc SI ; increments the offset in SI by one

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.