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.
Right now I'm having trouble reading a sector from disk into an array from my C-code (Turbo C with inline TASM).
The problem seems to be getting the data into the array (I think the controller reads fine). Take a look:
Right now I'm having trouble reading a sector from disk into an array from my C-code (Turbo C with inline TASM).
The problem seems to be getting the data into the array (I think the controller reads fine). Take a look:
char* fl_read_sector(char sector)
{
char buffer[512];
....
/* Where shall we store the data? */
asm push ds <----- THIS SECTION IS VERY VAGUE....
asm pop es <----- ...
asm mov bx, offset buffer <----- ...
...
Well there is your problem. The local variable is allocated on the stack, so you can't use offset to get its address (and ss: may not even point to where ds: points). You would need something along the lines of
Or you could make the local variable static, in which case it is allocated in the data segment, and the same area will be reused on every entry to your function.
The "push ds, pop es" pair of instructions is just a simple way of copying the value of segment register ds into es. That usage is extremely common.
It looks to me like the biggest problem you have here is that "buffer" is a completely temporary (ie. "automatic") variable allocation. The entire array is deleted as soon as this function exits. But you try to pass back a pointer to it anyway. You need to make it global or static.
Thanks! Doesn't work though. Seems like either nothing is being read to the buffer or I'm writing the data somewhere else (not to the buffer). I rewrote the code and attached a routine at the bottom which prints the contents of the buffer byte-by-byte in decimal form.
Now what I want to do (for the sake of proving that the code runs correctly) is to read the OEM-string from the bootsector. This should be located at sector 0 and 3 bytes in if I'm correct.
Right now I'm passing 0 or 1 to the fl_read_sector function. But whatever sector I choose the buffer seems to contain nothing but zeroes...
char* fl_read_sector(char sector)
{
int i = 0;
unsigned int bufptr = (unsigned int)buffer;
...
asm lea bx, bufptr
The lea instruction (among other uses) is used for loading the address of a variable on the stack. You want the contents, not the address of that variable. So: