inline assembly in VC 
Author Message
 inline assembly in VC

I would just like to whip up a lil function that sets the color of the
prompt
and text to a certain color based upon some params sent into the
function (I use int 10h). When I use MS Visual C 5.0 I can get the
following code to compile, but at run-time the int 10h  instruction
causes a "Fatal Exception" screen to appear and it shuts my program
down. I whipped up almost exactly the same thing (I hard set the color
in the asm) in a straight assembly program. It works BUT..... after
about 8 seconds the entire system comes to a halt! I have included the C

code and asm code. Can someone explain to me why this is happenning and
how to get around it? Not only does all of this happen, but when I goto
debug it, I can't end the program but stopping the debug session, and
all keyboard functions cease to work. (Probably because interrupts are
disabled when an INT is called). I am thinking that one way around this
would be to actually get the base:offset of the pointer to the ISR in
the vector table and actually perform a jump to that routine. I could
pushf   then push cs, and then make a dumby call to a procedure to push
IP, or I can mov    dx,offset label_ofNextinst. and then push dx instead

of making a dumby procedure call.  That way when it hits the IRET
instruction I am taken back to the appropriate location. I have also
tried the following by pushing the effected registers. It stops the
whole program at that instruction! Any ideas?

#include <stdio.h>
void setColor( int num );
char buff[12];
int c;

void main( void )
{   printf( "This should print some colors\n");
 scanf("%d",&c);
 setColor(c);
printf("Did it?");

Quote:
}

void setColor( int color)
{   __asm
 {
  mov  eax,0601h   // service number
  mov  ebx,color // color
  xor  cx,cx  //
  mov  edx,184fh
  int  10h
 }

Quote:
}

  stk  segment  stack
  db  64 dup(?)
stk  ends
data    segment
theColor  equ  [bp+4]
data  ends
code    segment
        assume   ds:data
 public _setColor
_setColor  proc  far
;-----------dos bookkeeping---------------------------------------
    push    ds
    xor  ax,ax
    push    ax
    mov     ax,data
    mov     ds,ax
;-----------dos bookkeeping---------------------------------------

 mov  ax,0601h  ; request set display 3
 mov  bh,1
 xor  cx,cx
 mov  dx,184fh
 int  10h



Sat, 13 Oct 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Inline Assembly Code

2. inline assembly and interrupts

3. Inline assembly on x86 Solaris

4. Inline assembly crashes

5. C libraries, inline assembly and other advanced C on Linux+i386

6. inline assembly

7. The inline assembly

8. problems porting ms inline assembly codes to linux (gnu - AT&T syntax)

9. Floating point + inline assembly + C =?

10. Help using INLINE ASSEMBLY

11. Inline Assembly for C

12. Pentium RDTSC timer (+GNU inline assembly) CPUID crashes

 

 
Powered by phpBB® Forum Software