Assembly from DOS to QT



  • I have some old code, for a game utility written in Assembly. The code compiles in Watcom 11. I'm out of luck compiling it in QT Creator. I looked through tutorials, books and what not. How does one approach to convert the below to something Creator can process?

    @#pragma aux scale =
    "imul ebx",
    "idiv ecx",
    parm [eax][ebx][ecx]
    modify [eax edx]\

    #pragma aux mulscale =
    "imul ebx",
    "shrd eax, edx, cl",
    parm [eax][ebx][ecx]
    modify [edx]@

    I forgot - the above is WASM - used to be the best way to program in 1994 :)



  • Please remember it's Qt and not QT (QuickTime).



  • This has nothing to do with Qt\QtCreator as far as I can tell.

    Qt is just C++. Your compiler handles the C++ and assembly.
    If your compiler handles WASM, it'll work. Most likely it'll need to be converted to AT&T or Intel style assembly depending on compiler.

    Which compiler are you using in QtCreator?
    In MSVC you just use:
    @__asm {
    ...
    }@



  • If you have the "default" Qt SDK for windows, you are using gcc. One of many description how to do inline assembler in gcc can be found "here":http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html



  • Thanks for all your responses. :D

    to Vcsala – It's QT Creator not QT SDK nor Quicktime.

    to xsacha – that's the first thing I tried before I posted. Creator seems to want something more.

    to Gerolf Reinwardt - The compiler that ships with QT-Creator is MingW. WASM is part of the (Intell) x86 – Windows, DOS family, and MingW/GCC expects Unix? Would you know of hand a web site or book that defines the core differences? The link is helpful, but it assumes I know the differences, right now I do not. :(



  • Actually it is Qt Creator...



  • Thank you Vcsala :)

    For all others: The topic has how now drastically changed. I need to figure out how to implement WASM, an Intel's x86 assembly language, into Qt Creator.



  • [quote author="Taamalus" date="1292694059"]to Vcsala – It's QT Creator not QT SDK nor Quicktime.[/quote]Vcsala was referring to the fact that Qt is spelled with capital Q and small t. That goes for both creator and the sdk. QuickTime is spelled with capital QT. But hey, it's off-topic.

    On-topic: Inline assembly is always dependent on environment, target processor and compiler. Chances are that if you're porting 15 year old code, there is no good reason to stick to the assembly implementation and just use C++ code instead. It's much more portable and the difference in performance will pass by unnoticed -- both because the systems are much faster now, and because your average compiler has become much more effective at optimization.



  • bq. Taamalus wrote
    The compiler that ships with QT-Creator is MingW. WASM is part of the (Intell) x86 – Windows, DOS family, and MingW/GCC expects Unix? Would you know of hand a web site or book that defines the core differences? The link is helpful, but it assumes I know the differences, right now I do not. :(

    The compiler is not platform dependant. How inline assembler works always depends on the compiler.

    So you see, inline assembler is not standardised. What is standard is the commands, that exist, but the order of the parameters, how you inle the assembler, how you access the parameters, you put from C/C++ to assembler and vice versa is totally different. I already did inline assembler on a multi platform project that uses MSVC for windows and gcc for linux embedded. It was really challenging as you had to write the assembler totally twice and different.



  • By the way. the command you can use in the assebler code depend on the processor platform you use (X86, x386, sparc, ...). So the assebmler commands depend on that. But mostly on common linux and windows machines, you wil find x386 architecture.



  • [quote author="Taamalus" date="1292697516"]For all others: The topic has how now drastically changed. I need to figure out how to implement WASM, an Intel's x86 assembly language, into Qt Creator.[/quote]

    That's not a matter of Qt Creator, as it is only an IDE that integrates an editor, compiler, linker, debugger and some other tools into a nice graphical user interface.

    Assembler code is highly dependend on your platform (i386, x86_64, ppc, ppc64, etc.) and the compiler/tool chain (gcc, MS Visual Studio toolchain, intel, etc.).

    You should search on the web for the details of your specific combination of the above. Maybe there are some hints on how to port from one tool chain to another.



  • To Gerolf Reinwardt – Those links were an eye opener. This is anything but simple to use.

    To Volker – Great. :( Since Qt Creator is cross-platform it can't adapt an Assembly Version.

    To Franzk – You are now the second person to suggest to look seriously into rewriting the code into straight C++. You would not know a good book to read? I have three about Assembly (ancient), none of which even mention C or C++. - Yes, we are off topic. PM me if this is more appropriate.



  • Taamalus, see books about C++ and Qt on "this wiki page":http://developer.qt.nokia.com/wiki/Books_and_Links_for_learning_C_and_advanced_topics.



  • [quote author="Taamalus" date="1292716462"]To Volker – Great. :( Since Qt Creator is cross-platform it can't adapt an Assembly Version.
    [/quote]

    Look, this has nothing to do with Qt or Qt Creator.

    If you want to target a single platform, continue using your Assembly code in the compiler that supports it. If the compiler supports C++, you can use Qt too.
    Just because Qt is cross-platform doesn't mean you need to use cross-platform code.

    It works the same as if you were using plain C++.

    WASM isn't supported by any mainstream compiler so if you want to continue using it and don't care about being cross-platform, just convert it to what your compiler uses.
    The default is MingW/GCC with QtCreator.

    Any assembly code you can do within C++ in any other mainstream IDE, you can do in Qt with QtCreator.



  • [quote author="Taamalus" date="1292716462"]To Volker – Great. :( Since Qt Creator is cross-platform it can't adapt an Assembly Version.[/quote]
    Qt Creator is neither the compiler nor an assembler. It works on what the underlying tool chain provides. This is gcc/g++/ld in the gnu/linux/mac world, it's the Visual Studio tool chain its the Microsoft compiler, with MinGW on Windows it's again gcc. Each of them may have another syntax for assembly language. Each of them works on different platforms (read: processor families like Intel x86 and siblings, PowerPC, ARM, and so on). You would have the very same problems with the native development environments. Qt libs and Qt creator cannot help you in this domain, which is logical programming a CPU by assembly language is by its nature very platform dependent.

    [quote author="Taamalus" date="1292716462"]To Franzk – You are now the second person to suggest to look seriously into rewriting the code into straight C++. You would not know a good book to read? I have three about Assembly (ancient), none of which even mention C or C++. - Yes, we are off topic. PM me if this is more appropriate.[/quote]

    You must understand the old code. What does it do? What's the flow of control, the data structures? etc. Then you should be able to reimplement this in plain C or C++. I don't know of any special book about this topic. We do have a wiki page on C++ books "here":http://developer.qt.nokia.com/wiki/Books_and_Links_for_learning_C_and_advanced_topics. Books about assembly language do seldom cover the links to "higher" programming languages.



  • [quote author="Volker" date="1292717715"][quote author="Taamalus" date="1292716462"]To Volker – Great. :( Since Qt Creator is cross-platform it can't adapt an Assembly Version.[/quote] Qt Creator is neither the compiler nor an assembler. It works on what the underlying tool chain provides. This is gcc/g++/ld in the gnu/linux/mac world, it's the Visual Studio tool chain its the Microsoft compiler, with MinGW on Windows it's again gcc. Each of them may have another syntax for assembly language. Each of them works on different platforms (read: processor families like Intel x86 and siblings, PowerPC, ARM, and so on). You would have the very same problems with the native development environments. Qt libs and Qt creator cannot help you in this domain, which is logical programming a CPU by assembly language is by its nature very platform dependent.

    You must understand the old code. What does it do? What's the flow of control, the data structures? etc. Then you should be able to reimplement this in plain C or C++. I don't know of any special book about this topic. We do have a wiki page on C++ books "here":http://developer.qt.nokia.com/wiki/Books_and_Links_for_learning_C_and_advanced_topics. Books about assembly language do seldom cover the links to "higher" programming languages.[/quote]
    That was not an complained about Qt Creator but one about Assembly. Until I posted my question and received the forum's feed back I never realized how diverse Assembly is. I assumed a low level language would come more standard.

    That also cancels my second question for a book. Unless someone converted WASM code into C++ and wrote a book about it, there wont be any books available for me to use. - Therefore I'll do as you suggest! This is anything but simple. :D



  • Well it's actually the opposite. The lower level the language is, the less platforms and architectures it generally covers.

    Higher-level interpreted languages like scripts and interpreted languages run on pretty much anything (think javascript, html, python).

    Qt is sort of special because it is C++ which isn't as high-level (it's closer to assembly) and yet, it is cross-platform (many operating systems and architectures are supported).

    Assembly is pretty much machine code (1:1 map) for individual architectures and compilers (which generally differ dependent on platform) generally choose different syntax.

    It works this way because, as you add layers of syntax and language the idea is to make it simpler to program in. In doing so, you usually add a type of method that performs several lower level types and methods in a way that is consistent through many platforms and architectures.



  • [quote author="Taamalus" date="1292725209"]Unless someone converted WASM code into C++[/quote]

    More than 15 years ago I remember there was a tool doing this kind of reverse engineering (at least for C), but as I remember the resulting code was rather unreadable.



  • [quote author="Taamalus" date="1292725209"]That was not an complained about Qt Creator but one about Assembly. Until I posted my question and received the forum's feed back I never realized how diverse Assembly is. I assumed a low level language would come more standard.[/quote]

    Ah, sorry. I misunderstood this. I cannot imagine anything other that is more platform dependend than assembly code :-) It is the lowest end of programming, since you directly manipulate the processor, i.e. load/save registers, ask the processor to do some math, etc. All that depends on the processor itself: how many registers are there, is it a "RISC":http://en.wikipedia.org/wiki/Reduced_instruction_set_computing or "CISC":http://en.wikipedia.org/wiki/Complex_instruction_set_computer architecture, and so on. Regarding this nature of assembly language, it's clear, that it's quite impossible to standardize this :-)

    [quote author="Taamalus" date="1292725209"]That also cancels my second question for a book. Unless someone converted WASM code into C++ and wrote a book about it, there wont be any books available for me to use. - Therefore I'll do as you suggest! This is anything but simple. :D[/quote]

    This task (writing a book) would be quit impossible. Assembler code mostly used to do some time critical tasks and is often hand optimized. One has to reverse-engineer the code and understand what it does, to back-translate it into a higher level language like C or C++.



  • [quote author="Taamalus" date="1292716462"]You are now the second person to suggest to look seriously into rewriting the code into straight C++.[/quote]It only makes sense. It will improve maintainability and readability. It'll just cost you the extra time of translating (I understand it's fully written in assembly?).

    [quote author="Taamalus" date="1292716462"]You would not know a good book to read? I have three about Assembly (ancient), none of which even mention C or C++.[/quote] A book about converting asm to c/c++? I wouldn't know of any. Besides, I don't think I'd want one. You have to actually reverse engineer the thing. Find out what the assembly does and rewrite it. It'll be worth the effort in the end if you're going to maintain that project.



  • [quote author="Franzk" date="1292834690"]It only makes sense. It will improve maintainability and readability. It'll just cost you the extra time of translating (I understand it's fully written in assembly?). -cut- Find out what the assembly does and rewrite it. It'll be worth the effort in the end if you're going to maintain that project. [/quote]
    It's sort of half and half. Half is Assembly the other is C. I don't think it will make a difference, if it does, please let know.

    I consider this thread (topic) closed. The unanimous answer is given now by all parties involved, thanks to all who took the time to give the input.



  • Hi Taamalus, if you want to close the thread, plesae send a small note to one of our forum admins ("denis":http://developer.qt.nokia.com/member/222 or "chetankjain":http://developer.qt.nokia.com/member/1186) our "Qt admins":http://developer.qt.nokia.com/wiki/Admins so they close the topic.
    Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.