|
Prev: cmp syntax in HLA
Next: Touch
From: Rod Pemberton on 30 Mar 2008 16:32 "Frank Kotler" <fbkotler(a)verizon.net> wrote in message news:boIHj.9633$oE1.9189(a)trndny09... > ... > mov byte si,0A8h > ... > > Gotta love that A86 syntax... And, in the "correct" syntax... move.b #$A8,(r5.w) ;) Rod Pemberton
From: Frank Kotler on 30 Mar 2008 17:03
almas wrote: > Hi Frank ; Hi Rod > Hi every body. > > I will try the solution of Rod. Good. (I haven't gotten back to mine...) > Yes, i look use "handle" in Bx, but first, i push bx. Well... first you push the count in cx, then you push the handle. Then you pop... well, it's supposed to be the count, but it's your handle. Bye-bye handle! Look again... >>>push cx >>>mov cx,5 ; i want to remplace 5 bytes by � >>>push bx ; save the handle >>... Here's your "mloop"... >>... >>>pop cx There's your handle... >>>sub cx,bx ; resize file buffer This value never gets used for anything. >>>pop bx ; restore handle Yeah... only it's the count. > But, sure, my file do..... no thing :-) And that's why. You can see it quite plainly if you step through your program in a debugger. Do you use D86? > Si i will use the new engine. Okay... You tried a "clever trick" of loading and comparing two bytes at once - works for an even number of bytes before the CR/LF, but if it's an odd number you'll miss it, I think. Fixing *just* the push/pop order above, your code *does* put some replacements in the file... just not in the right places. You could probably fix it yourself, from there. I have a question on "design specs". If we encounter a line shorter than 5 characters, are we supposed to print 5 "replacements", or just replace the characters that are there? I've assumed the latter... This is *not* right. It "kinda works". I've cranked the buffer size up to what seems like a "nice round number" to me - 4k. (after arguing with Robert that 1 byte is all Ivan needs, I'm urging more on you...). A buffer of 256 bytes is "too" small - the least we can read from a disk is a sector - 512 bytes - so we ought to buffer at least (and a multiple of) that much. For "test purposes", though, cut the buffer down to 10h - suddenly 4 replacements seems like enough in spots!!! Definitely not right, but I can't spot the error. I'm tired of it, right now. Free copy of Nasm if you can spot my error! Best, Frank ; configuration section BUFSIZ equ 1000h REPCOUNT equ 5 REPCHAR equ 0A8h ; parse command line mov si, 80h lodsb ; error? cmp al, 0 jnz good_cl mov dx, offset cl_err mov ah, 9 int 21h jmp quit good_cl: cbw ;extend AL to AX xchg bx,ax ;swap size to bx for indexing mov byte ptr [bx+si], 0 ;null terminate command line dospc: cmp byte ptr [si], 32 ;any leading spaces ? jne gotfile ;nooo inc si ;yeahh, dump it jmp short dospc ;check next gotfile: mov ax, 3d12h ; open file READ/WRITE/NO SHARE mov dx, si ; filename on command line int 21h ; error? jnc goodopen mov dx, offset open_err mov ah, 9 int 21h jmp quit goodopen: mov [filehandle], ax readlop: mov ah, 3fh ; read file mov bx, [filehandle] mov cx, BUFSIZ ;read buffer full mov dx, offset file_buffer ;buffer int 21h ; error? jnc good_read mov dx, offset read_err mov ah, 9 int 21h jmp close_file good_read: test ax, ax ;nothing read ? (end of file) jnz got_bytes jmp close_file ;yeahh, we're done got_bytes: mov [bytes], ax ;bytes read mov cx, ax ;counter mov si, offset file_buffer mov di, si add cx, si ; cx marks end of data (or buffer) mov bx, [line_pos] startline: ; mov bx, [line_pos] lineloop: lodsb inc bx cmp al, 10 jz unxline cmp al, 13 jnz continue_line stosb ; save the CR cmp si, cx ja end_of_buffer xor bx, bx ; reset to start of line mov [line_pos], bx lodsb ; assume it's a LF unxline: xor bx, bx ; reset to start of line mov [line_pos], bx stosb ; save it cmp si, cx ja end_of_buffer jmp short startline continue_line: cmp bx, REPCOUNT ja skip mov al, REPCHAR skip: stosb ; store the char, or its replacement cmp si, cx jbe lineloop end_of_buffer: mov [line_pos], bx mov ax,4200h ; seek set file position beginning mov bx, [filehandle] mov cx, [file_pos_hi] ;most significant part of offset mov dx, [file_pos_lo] ;least significant part of offset int 21h ; error? jnc good_seek mov dx, offset seek_err mov ah, 9 int 21h jmp close_file good_seek: mov cx,[bytes] ;get offset size add [file_pos_lo], cx adc word ptr [file_pos_hi], 0 ;save them back for next loop mov ah,40h ; write to file mov bx,[filehandle] mov dx,offset file_buffer ;buffer int 21h ; error? jnc good_write mov dx, offset write_err mov ah, 9 int 21h jmp close_file good_write: cmp word ptr [bytes], BUFSIZ ;less than 256 bytes left ? jb close_file ;yeahh, must be last read jmp readlop ;noo, go on reading close_file: mov ah,3eh ; close file int 21h ; error? jmp quit? quit: ret ; int 20h ; DATA open_err db "error opening file$" read_err db "error reading file$" write_err db "error writing file$" seek_err db "error seeking in file$" cl_err db "Usage: remplace filename.ext$" file_pos_hi dw 0 ; at the begining, value must be 0 file_pos_lo dw 0 line_pos dw 0 filehandle dw ? bytes dw ? file_buffer db BUFSIZ DUP (?) |