Help With Turbo C, Asm, And Structures

Programming, for all ages and all languages.
Post Reply
renovatio
Member
Member
Posts: 57
Joined: Fri May 23, 2008 5:13 am

Help With Turbo C, Asm, And Structures

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Help With Turbo C, Asm, And Structures

Post 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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
renovatio
Member
Member
Posts: 57
Joined: Fri May 23, 2008 5:13 am

Re: Help With Turbo C, Asm, And Structures

Post 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...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Help With Turbo C, Asm, And Structures

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply