ASM and C++ in good ol' Turbo 3.0

This is a discussion on ASM and C++ in good ol' Turbo 3.0 within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm writing some code where i mix assembler and C. Now i'm stuck trying to get a value from ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    4

    Thumbs up ASM and C++ in good ol' Turbo 3.0

    Hello,
    I'm writing some code where i mix assembler and C.
    Now i'm stuck trying to get a value from a register(in assembly) to a variable(in C such as a char).

    so:

    asm out 0x44, al; say this was the last assembler instruction
    char value;

    value= what's in 0x44 how do i do that?

    Thanks in advance

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    According to this, Turbo C automatically substitutes the correct instructions when it finds C tokens in your asm.

    C Symbols

    You can use C symbols in your asm statements; Turbo C++ Inline assembly automatically converts them to appropriate assembly references to data language operands and appends underscores onto and functions identifier names. You can use any symbol, including automatic (local) variables, register variables, and function parameters.

    In general, you can use a C symbol in any position where an address operand would be legal. Of course, you can use a register variable wherever a register would be a legal operand. If the assembler encounters an identifier while parsing the operands of an inline assembly instruction, it searches for the identifier in the C symbol table. The names of the 80x86 registers are excluded from this search. Either uppercase or lowercase forms of the register names can be used.
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    so according to your quote, this should work, right?

    int value;
    asm out value, al;

    unfortunately it doesn't work. i get: Invalid combination of opcode and operands

    however,
    asm mov value, 0x01

    works just fine (at least it compiles)

    any ideas?

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Use mov.

    Since you couldn't figure out this on your own and mov is one of the first and most fundamental operations in all of assembly....perhaps you should study up a bit on assembler before trying to use it. I might also add it would be a good idea to get a compiler that was created within the last decade or so.
    Last edited by VirtualAce; 04-05-2010 at 04:18 PM.

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    I'm programming for the casio calculator which is based on the 286 processor thus the need for a prehistoric compiler.
    Well, yes , i got almost zero experience with the x86 instruction set, i just need to use it to access the serial port which is not accessible from C because of the hardware configuration of the calculator.
    The mov comand sends the value '0x01' to the variable but i want to send the contents of a register to a variable.

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,454
    Quote Originally Posted by trennonix View Post
    The mov comand sends the value '0x01' to the variable but i want to send the contents of a register to a variable.
    In Turbo C there were some predefined variables like _EP that give access to registers directly from C - no need in assembler here...

    I do not exactly remember the names - help should answer that (I haven't touched Turbo C more than 15 years...)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    Thanks alot! now I got it working.

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Mov will work for both directions.

  9. #9
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    The 'value' would be assembled as say something like: dword ptr[ebp-4]
    so the line:

    out value,al

    be assembled as:

    out dword ptr[ebp-4],al

    but there is no opcode for this as it is illegal using the 'out' mnemonic:

    you can only have either an immediate value or edx as the first argument:

    out 220,al
    or
    out edx,al

    so if you wanted to open 'value' port you could:

    mov edx,value
    out edx,al

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I don't think the OP was talking about sending data to/from ports.

Popular pages Recent additions subscribe to a feed

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