程序集8086:使用16位寄存器获取并打印32位文件大小

时间:2014-03-24 14:47:39

标签: tasm

我需要使用函数23h http://www.ousob.com/ng/asm/ng4d85d.php打印文件大小但是我不明白如何从FCB的(偏移21h)获得值,它应该是4byte值,所以需要将它移动到16bit对寄存器,例如BX和CX 这是我的简单代码:

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

然后我需要打印它,但我只知道如何打印一个16位寄存器,我不知道如何找到一些教程如何为32位值(2个寄存器)这样做,只是, 感谢

1 个答案:

答案 0 :(得分:0)

FCB返回记录数(FCB的偏移21h处的32位数量)和每个记录的大小(FCB偏移0Eh处的16位数量)。您需要将它们相乘以获得文件大小的近似值。它只是一个近似值,因为部分块被计为此调用的整个块。

因此假设input已在数据段的内存中声明为FCB结构,并且您的文件只包含27个字节长的记录,您的代码可能如下所示。

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

请参阅this derivation历史悠久的"拉尔夫布朗的中断列表"有关此中断的一些预防措施的列表。

相关问题