Question

i need to print a filesize using function 23h http://www.ousob.com/ng/asm/ng4d85d.php but i dont understand how can i get value from (offset 21h) of the FCB, it should be 4byte value, so need to move it into pair of 16bit registers, e.g. BX and CX this is my simple code:

mov dx,offset input
mov ah,23h  
int 21h

then i need to print it, but i just know how to print one 16bit register and i dont know find some tutorial how to do this for 32bit value (2 registers) simply, thanks

Was it helpful?

Solution

The FCB returns both the number of records (a 32-bit quantity at offset 21h of the FCB) and the size of each record (a 16-bit quantity at offset 0Eh of the FCB). You need to multiply those together to get an approximation of the file size. It's only an approximation because a partial block is counted as a whole block for this call.

So assuming that input is already declared as an FCB structure in memory in the Data Segment and that your file consists exclusively of records that 27 bytes long, your code might look like this.

mov dx,offset input    ; point to FCB
mov si, dx     ; copy pointer
add si,0Eh     ; point to record size within FCB
mov [si],27    ; load record size = 27 bytes
mov ah,23h     ; get file size
int 21h        ; call the DOS interrupt
cmp al,0       ; was the call successful?
jnz error      ; if not, handle the error
add si,13h     ;   advance pointer to point to FCB:21h
; now ds:si points to file size in records

See this derivation of the age-old "Ralf Brown's interrupt list" for a list of some of the many precautions regarding this interrupt.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top