Funktionsaufruf mit Short (Inlineassembly)



  • Hallo
    Ich lese gerade ein E-Book über Assembly, dort wurde bisher allerdings noch nicht erklärt, wie man eine Konsolenausgabe realisiert, da ich aber die Anweisungen testen möchte, mache ich das ganze im Moment mit Inline Assembly(Visual C++ 2008).
    Das Rahmenprogramm sieht im Moment so aus:

    #include <cstdlib>
    #include <iostream>
    
    void __stdcall printChar(char character)
      {
      std::cout << character << std::endl;
      }
    
    void __stdcall printCharAsNum(char number)
      {
      std::cout << static_cast<int>(number) << std::endl;
      }
    
    void __stdcall printInt(int number)
      {
      std::cout << number << std::endl;
      }
    
    void __stdcall printShort(short number)
      {
      std::cout << number << std::endl;
      }
    
    int main()
      {            
      __asm
        {
        mov eax, 100
        mov ebx, 51
        shrd eax, ebx, 1
        push eax
        call printInt
        }
      system("pause");
      }
    

    Das funktioniert so auch problemlos.
    Wenn ich nun allerdings den asm Block durch folgendes austausche:

    mov ax, 100
        mov bx, 51
        shrd ax, bx, 1
        push ax
        call printShort
    

    Verabschiedet sich das ganze mit einem StackOverflow.
    Warum?



  • Hi!
    Du musst, auch wenn Du nur einen short Wert an Deine Funktion übergibst, einen 32-Bitwert auf den Stack pushen!
    z.B.:

    __asm
     {
        mov  ax, 100
        mov  bx, 51
        shrd ax, bx, 1
        and  eax, 0ffffh // ! 
        push eax
        call printShort
     }
    

    MfG


Anmelden zum Antworten