W
W
watmag2017-05-19 16:37:58
assembler
watmag, 2017-05-19 16:37:58

Assembler, free hard disk space?

The program should display the free space on the selected hard drive, but does not want to do this. In the program I used interrupt int 21h, function 36h.
Displays 976 MB, it is not clear what it is ?. Although the free space is around 8GB. All this was done in virtual box, windows xp.

.MODEL SMALL
.386
STACK 256h
DATASEG
CODESEG 
 
start: 
  mov eax,@data 
  mov ds,eax ; Data Segment
  xor eax,eax
  mov ah, 36h
  mov dl, 0
  int 21h
 
  mul ebx        
  mov ebx,edx
  shl ebx, 16
  add eax,ebx
  mul ecx
  
cnvrt: 
xor ecx,ecx ;счетчик десятичных цифр
mov ebx,10 ;основание сист. счисления
ckl:
xor edx,edx ;расширим делимое
div ebx
push edx ;получаемые цифры кладем в стек
inc cx
test eax,eax ;делитель - ноль ?
jnz ckl ;еще нет, продолжим
 
outpt: ;вывод числа на экран
 
pop eax
add al,'0' ;десятичную цифру -> в ASCII
int 29h ;вывод цифры
 
loop outpt
 
 
 mov ah,10h
 int 16h
end start

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2017-05-19
@watmag

0) there is no guarantee that for your real disk all response parameters AX, BX, CX fit in 16 bits (perhaps, of course, DOS cheats something for compatibility, but again there is no guarantee);
Now ASM itself:
1) are you sure that the upper word ebx is pure on the first multiplication?
2) the meaning of manipulations is absolutely incomprehensible

mov ebx,edx
  shl ebx, 16
  add eax,ebx

3) are you sure that the upper word esx is pure on the second multiplication?
4) here you completely killed the upper 32 bits of meaningful information (and 8 GB no longer fit in the lower 32 bits):
xor edx,edx ;расширим делимое

S
sisn, 2017-05-19
@sisn

https://ru.wikipedia.org/wiki/FAT#.D0.A5.D0.B0.D1....
Other calls apply for FAT32.
For an API targeting FAT16 features, you will never get as large values ​​as you expect.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question