Advertisement

Changing passed values with inline asm

Started by October 12, 2000 05:41 PM
3 comments, last by farmersckn 24 years, 3 months ago
here''s my GetPaletteEntry function for screen mode 13h.
    
void GetPaletteEntry (byte bIndex, byte bRed, byte bGreen, byte bBlue)
{
   asm {
   mov dx, 0x3c7
   xor ah, ah
   mov al, bIndex
   out dx, al
   mov dx, 0x3c9
   xor ah, ah  // This isn''t necessary, i dont'' think.
   in al, dx
   mov bRed, al
   in al, dx
   mov bGreen, al
   in al, dx
   mov bBlue, al
   }
}
    
Now, how do i change that so i can actually get the values? I''ve tried changing bRed, bGreen, and bBlue to references, but i get invalid combination of opcodes and operands. Second, i would like to do this without using locals, because it shouldn''t *have* to, and i would like the speed... whatever. Clues anyone, I know you are out there, and i know you know... well, thanks for the help, in advance. farmersckn
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
    void GetPaletteEntry (byte bIndex, byte *bRed, byte *bGreen, byte *bBlue){asm {   mov dx, 0x3c7   xor ah, ah   mov al, [bIndex]   out dx, al   mov dx, 0x3c9   xor ah, ah  // This isn't necessary, i dont' think.   //That makes ah 0x0, i think it is important - odds are is is zero and will work most of the time without it - chances are at some point it won't be zero any more! You need to make sure it is.   in al, dx   mov [bRed], al   in al, dx   mov [bGreen], al   in al, dx   mov [bBlue], al   }}    


Edited by - Magmai Kai Holmlor on October 12, 2000 8:53:15 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
If you are passing by reference, then the parameters is actually converted to pointers. That means you have to use the value of the pointer in your code. Like this:

void GetPaletteEntry (byte &bIndex, byte &bRed, byte &bGreen, byte &bBlue)
{
asm {
mov dx, 0x3c7
xor ah, ah
mov al, [bIndex]
out dx, al
mov dx, 0x3c9
xor ah, ah // This isn''t necessary, i dont'' think.
in al, dx
mov [bRed], al
in al, dx
mov [bGreen], al
in al, dx
mov [bBlue], al
}
}
If you are passing by reference, then the parameters is actually converted to pointers. That means you have to use the value of the pointer in your code. Like this:

void GetPaletteEntry (byte &bIndex, byte &bRed, byte &bGreen, byte &bBlue)
{
asm {
mov dx, 0x3c7
xor ah, ah
mov al, [bIndex]
out dx, al
mov dx, 0x3c9
xor ah, ah // This isn''t necessary, i dont'' think.
in al, dx
mov [bRed], al
in al, dx
mov [bGreen], al
in al, dx
mov [bBlue], al
}
}
Thanks guys, I just looked some stuff up on my inline assembler (tc3.0++) and found out, like you said, that it interprets a reference as the address of the variable. So... my new function looks like this, and it actually works.
    void GetPaletteEntry (byte &bIndex, byte &bRed, byte &bGreen, byte &bBlue){  asm {  mov dx, 0x3c7  xor ah, ah  mov al, [BYTE PTR bIndex]  out dx, al  mov dx, 0x3c9   xor ah, ah  in al, dx   les di, [bRed]  mov [es:di], al  in al, dx    les di, [bGreen]  mov [es:di], al  in al, dx   les di, [bBlue]  mov [es:di], al  }}    

HEY! It works! Thanks. I hadn''t expected to get replies so fast. It amazes me how helpful people are on this site.
farmersckn
p.s. Btw, I''m actually just learning assembler, by looking at other bits and pieces of code, so if i''m missing anything in this, I''d appreciate the help. Thanks.
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.

This topic is closed to new replies.

Advertisement