views:

444

answers:

2

Hi to all I need to be able to write a program in assembly to read the first sector of a disk (The MBR) and write it to a floppy disk or at least show the data. I understand that INT 13h and 25h do not work in the windows protected mode and i even tried my code in Dos but the dos system hangs when I run the program. This is the code:

  MOV byte ptr es:[bx], offset result
  MOV     AL,1 ;number ofsectors to read
  MOV     Cl,1 
  MOV     ch,0  
  mov     dl,80h  ;the HDD
  mov     dh,1
  mov ah,02h
  INT     13h

result is the buffer variable.

Thanks in advance.

+1  A: 

I think this line is wrong

MOV byte ptr es:[bx], offset result ' attempts to write memory [bx]

It should be

MOV es, segment_offset ' probably not needed
MOV bx, buffer_offset
...

And maybe you also have to restore the ES, example

push es
mov  es, ...
...
pop  es
' done
Nick D
Thanks Nick DI changed my code to this: mov dx,80h ;first physical disk mov cx,1 ;head 1, sector 0 mov bx,ds ; mov es,bx ;point to boot record buffer mov bx,OFFSET result ;read into boot record mov ax,0201h ;read one sector int 13hIt seems it works. It gives me a lot of junk when I print it out but how do I make sure it's the real MBR?Thank you all for your patience in reading my questions.
Auxiliary
@Auxiliary, check out http://mirror.href.com/thestarman/asm/mbr/STDMBR.htm which provides a lot of info about MBR.
Nick D
A: 

Yeb. it finally worked. This is the code (only runs in DOS because the INT 13h can't run in windows OSes.

            mov dx,80h
        mov cx,1
        mov bx,ds
        mov es,bx
        mov bx,offset result
        mov ax,0201h
        int 13h     
Auxiliary