|
Prev: cmp syntax in HLA
Next: Touch
From: Rod Pemberton on 30 Mar 2008 00:48 "almas" <almes(a)naburo.com> wrote in message news:47eebff8$0$857$ba4acef3(a)news.orange.fr... > 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
From: Frank Kotler on 30 Mar 2008 04:19 almas wrote: > 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 My condolences. .... > push cx > mov cx,5 ; i want to remplace 5 bytes by � > push bx ; save the handle .... .... > pop cx > sub cx,bx ; resize file buffer > pop bx ; restore handle There's one big problem, the seek fails because you're trying to use the count as the handle... (Rod quietly fixes this) Best, Frank
From: Frank Kotler on 30 Mar 2008 04:42 Rod Pemberton wrote: .... > ; 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 Got the pushes and pops in the right order... This one is still unused, though... > pop bx ; restore handle > > >>; ----------- end of my "engine " ----------- >> >>mov ax,4200h ; seek set file position beginning >> mov cx,[count1] ;most significant part of offset I haven't tried your code... Looks to me as if it's going to skip the first line, and give us an extra 5 '?'s (forgive the lack of a Europen keyboard) after the last line, no? I'll try it if and when I get around to it. I'm embarrassed to admit that *my* version *still* isn't working right. .... mov byte si,0A8h .... Gotta love that A86 syntax... Best, Frank
From: almas on 30 Mar 2008 14:19 Hi Frank ; Hi Rod Hi every body. I will try the solution of Rod. Yes, i look use "handle" in Bx, but first, i push bx. But, sure, my file do..... no thing :-) Si i will use the new engine. Regards Almas "Frank Kotler" <fbkotler(a)verizon.net> a �crit dans le message de news: u2IHj.1705$ie3.305(a)trndny02... > almas wrote: >> 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 > > My condolences. > > ... >> push cx >> mov cx,5 ; i want to remplace 5 bytes by � >> push bx ; save the handle > ... > > ... >> pop cx >> sub cx,bx ; resize file buffer >> pop bx ; restore handle > > There's one big problem, the seek fails because you're trying to use the > count as the handle... > > (Rod quietly fixes this) > > Best, > Frank
From: Rod Pemberton on 30 Mar 2008 16:10
"Frank Kotler" <fbkotler(a)verizon.net> wrote in message news:boIHj.9633$oE1.9189(a)trndny09... > I'm embarrassed to admit that *my* version *still* isn't working > right. Really? Wow, with the stuff you've been cranking out lately, I've been getting jealous... It must be a full time job! :-) > I haven't tried your code... Looks to me as if it's going to skip the > first line, Well, there's no 0x0d 0x0a prior to the first line... that'd require a line counter and comparison - for just the first line, wouldn't it? > and give us an extra 5 '?'s (forgive the lack of a Europen > keyboard) after the last line, no? I'll try it if and when I get around > to it. There's is a bug similar to that (i.e., try one letter on the last line and get _three_ inverted '?'s - instead of five... probably something wrong with cx calc. or maybe Win98's dos box is fixing memory errors... yet again... Ooops, didn't think about that. :-( ). Of course, the DOS editors I use probably all put a 0x0d and 0x0a at the end of every file... (You "is" on Linux with vi or emacs, yes?) The final '\n' is required by C. I'm not sure why DOS editors do that though. Also, there's 0x0d 0x0a in "term" and five 0's (should correspond to replacement length of five inverted '?'s) just in case the line is long and has no returns. But, I didn't bother to test long lines or a full buffer... Since I wasn't quite sure how he was using 'buffer', I suspect there might be problems with the length of bytes read vs. the size of the buffer, i.e., might need more comparisons and jumps to oloop. I decided to leave it as "quick and dirty." I.e., he can complain if doesn't work well enough. :-) RP |