Page 1 of 1

Help With Turbo C, Asm, And Structures

Posted: Fri Aug 01, 2008 7:46 am
by renovatio
Hello, thanks for reading my post. I writing a function to load a sector into an structure. My function's code is the following:

Code: Select all

void loadsct(unsigned char size, unsigned char *where, unsigned char track, unsigned char sector, unsigned char head)
{
   asm {
      mov ah, 2h
      mov al, [size]
      lea bx, where
      mov ch, [track]
      mov cl, [sector]
      mov dh, [head]
      mov dl, 0
      int 13h
   }
}
and this is how i call it:

Code: Select all

struct entry
{
   unsigned char name[10];
   unsigned char size;
   unsigned char track;
   unsigned char sector;
   unsigned char head;
};

struct entry direntries[14];

void main(void)
{
   loadsct(1, &direntries[0].name[0], 0, 1, 0);
}
well this is not working... and i can't undertstand why...

thanks

Re: Help With Turbo C, Asm, And Structures

Posted: Fri Aug 01, 2008 8:44 am
by Combuster
a) you didn't set ES
b) you don't preserve registers
c) you don't check return values.

edit:
d) you preserve a 10 byte buffer for a call that fills in 256 bytes

Re: Help With Turbo C, Asm, And Structures

Posted: Fri Aug 01, 2008 9:01 am
by renovatio
* ES is set because i'm working with turbo c++ 3.0 under windows, and as far as i know windows or turbo c++ set it.
* Registers musn't be preserved because i'm not saving anything in regs, just in memory.
* Return values are in the structure...
* i'm reserving 14*14 bytes.... 10 is the number of chars thar name allows...

Re: Help With Turbo C, Asm, And Structures

Posted: Fri Aug 01, 2008 9:43 am
by Combuster
* ES is set because i'm working with turbo c++ 3.0 under windows, and as far as i know windows or turbo c++ set it.
It doesn't always do that.
Registers musn't be preserved because i'm not saving anything in regs, just in memory.
You just put everything in registers with that assembly.
Return values are in the structure
Not CF (very important for debugging)
i'm reserving 14*14 bytes....
My fault, but even so, 14*14 < 256, i.e. memory corruption still occurs.

But the fact that you have that many (beginners) bugs left and you refuse to check them out is IMO an indication that you are far from ready to do this.