Page 1 of 1

Write sectors to usb drive from assembly

Posted: Mon Dec 28, 2015 4:58 am
by pocokman
I'm developing a bare metal software (there is no operating system, my code is started by the grub), and i would like to save some measurements data to an usb drive. I switched to real mode after my tests in order to use BIOS interrupts, but before I saved my data to the memory address 0xEE00 (it is an awailable address in real mode).

I used the following code to write a sector to my usb drive:

Code: Select all

mov  ax, 0
mov  es, ax
mov  ah, 0x03
mov  al, 0x01
mov  cx, 1
mov  dl, 0x80 ; drive
mov  dh, 0 ; head
mov  bx, 0xEE00
clc
int  0x13
After the tests, the "pendrive is reading or writing" led was blinking, i.e. my pendrive showed that this code writes something to the pendrive. CF is zero, i've checked it. However, after I read the first ~5 Mbytes from this pendrive by linux dd, I can't find the modified sector. I tried to write a sector filled by 'A' characters, but there is no such a sector on my pendrive. What is the problem? One more thing: I've removed my hard discs from the test computer.

Re: Write sectors to usb drive from assembly

Posted: Mon Dec 28, 2015 5:13 am
by iansjack
You don't set DS or SS. At least you haven't shown that you do.

What happens if you follow the write by a read to a different address, using the same parameters otherwise? What if you just try to read a known sector with those values - do you get the right data? 0x80 for the drive number looks like a magic number to me.

Re: Write sectors to usb drive from assembly

Posted: Mon Dec 28, 2015 5:55 am
by pocokman
Thank you very much, I set ds = 0, and my I found my modified sector on the pendrive =D>