Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly Language > Re: remplace A...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 8 Topic 4932 of 5156
Post > Topic >>

Re: remplace Ascii

by "Rod Pemberton" <do_not_have@[EMAIL PROTECTED] > Mar 30, 2008 at 12:48 AM

"almas" <almes@[EMAIL PROTECTED]
> wrote in message
news:47eebff8$0$857$ba4acef3@[EMAIL PROTECTED]
> Hi every body.
> I have a text.... many lines, end of line is OD OA
> I want to change the beginig of each line
> the first 5 bytes remplaced by   "¿"
>
> Below my code... sorry it is not OK
> Who have an idea ?
>
> I use DOS  Operating System    compiler is A86
>

1) replace ("remplace") engine
2) add safety and terminating buffer "term:" after "bytes:"

>         mov   si,0080h
>         lodsb
>         cbw                   ;extend AL to AX
>         xchg  bx,ax           ;swap size to bx for indexing
>         mov   byte [bx+si],0  ;null terminate command line
>         mov   di,inbuff       ;our buffer
> ; dospc: cmp   byte [si],32   ;any leading spaces ? ; jne nospc ;nooo
>         inc   si              ;yeahh, dump it ; jmp  dospc ;check next
> nospc: mov   cx,1                   ;we're here, so we got one arg
> copy1: lodsb                        ;load byte SI to AL
>         cmp   al,0                  ;0 ?(end of line)
>         je   done                   ;yeahh
>         stosb                     ;noo, move AL to DI, incrase DI
>         jmp short  copy1            ;go on
> done:  mov   byte [di],0    ;null terminate END of PARSE
> gotfile:
>         mov   ax,3d12h              ; open file  READ/WRITE/NO SHARE
>         mov   dx,offset inbuff      ;filename
>         int   21h
>
> fopok: xchg ax,bx
> ; ; handle ; mov word [bytes],256 ; buffer size
> ; ; NOTE BX will not change  I put value 0 into count 1 and 2
> ; ; xor ax,ax ; mov offset count1,ax ; clear out ; mov offset count2,ax
>
> readlop:    mov   ah,3fh          ; read file ;  mov bx,[filehandle]
>         mov   cx,[bytes]          ;read buffer full
>         mov   dx,offset address   ;buffer
>         int   21h
>         cmp   ax,0              ;nothing read ? (end of file)
>         ja   main               ;nooo, do the work
>         jmp short  quit         ;yeahh, we're done
> main:
>         mov   [bytes],ax        ;bytes read
>         mov   cx,ax             ;counter
>         mov   si,address        ;file buffer
> ;                   ----------  here the "engine" --------------

; replace i.e., "remplace" engine  ;-)

mov di,si
add si,cx

push bx                ; save the handle
push cx

cld
mloop:                 ; is it end of line ?
mov al,0Dh
repne scasb
mov al,0Ah
scasb
jnz mloop

push di                ; blank line ?  Yes, skip.
mov al,0Dh
scasb
pop di
jz mloop

cmp di,si ;term            ; past end of buffer ?  Yes, exit.
ja oloop

mov cx,5               ; i want to remplace 5 bytes by ¨
mov al,0A8h
rep stosb

cmp di,si ;term            ; past end of buffer ?  Yes, exit.
ja oloop

jmp mloop

oloop:

pop cx
sub cx,di                  ; resize  file buffer
add cx,address
pop bx                     ; restore handle

> ;    ----------- end of my "engine " -----------
>
> mov ax,4200h                     ; seek set file position beginning
>         mov   cx,[count1]        ;most significant part of offset
>      mov   dx,[offset count2] ;least significant part of offset
>         int   21h
>
>         mov  cx,[bytes]          ;get offset size
>         mov  dx,[offset count1]  ;the most significant part
>         mov  ax,[count2]         ;the least significant part
>         add  ax,cx               ;add offset to least sig part
>         adc  dx,0                ;add with carry
>         mov  [offset count1],dx  ;save them back for next loop
>         mov  [count2],ax
>
>   mov   ah,40h              ;  write to file  mov bx,[filehandle]
>         mov   dx,offset address   ;buffer
>         int   21h
>         cmp   word [bytes],256    ;less than 256 bytes left ?
>         jb   quit                 ;yeahh, must be last read
>         jmp short  readlop        ;noo, go on reading
> quit:                    ; cmp word [filehandle],0 ;any filehandle
>
>         mov   ah,3eh             ; close file
>         int   21h
> nofile: ret                      ; int   20h
>
> ; DATA
> bytes        dw   ,100h ; size buffer for file

term:        db    0dh,0ah,0,0,0,0,0

> filesize:    db:   0,0
> filehandle   dw    0,0
> count1       dw    0,0  ; at the begining, value must be 0
> count2       dw    0,0
> inbuff:      db:   0,0
> address:     db:  ,0,0

I know there is at least one bug in "engine" but it is trivial...  Also,
I'm
not sure if the cx calculation is correct for the rest of your code.


Rod Pemberton
 




 8 Posts in Topic:
remplace Ascii
"almas" <alm  2008-03-29 23:18:51 
Re: remplace Ascii
"Rod Pemberton"  2008-03-30 00:48:20 
Re: remplace Ascii
Frank Kotler <fbkotler  2008-03-30 08:42:47 
Re: remplace Ascii
"Rod Pemberton"  2008-03-30 16:10:33 
Re: remplace Ascii
"Rod Pemberton"  2008-03-30 16:32:32 
Re: remplace Ascii
Frank Kotler <fbkotler  2008-03-30 08:19:38 
Re: remplace Ascii
"almas" <alm  2008-03-30 20:19:15 
Re: remplace Ascii
Frank Kotler <fbkotler  2008-03-30 21:03:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 7 16:08:33 CDT 2008.