asm keyword

This is a discussion on asm keyword within the C++ Programming forums, part of the General Programming Boards category; i want to use it...but how? just a small example please... x86...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    719

    asm keyword

    i want to use it...but how?

    just a small example please... x86

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    I think this is compiler specific. Im not even sure all compiler supports inline asm.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    oh...that sucks....i guess i'll have to go find a real asm compiler if i want to play

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Read the documentation for your compiler to learn how to do this. There is a good chance that it is one of the following ways though.
    Code:
    asm
    {
      ...
    }
    or
    Code:
    __asm
    {
      ...
    }

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    ...say...i know it's the wrong forum, but i already have this post, so i guess i'll ask....

    if i read a tutorial about 16 bit assembler would it still work with 32 bit assembler compiler granted i double up the memory values?

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    no...that doesn't work for my compiler.....the ide recognizes the keyword, but then it think i'm trying to declare 'system("PAUSE")'...stupid compiler

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,674
    You're compiler's documentation is the best place to get a small example (if inline assembly is supported by your compiler).

    Here are the docs for GNU and MSVC:
    http://gcc.gnu.org/onlinedocs/gcc-3....l#Extended-Asm
    http://msdn.microsoft.com/library/de...gref___asm.asp

    gg

    [Edit]Jeez, 4 replies in the time it took me to look up those links [/Edit]

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    if i read a tutorial about 16 bit assembler would it still work with 32 bit assembler compiler granted i double up the memory values?
    You would probably have to make more changes that just using 32 bit registers vs 16 bit. Chances are the instruction sets would be different as well.

  9. #9
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Each processor family has its own machine / assembly language. Assembly is NOT portable*. The assembler is specific to the processor, and must be compatible with the compiler when included in a C++ program.

    Assembly is essentially human-readable machine-code. It's WAY easier to write an assembler, than to write a compiler. I've heard old stories of hiring students to "assemble" code by hand! They just used a table to convert each assembly language instruction to it's associated (hex or binary) machine code instruction... No computer knowledge required!

    The original 16-bit x86 processors had something like 30 - 60 instructions. Pentiums have something like 300 instructions.

    *[EDIT]-
    The 'interesting' thing is... the asm keyword IS part of the (portable) standard. But, as soon as you put ANYTHING inside the brackets, your code is no longer standard or portable!

    From the standard

    7.4 The asm declaration

    1. An asm declaration has the form
    asm-definition:
    asm ( stringliteral) ;

    The meaning of an asm declaration is implementation defined.
    [Note: Typically it is used to pass information through the implementation to an assembler. ]
    Last edited by DougDbug; 10-13-2004 at 03:17 PM.

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    You would probably have to make more changes that just using 32 bit registers vs 16 bit. Chances are the instruction sets would be different as well.
    At least on the Intel x86 platforms for IA-32 and IA-64, the only difference between 32 bit and 16 bit instructions is the size of the data type, and the memory address size.

    These can both be overriden even in 16-bit code using 66h and 67h opcode prefixes.
    I believe that 66h is operand size overide and 67h is memory operand size override.

    But this code should work on all x86 systems regardless of whether or not you are in 16-bit or 32-bit. The problem comes when you want to run 32-bit code in a 16-bit environment - as I said you must use the prefixes to do that. The prefixes really are the syntactic equivalent of using the 32-bit version and in fact in the actual binary encoding that is exactly what is happening. But if your compiler does not allow access to EAX you would prefix a mov ax,[value] with a 66h.

    db 66h
    mov ax,[value32]

    This should move value32 into eax if I understand the docs correctly.

    Same with string instructions.

    rep movsw

    This is a 16 bit copy from DS:SI to ES:DI for CX size.

    db 66h
    rep movsw

    This would be a 32-bit copy from DS:ESI to ES:EDI for ECX size.

    Check the Intel manuals for more information.

    I did not show examples for memory address operand size override prefix 67h.
    Last edited by VirtualAce; 10-13-2004 at 04:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc asm code syntax
    By Uberapa in forum C Programming
    Replies: 4
    Last Post: 06-15-2007, 01:16 AM
  2. asm keyword???
    By Mr_Jack in forum C++ Programming
    Replies: 2
    Last Post: 12-18-2003, 11:36 AM
  3. Understanding ASM
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 07-12-2002, 07:39 PM
  4. asm mov
    By manu in forum C++ Programming
    Replies: 1
    Last Post: 12-15-2001, 11:59 AM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21