|
From: almas on 29 Mar 2008 18:18 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 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" -------------- push cx mov cx,5 ; i want to remplace 5 bytes by � push bx ; save the handle xor bx,bx ; will be used like counter mloop: lodsw inc bx ; count inc bx cmp ax,0D0Ah ; is it end of line ? jz mloop lodsb inc bx cmp al,0Dh jz mon0a mov byte si,0A8h ; new line, then remplace by � lodsb inc bx mon0a: cmp al,0Ah jz mloop mov byte si, 0A8h ; again change with � loop mloop pop cx sub cx,bx ; resize file buffer 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 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
|
Pages: 1 Prev: multiplication differences in HLA and gnu as Next: Why is my nasm program killing itself? |