TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: ALL
from: KURT WISMER
date: 1997-06-13 19:29:00
subject: problem with my code...

ok, can someone tell me what i'm doing wrong here? the problematic
behaviour is described below...
; DiskBack - generates an image of a floppy disk in a file (and parses
; out the empty space).
cseg  segment  word
assume cs:cseg, ds:cseg
org 100h
begin:
   mov dx, offset file      ;create file with filename in [dx]
   xor cx, cx               ;set file attributes = 00000000
   mov ah, 3ch              ;create function => int 21h, ah = 3ch
   int 21h                  ;returns handle of created file in ax
   mov ax, 3d01h            ;open function => int 21h, ah = 3dh
                            ;open access is "write" => al = 00000001b = 01h
                            ;[dx] = file name
   int 21h                  ;returns handle of opened file in ax
   mov di, ax               ;save handle
   xor ax, ax               ; drive al = 0 => a: drive
   mov dx, 0ffffh           ; start at sector -1
arge:
   inc dx                   ;move sector pointer forward by 1
   mov cx, 1h               ;read 1 sector
   mov bx, offset buff      ;set read buffer
   int 25h                  ;absolute disk read cx sectors starting at dx
   jc close                 ;close and exit on error
   mov bx, offset buff      ;prep buffer for comparison
   mov cx, 200h             ;200h byte string comparisons between buffer
loop1:
   cmp byte ptr[bx], 0f6h   ;compare the sector to the hex byte f6 (empty)
   jne writ                 ;write sector at first instance of a difference
   inc bx
   loop loop1
   jmp arge                 ;skip sector save routine if the sector is
                            ;full of f6h's
writ:
   push dx                  ;save sector index
   mov bx, offset buff + 200h    ;append sector index to buffered sector
   mov byte ptr[bx], dh          ;for later recovery
   mov byte ptr[bx + 1], dl
   mov bx, di               ;restore file handle
   mov dx, offset buff
   mov ah, 40h              ;write function => int 21h, ah = 40h
;--------- problem line ----------
   mov cx, 202h             ; ****  write 200h (512) bytes
;---------------------------------
   int 21h                  ;writes 1 sector to the file with handle bx
   pop dx                   ;restore sector index
   jmp arge
close:
   mov bx, di               ;restore file handle
   mov ah, 3eh              ;close file => int 21h, ah = 3eh
   int 21h                  ;bx = file handle
   mov ax, 4c00h            ;exit program
   int 21h                  ;
file db 'diskback.img',0
buff db 202 dup(?)
cseg ends
end begin
--------
so here's the problem... as it stands now the resulting com file
executes and saves the first sector of drive a: and the word sized
number representing which sector it is, but refuses to go any further (i
can tell by the amount of time the program takes to exit)... if i change
the "problem line" to "mov cx, 200h" the program goes through all of a:
drive and i get the 4608 bytes worth that i was expected from a freshly
formatted floppy but i lose the "sector index" number (obviously, since
i'm no longer writing those last two bytes)...
i've tried putting a separate write procedure for those last two bytes
but i get the same result as if i left it as it looks above...
what am i missing? (this is being assembled under tasm, btw)
... ow that you know that i know that you know that i kn...
--- TGWave v1.20.b09
---------------
* Origin: fks Online! * Ontario, Canada * (905)820-7273 * (1:259/423)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.