Write sectors to usb drive from assembly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pocokman
Posts: 2
Joined: Mon Dec 28, 2015 4:53 am

Write sectors to usb drive from assembly

Post 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.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Write sectors to usb drive from assembly

Post 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.
pocokman
Posts: 2
Joined: Mon Dec 28, 2015 4:53 am

Re: Write sectors to usb drive from assembly

Post by pocokman »

Thank you very much, I set ds = 0, and my I found my modified sector on the pendrive =D>
Post Reply