Could someone help me with this imbedded assembly code 
Author Message
 Could someone help me with this imbedded assembly code

#include <iostream.h>

unsigned char scankey(void)
{
 asm{
  mov ah, 01h
  int 16h
  jz empty;
  mov ah, 00h
  int 16h
  mov al, ah
  xor ah, ah
  jmp done;
  empty:
   xor ax, ax
  done:
  }
 }
void main(void)
{
 unsigned char key = 'a';
 do
 {
  cout << key << endl;
  key = scankey();
  } while (key != 'q');
 }

  Could someone tell me what is wrong with this code?  I am using Borland
  C++ 3.0.  The errors I am getting are

            error test.cpp 19: undefined label 'done'
            error test.cpp 19: undefined label 'empty'
            warning test.cpp 19: Function should return a value

     This program is supposed to display a character on each line and read
   the keyboard buffer to see if a key had been pressed.  If a key was
   pressed it will then print that character instead.  It will repeat until
   the q key is pressed.  Don't judge it too harshly, I'm only a beginner!

                                Larry



Fri, 04 Sep 1998 03:00:00 GMT  
 Could someone help me with this imbedded assembly code

Quote:
> #include <iostream.h>

  <iostream.h>, cout, and << as a stream operator are not part of the C
language (they are part of C++, which is discussed in comp.lang.c++).

Quote:
> unsigned char scankey(void)
> {
>  asm{

  Inline assembly is not part of C or C++.  Check your compiler docs to
see if Borland has any special way of dealing with labels in inline
assembly.  Failing that, look in comp.lang.asm.x86 or
comp.os.ms-windows.programmer.

Quote:
> void main(void)

  Contrary to some books (and even some compiler manuals) main returns
int in C (and in C++):

  int main(void)

  Good luck.

/**James Robinson***********************            
  "An important goal of almost every graphics program is to draw pictures on
 the screen."    -- Neider, Davis & Woo, _OpenGL_Programming_Guide_, Chapter 10



Fri, 04 Sep 1998 03:00:00 GMT  
 Could someone help me with this imbedded assembly code
I believe that you're going to need to pull the labels out of the assembly
section and explicitly return the contents of ax.  The modified function
would read:

unsigned char scankey(void)
{
    unsigned char keyFound;

    asm {
        mov ah, 01h
        int 16h
        jz empty;
        mov ah, 00h
        int 16h
        mov al, keyFound
    }
empty:
    return( keyFound );

Quote:
}

>#include <iostream.h>

>unsigned char scankey(void)
>{
> asm{
>  mov ah, 01h
>  int 16h
>  jz empty;
>  mov ah, 00h
>  int 16h
>  mov al, ah
>  xor ah, ah
>  jmp done;
>  empty:
>   xor ax, ax
>  done:
>  }
> }

>  Could someone tell me what is wrong with this code?  I am using Borland
>  C++ 3.0.  The errors I am getting are

>            error test.cpp 19: undefined label 'done'
>            error test.cpp 19: undefined label 'empty'
>            warning test.cpp 19: Function should return a value

---

phone/fax (847) 439-7714


Sat, 05 Sep 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Someone Please Help Me - I Help You in Any Software Queries/Programming/Coding

2. Can someone help me to port this short qbasic code to C (linux C)

3. Can someone help me with this code...

4. Can someone help me fix this code?

5. help: can the debugger misinterpret assembly code ?

6. how convert a c code to a assembly code

7. SOMEONE HELP ME, HELP ME, HELP ME PLEASE...

8. HELP: Could someone help me out with this?

9. Can someone look at this code?please.

10. Access Violation in C - Jumping into someone else's code

11. Can someone explain this piece of Code?

12. Can someone please explain this code?

 

 
Powered by phpBB® Forum Software