flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > DOS > Newbie : DOS program from a book wont run

Goto page Previous  1, 2, 3, 4, 5, 6  Next
Author
Thread Post new topic Reply to topic
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)

neville wrote:
There is no right way or wrong way!
...
So there's nothing wrong with limiting your focus initially to a 16-bit real mode environment (which incidentally to this day every X86 CPU still sets up on power-up).
...
Because of all the inconsistencies (idiosyncrasies?) in the X86 architecture, a good grounding in the 16-bit fundamentals won't ever do you any harm!



Just to state the obvious ....

You need a BIOS in order to run an old OS like DOS, which UEFI doesn't always provide (CSM). Hence the (future-proof?) reliance on VMs (and VT-X for ultra speed and compatibility).

The misconception is that a 16-bit OS (like DOS) or simple file format (like .COM) is inherently limited, which isn't true. You can very easily access higher amounts of RAM or newer cpu instructions. Admittedly, trying to do 32-bit (or 64-bit or ...) arithmetic in pure 16-bit is less than obvious, but it's still possible (not counting the extremely easy solution of just directly using 32-bit registers, when available). Similarly, while you can restrict yourself to 64 kb of RAM (or 640 kb or swapping to HD or ...), you also have the option of using EMS or XMS or DPMI or similar to do it for you (even in DOS, even with .COM). Heck, didn't FASM already make that obvious? And it used to be .COM, too!

In fairness, AMD64 is widely considered superior and has now been ubiquitous for several years. Since none of the three major OSes supports DOS anymore (except Win 32-bit, barely, which is going away soon), it's less attractive than it used to be (e.g. 32-bit WinXP, which just turned 15). So, while you can use emulators or 32-bit Windows or DOSEMU (even under x64), it's going far out of your way and for little gain.

If you use and prefer Win64 full-time, you may as well learn AMD64 (and stdcall or whatever). Trying to learn DOS under Win64 is like trying to learn guitar from a drummer. It's still possible, but it's harder than it has to be.

I still like and use DOS, so it's fun for me. I try to give pointers where I can, but overall you just have to really know what you want. It's really not totally reasonable to suggest DOS in this day and age, but discounting it entirely isn't fair either (because of decades of legacy code, web sites, books, tools).
Post 27 Oct 2016, 21:27
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)

rugxulo wrote:
Though I'd honestly recommend (Free)Pascal if all you want to do is learn general computing principles. In particular, it supports inline asm, and it even has a i8086-msdos (cross-)target nowadays. (Just FYI, "asmmode intel" is default for "mode tp" [turbo].)



Here's an overly simple example (although I'm no expert either):

d2x.pas:

Code:

{$mode tp}
program d2x;
var n:byte; err:integer;
  procedure hexbyte(bbyte); assembler;
  asm
    int3
    mov al,b
    mov dx,ax
    mov cl,4
    shr al,cl
    cmp al,10
    sbb al,105
    das
    int 29h
    mov ax,dx
    and al,15
    cmp al,10
    sbb al,105
    das
    int 29h
  end;
begin if paramcount=0 then halt;
  val(paramstr(1),n,err); hexbyte(n); writeln('=',hexstr(n,2))
end.





  • ppcross8086.exe -l- -CX- -a d2x.pas
    (which I think assumes full Win32 FPC 3.0.0 is also installed, not only the cross-compiler, which comes with and uses NASM and WLINK for 16-bit)
  • Small model is default, but you can also use -WmTiny (or Medium or Compact or Large)
  • "grdb d2x.exe 30" (under DOSBox, although GRDB is not included, just a third-party debugger) and then 'g' (go, run from start) will stop execution at "int3", allowing you to 't' (trace, step into) or 'p' (proceed, step over)
  • "mov al,b" automatically becomes "mov al,[bp+4]" (see D2X.S)
  • for 186, change "mov cl,4 // shr al,cl" into "shr al,4" and add "-Cp80186" to compiler cmdline
  • the compiler automatically ends the proc with "mov sp,bp // pop bp" (or 186 "leave") and "ret 2"
  • "int 29h" is just a DOS shortcut to print char in AL to stderr (instead of bloated stdout "mov ah,2 // mov dl,char // int 21h"), the rest is just obscure BCD magic, not worth worrying about irrelevant details here
Post 29 Oct 2016, 23:41
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)

revolution wrote:
Yuck, AT&T syntax is awful.




gas NEWS wrote:

Changes in 2.10 [year 2000??]:

* A new pseudo-op .intel_syntax has been implemented to allow gas to parse i386
assembly programs with intel syntax.




Code:

typedef struct { char low,high; } grouped_char; 

char getHigh(grouped_char chars) {
  char result;
    
  asm(
#ifndef INTEL
    "shr $8,%%ax\n"      // bitshift AH into AL
    "mov %%al,%%bl\n"    // BL <-- AL
#else
    ".intel_syntax noprefix\n"
    "shr ax,8\n"
    "mov bl,al\n"
    ".att_syntax prefix\n"
#endif
     : "=b"  (result)    // resulting char is found in BL
     : "a"   (chars)     // pass char group parameter into AX
  );
  return result;
}


Post 30 Oct 2016, 21:48
View user's profile Send private message Visit poster's website Reply with quote
radarblue



Joined: 10 Oct 2016
Posts: 44
Location: Norway, Oslo

Quote:
Yuck, AT&T syntax is awful.


Hehehe Smile I agree, and especially the GCC. Its just wretched.
I am reading and reading like never before ! RISC and CISC and VLIW-Epic and the 16-20bit, 32bit, 64bit. Real, Unreal, protected mode The emulators required. The CPU and the languages is a rather large topic .

Last problem I encountered, was to make a C_scanf inline numerical value to be picked up into the Register, then exchanged with another value. It remains unsolved for the time being. Another problem, the XCHG inline in GCC didnt exchange properly, it just copied the value from one reg to the other.


Quote:
radarblue, I feel like you don't have focus on what exactly you're trying to learn. Is it general programming or 8086/386 or C or Windows or ... ?

To be honest I am just starting to concieve what I have messed myself into ...! However. I want to learn and I have my favorite book. With the EMU8086 and the C, I have got some results paricularely in making Coiling programs, calculate the number of turns and wire crossections, as it relates coil diameter and lenghts and the Ohm of the wire. And I figure, others have learned it before so why cant I ? Just like electricity, a few years back I knew absolutely nothing of Volts or Ampere and 1200kVA transformers. with time I have learned. Now my book suggests FASM, and the examples are providing some examples. I just can figure it on my own. I have to learn from people who have done this before . Altho the questions and resonemments may seem ... totally wrong .

_________________
Where`s my Amiga ?
Post 31 Oct 2016, 16:52
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 471
8-bit and 16-bit programming are just as important as the 32/64 bit programming. Some low-end modern 'appliances' still use 16-bit microprocessors. Btw, everybody seemed to have forgotten the basic fact that microprocessors know no DOS, Linux or Windows.

The only problem, especially for beginners, is the lack of infrastructure and tools to support such programming on modern OS/CPUs. Emulators can take you to some point ahead, but that won't be far. VM can give you that fake impression but in the end you'll bump into similar restrictions.

So my suggestions, buy a 32-bit PC or if u already have one, put it in a vault. They are good for 16-bit programming. Treasure it like hell. Besides, 32-bit programming still has 50 years more to go before it becomes completely obsolete (call this system error's Law. Forget Newton's Law).

Next suggestion, start anew with 64-bit processors / programming. It's the most ideal bit-ness for most human computational needs and will stay for the next 150-300 years. You can't go wrong with it. FASM will become FASM++ by then.

Next, burn any references on AT&T syntax. AT&T is basically a land-based phone company that has nothing to do with x86 architecture or CPUs. They don't even produce an OS or a useful software to begin with. Their main office is probably operating on Apple computers as we speak! What in the hell???!! A dude on Stackoverflow once advised me to learn AT&T syntax. I replied to him that time & effort needed to learn AT&T syntax is about equal the time & effort I'd need to learn big-endian processors or anything that require reversing your brain's default components. That dude retired from Stackoverflow after that.
Post 31 Oct 2016, 19:10
View user's profile Send private message Reply with quote
radarblue



Joined: 10 Oct 2016
Posts: 44
Location: Norway, Oslo
I think I will do that. Dig up my old Pentium Win32 PC from the basement and start programming on that machine instead, and also learn to get around in DOS (its about time) . I have to make some moves to make this work . To program onto the actual CPU is the way to go, so I can proceed in my study .

The references and examples to 16 and 32 bits are extensive and valuable, information provided on the FASM forum included, very informative ! I will be reading over this plenty of times. Also I will look closer into 64 bit programming as a separate project, when the time comes . And abandon AT&T syntax, it was a digression in my progress.

For now, into the basement and see if the win32 starts up ! I remember I got alot of bluescreens on that machine but inspected the PWB to see that it had bad capacitors, leaky and corroded, then soldered on new Caps. Amazingly it worked. I eventually bought the proper hardware to build a 64bit laters.
Post 01 Nov 2016, 21:26
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)

system error wrote:

Emulators can take you to some point ahead, but that won't be far. VM can give you that fake impression but in the end you'll bump into similar restrictions.



Emulators are fairly good (although very slow without VT-X) but usually lack good support for graphics and sound. Otherwise you'll mostly be fine.


Quote:

So my suggestions, buy a 32-bit PC or if u already have one, put it in a vault. They are good for 16-bit programming. Treasure it like hell. Besides, 32-bit programming still has 50 years more to go before it becomes completely obsolete (call this system error's Law. Forget Newton's Law).



"50 years more"?? That's not true at all. Many 32-bit (even 64-bit) cpus have been obsoleted in the past decade. Look at Alpha, Itanium, VAX, PPC (32-bit only), etc. I would not rely on any 32-bit lasting beyond the next few years. It's quite clear (to me) that most people (OS and compiler devs) want to throw it away too.


Quote:

Next suggestion, start anew with 64-bit processors / programming. It's the most ideal bit-ness for most human computational needs and will stay for the next 150-300 years. You can't go wrong with it. FASM will become FASM++ by then.



While some loose form of "64-bit" may still be available in a decade or two, it won't be what we're used to. Even if the raw instructions are "mostly" compatible (which is far from likely), you're still relying on new OSes, APIs, compilers (and languages/dialects), plus the same old problems (license wars, ugh). Apple is probably the worst (best?) example of this.


Last edited by rugxulo on 02 Nov 2016, 01:55; edited 1 time in total
Post 02 Nov 2016, 01:14
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)

radarblue wrote:
I think I will do that. Dig up my old Pentium Win32 PC from the basement and start programming on that machine instead, and also learn to get around in DOS (its about time). I have to make some moves to make this work. To program onto the actual CPU is the way to go, so I can proceed in my study.



Wait, are you sure your current PC doesn't have a BIOS? My 2009/2010-ish machines both have BIOSes, despite being 64-bit capable, so I can easily boot DOS natively (even via USB). Heck, the Dell laptop has a diagnostics partition that uses (modified) DR-DOS (aka, DRMK).

I didn't mean to unfairly scare you off. I don't have any UEFI machines, so from what I've heard, you can't always rely on a BIOS-like (CSM) compatibility module. It's possible that yours is fine.

But you don't explicitly need a 32-bit only machine.
Post 02 Nov 2016, 01:24
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 254

rugxulo wrote:
Wait, are you sure your current PC doesn't have a BIOS? My 2009/2010-ish machines both have BIOSes, despite being 64-bit capable, so I can easily boot DOS natively (even via USB). Heck, the Dell laptop has a diagnostics partition that uses (modified) DR-DOS (aka, DRMK).

I didn't mean to unfairly scare you off. I don't have any UEFI machines, so from what I've heard, you can't always rely on a BIOS-like (CSM) compatibility module. It's possible that yours is fine.

But you don't explicitly need a 32-bit only machine.

Correct-o. The x64 desktop that I built in 2011 is BIOS-only, while the laptop I bought only a year later was UEFI-only, which won't let me play with my DOS bootdisks.
Post 02 Nov 2016, 01:38
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 471

rugxulo wrote:
"50 years more"?? That's not true at all. Many 32-bit (even 64-bit) cpus have been obsoleted in the past decade. Look at Alpha, Itanium, VAX, PPC (32-bit only), etc. I would not rely on any 32-bit lasting beyond the next few years. It's quite clear (to me) that most people (OS and compiler devs) want to throw it away too.



I don't agree with this one. Computing industry is in its golden years with 32-bit CPUs. People have invested trillions and probably more. Software authors are largely reluctant to take the 64-bit leap. Colleges, schools, and universities, are obviously not ready to let go their 32-bit PC labs, manuals, textbooks, courseware anytime soon. That's sounds like an awful lots of monies for not so obvious benefits.

Companies are not willing to re-train existing employeess. Not to mention book publishers, telcos, web hosting companies, call centers, workplaces etc... these people have no pressing needs to switch to 64-bit world. This thread serves as the best example showing how difficult it is to even totally kill 16-bit spirit looonng after that 80286 era. Stackoverflow is still receiving steady streams of 16-bit questions from all over and now you want to kill 32-bitness that fast? Not a chance bro. Unlike 32-bit CPUs that are reluctant to 16-bit stuff, 64-bit CPUs are extremely permissive to 32-bit thingy. So yeah, based on these, 32-bitness is not going anywhere anytime soon. I give it 50 years and that's minimum.
Post 02 Nov 2016, 08:43
View user's profile Send private message Reply with quote
radarblue



Joined: 10 Oct 2016
Posts: 44
Location: Norway, Oslo
Its a "Wolfdale" Intel Core Duo E8500 3.16Ghz , LGA775 CPU socket . It has a BIOS . Its not a Itanium thing (not IA64). I bought an older CPU and PWB because I needed to migrate the Harddisks via IDE sockets onto the new machine. In the system info / system type it says X64 . Bios mode - Legacy .

Maybe check X64-IA32 . Just a little read .
http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

Personally I think machines all the way into 8 Bits will be forever interesting, particularely in embedded systems, due to the small size and the limited computing needs. Certainly in the Workstations and number crunchers the demand will always be "more" ! Then again, the heavy industry is heavy. and are they interested in changing the complete computing system just because there a new hip chip ? Assembly appears to embrace all the processors however each CPU architecture has its indevidual "skeletons", or building structure ( is that what is called prolog and epilog, starting and ending the program) but share the GPR and Stacks. Thats why I find it facinating. I read that the Assembly language was more or less developed in the 1940s, handcoded for electronic machines. The language is older than any processor on the market. Meaning the CPUs may be developed to understand Assembly in the first place ! I dont know about IA64, but the usual HLL`s are "disassembled" into Assembly before binarys. Assembly is there to stay !

NOGO - GCC wont XCHG

Code:
#include <stdio.h
//C . GCC .  
int main() 
{  
        int x,y,z,w
        printf ("Enter 2 integers : ")
        scanf ("%d %d",&x,&y);
        printf("before xchg\nx y = %d %d\n",x,y);
        
        asm ("mov $0,%%al"
            :"=a"(z)
            );
        
        asm ("mov %%bl,%%al"
            :"=a"(z)
            :"b"(x),"a"(z)
            )
        printf("x = z = %d\n",z)
        
            asm ("mov $0,%%bl"   
            :"=b"(w)            
            );
        
        asm ("mov %%cl,%%bl"   
            :"=b"(w)
            :"c"(y),"b"(w
            )
            
       printf("y = w = %d\n",w);  
       
        asm ("xchg %%bl,%%al"   // define instruction and registers. 
            :"=a"(w)            // define dst register with variable. 
            : "b"(z),"a"(w)     // define operation registers. 
            )
             
        printf("after xchg\nw z = %d %d",w,z)
        return 0
}


Just look at it, its hideous, and it doesnt exchange the numbers . It would be better to easier to write in plain binarys ! There has to be another compiler ... ! Than the GCC . Im actually considering the Intel Parallell Studio XE. Gonna do some more research and see if it does me any good. It seems to lead to Microsoft Visual Studio. Will this be locked to MASM inline in that case ? Intel is NOT Microsoft.
Post 02 Nov 2016, 19:56
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)
It's hard to be objective here.


system error wrote:
I don't agree with this one. Computing industry is in its golden years with 32-bit CPUs. People have invested trillions and probably more. Software authors are largely reluctant to take the 64-bit leap. Colleges, schools, and universities, are obviously not ready to let go their 32-bit PC labs, manuals, textbooks, courseware anytime soon. That's sounds like an awful lots of monies for not so obvious benefits.



As much as I hate the forced migration, it's unavoidable. There was never much intent to keep 32-bit at all unless forced because AMD64 is considered superior in all ways. The fact that 32-bit has lasted this long is only because it's not easy switching everything over, but by now most people have done so.

Take for example the migration away from WinXP compatibility, the forcing of SSE2 in many projects, and of course (my favorite) the deprecation/deletion of all things DOS. The world at large does not care about legacy at all unless forced.

But I agree that existing textbooks and lack of money could slow down the transition, but that's not permanent. 20 years ago Win95 was DOS-based, but by 2007 (Vista, ten years ago) nobody cared anymore.


Quote:

Companies are not willing to re-train existing employeess. Not to mention book publishers, telcos, web hosting companies, call centers, workplaces etc... these people have no pressing needs to switch to 64-bit world. This thread serves as the best example showing how difficult it is to even totally kill 16-bit spirit looonng after that 80286 era. Stackoverflow is still receiving steady streams of 16-bit questions from all over and now you want to kill 32-bitness that fast? Not a chance bro. Unlike 32-bit CPUs that are reluctant to 16-bit stuff, 64-bit CPUs are extremely permissive to 32-bit thingy. So yeah, based on these, 32-bitness is not going anywhere anytime soon. I give it 50 years and that's minimum.



Look, I can flat out guarantee that won't be the case. I have literally seen dozens of projects (OSes and compilers) either force SSE2 for 32-bit or drop 32-bit support entirely. Heck, Windows needs a late-model P4 with NX bit on its 32-bit editions, so that's the last of the 32-bit only cpus. Neither Chrome nor Firefox will work with XP anymore, nor do they run without SSE2, and that too is P4 era. And if you're forcing SSE2 (like Bochs prebuilt binaries also do), you're practically AMD64 anyways since that is part of the standard ABI there. Certain OSes have already dropped 32-bit support (e.g. PC-BSD, aka TrueOS) and others have strongly considered it (Ubuntu?).

http://www.omgubuntu.co.uk/2016/06/ubuntu-drop-32-bit-desktop-iso-image-installer

They'll find all kinds of excuses: "security", "more registers", "faster", "everyone has it", etc. It doesn't matter why or whether it's a good idea, all that matters is that you can't stop them. Sad

For that reason alone, you probably shouldn't write OS-specific or arch-specific code (unless you like emulators). It just doesn't last. Of course truly "portable" code isn't easy either. It's not quite all doom and gloom and totally hopeless, but indeed you'd be wise to hedge your bets by not putting all your eggs in one basket. (For pete's sake, FreeDOS is free, compatible with decades of software, and there is no x86 OS that runs on more processors, yet it is ignored more than anybody. If even WinXP isn't safe from deprecation then nothing is.)
Post 03 Nov 2016, 16:19
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)

radarblue wrote:
There has to be another compiler ... ! Than the GCC . Im actually considering the Intel Parallell Studio XE. Gonna do some more research and see if it does me any good. It seems to lead to Microsoft Visual Studio. Will this be locked to MASM inline in that case ? Intel is NOT Microsoft.



I don't know why you're hung up on C/GCC. Admittedly, maybe you don't grok Pascal, but it's easier than C in many ways. I think FPC is a better choice overall, for various reasons.

Don't waste your money on Intel's expensive compiler unless you seriously know exactly what you want to do. (Besides, the Linux version is allegedly freeware for non-commercial use.)

Allegedly, not that I've tried, MSVC Express is freeware (but huge download) and comes with MASM (but their 64-bit compiler doesn't allow inline asm at all).

If all you want to do is mix 32-bit assembly and C, then read Paul Carter's book (thus you can easily use GCC and FASM but only via separate .asm files / .o modules, not inline).

Why didn't you use OpenWatcom again? From what I recall, you got confused and downloaded the Fortran (only) installer, not the C/C++ one. Grab the Win32 C/C++ installer here (or here mirrored).

Actually, there are various C compilers that allow inline assembly (and not using cursed GAS / AT&T brain rot): CC386 (includes NASM), SmallerC (click "Clone or Download" button, still needs NASM or YASM).
Post 03 Nov 2016, 22:36
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)

radarblue wrote:
Just look at it, its hideous, and it doesnt exchange the numbers.



You're (apparently) doing this:


Code:

mov al,0
mov al,bl ; clobbers the 0
printf ; clobbers almost everything

mov bl,0
mov bl,cl ; clobbers the 0
printf ; clobbers almost everything
       
xchg al,bl ; your values weren't saved and thus were overwritten
printf ; probably prints garbage




I haven't run this natively, but that's a quick guess.
Post 03 Nov 2016, 23:07
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14672
Location: Origae-6

rugxulo wrote:

radarblue wrote:
Just look at it, its hideous, and it doesnt exchange the numbers.



You're (apparently) doing this:


Code:

mov al,0
mov al,bl ; clobbers the 0
printf ; clobbers almost everything

mov bl,0
mov bl,cl ; clobbers the 0
printf ; clobbers almost everything
       
xchg al,bl ; your values weren't saved and thus were overwritten
printf ; probably prints garbage




I haven't run this natively, but that's a quick guess.

I think you missed the assignments of the zero value to the C variables each time the asm block is closed. So the zero value is not necessarily wasted.

C calling convention only "clobbers" EAX, ECX, EDX and EFLAGS. I wouldn't call that "almost everything".

The final "xchg al,bl" will print the return value from printf (in EAX) as a split value between EBX (not clobbered by printf) and EAX.

Although I am not sure what the C code will do with "int x" and assigning AL to x. Does it zero extend, or sign extend, or just replace the lower 8 bits? Or is the behaviour undefined within C?


Last edited by revolution on 03 Nov 2016, 23:48; edited 1 time in total
Post 03 Nov 2016, 23:17
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)
Honestly, it would be easier for him to step through with a debugger, e.g. OpenWatcom's WD. (Of course, that's 32-bit only.) That way he could see all the registers. (Or maybe RHIDE although that's been obsolete and abandoned for over a decade. Still works and is fairly easy to use but not maintained at all, and the DJGPP port only supports COFF debug info, which is also mostly deprecated.)

Another alternative (that I haven't tried but looks very promising) is using the aforementioned 64-bit C + assembly book by Ray Seyfarth, who uses his own homegrown IDE (ebe) that makes this all incredibly easy (as frontend to YASM + LD + GDB). I didn't want to push too hard to goad the OP into buying it, but apparently the digital version is only $5 USD, so that's not too prohibitive. Of course, ebe is free (SF.net) and comes with free compiler tools (MinGW, etc.), so he could always just try that first.
Post 03 Nov 2016, 23:46
View user's profile Send private message Visit poster's website Reply with quote
radarblue



Joined: 10 Oct 2016
Posts: 44
Location: Norway, Oslo
I read thru the getting started on the Openwatcom and it is up and running in 64bit, win10. However making an Assembly inline, seems to be using a macro called #PRAGMA AUX. And certainly there is a special way to claim the ASM. that I find nowhere.
LINK1 : http://users.pja.edu.pl/~jms/qnx/help/watcom/compiler-tools/pragma32.html#AuxiliaryPragmas

LINK2 : http://www.azillionmonkeys.com/qed/watfaq.shtml#6

LINK3 : https://users.pja.edu.pl/~jms/qnx/help/watcom/compiler-tools/cpasm.html#Tutorial


program inline NOGO.

Code:
     #include <stdio.h
     int main()
//openwatcom v2.0 . bnnt64 . win10.
//Exhange 2 numbers using Assembly in C.
     { 
        int x,y,rslt1,rslt2,a;
        
        printf ("Enter 2 numbers: ");
        scanf ("%d %d",&x,&y);
        printf ("x=%d y=%d",x,y);

        __asm
        #pragma aux // <------------------Macro Error for the Assembler.
          
        "    eax,x              "\
        "    ebx,y              "\
        "    xchg x,y           "\
        "    mov rslt1,x        "\
        "    mov rslt2,y        "\
           

         printf ("x=%d y=%d",rslt1,rslt2);
         printf("Press any key to exit...\n")
         scanf ("%d",a); // prohibits program to quit.
         return 0;
     }



And WOW. I managed in the EMU8086 to enter 4 characters from the keyboard move 2 values, fromto BX, then from BX into DI with displacement, then from DI to CX free up the BX, then display BX. Then move additional 2 Values into BX, erasing the former value and storing them into DI plus displacement. Stoked !

Program is a GO.

Code:
;xchg_2_characters . EMU8086
.stack
.data
parlist label byte  ; parameter list
maxlen db 7
actlen db ?
opfld db 7 dup (?; operand field

prmpt db 0dh,0ah"Enter 4 characters:$"
rslt1 db 0dh,0ah"Before exchange =            $"
rslt2 db 0dh,0ah"After exchange =             $"

.code
proc
    ;set up program
    mov ax,@data
    mov dsax
    
    ;read prompt
    mov ah,09h      ;display string
    lea dx,prmpt    ;load adress of prompt DX data register
    int 21h         ;DOS interrupt
    
    ;keyboard return to enter characters
    mov ah,0ah      ; buffered keyboard input
    lea dx,parlist  ; load adress of parlist
    int 21h
    
    ;store characters from opfld to bl and bh
    mov bl,opfld    ;get 1t character
    mov bh,opfld+1  ;get 2nd character
     
    mov [di+1],bl
    mov [di+2],bh
    
    mov cl,[di+1]
    mov ch,[di+2
   
    ;display original character
    mov rslt1+20,bl
    mov rslt1+22,bh 
    
    mov bl,opfld+2
    mov bh,opfld+3  
    
    mov [di+3],bl
    mov [di+4],bh 
    
    mov rslt1+24,bl
    mov rslt1+26,bh
    
    mov ah,09h
    lea dx,rslt1
    int 21h
    
    ;exchange characters
    xchg cl,ch
    
    ;display swapped characters
    mov rslt2+20,cl
    mov rslt2+22,ch 
    
    mov cl,[di+3]
    mov ch,[di+4]
    
    xchg cl,ch 
    
    mov rslt2+24,cl
    mov rslt2+26,ch
        
    mov ah,09h
    lea dx,rslt2
    int 21h
    
    endp




To learn C is just an excuse to learn Assembly. The inline is part of the deal.[/url]


Last edited by radarblue on 06 Nov 2016, 00:58; edited 1 time in total
Post 05 Nov 2016, 18:55
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2109
Location: Usono (aka, USA)

radarblue wrote:
I read thru the getting started on the Openwatcom and it is up and running in 64bit, win10. However making an Assembly inline, seems to be using a macro called #PRAGMA AUX. And certainly there is a special way to claim the ASM. that I find nowhere.

LINK2 : http://www.azillionmonkeys.com/qed/watfaq.shtml#6




Paul Hsieh wrote:

Starting with version 11.0 WATCOM C/C++ supports the "_asm" language extension, purely as a compatibility feature as most other PC based C compilers use it. WATCOM still recommends the use of the #pragma aux method since it gives you and the compiler far more control. Refer to the online documentation.




Quote:

//openwatcom v2.0 . bnnt64 . win10.



2.0 (despite some 64-bit support) has not been officially released or well tested, so it's probably fairly unstable. So I don't recommend using that over 1.9.

Nevertheless, the latest 2.0-pre builds that I could find (untested by me) are here.


Quote:
To learn C is just an excuse to learn Assembly. The inline is part of the deal.



I'm not sure that's the best way, but you can use WD (even with WASM output). I've never used Emu8086, so I don't know how helpful it is (compared to true native debuggers).
Post 05 Nov 2016, 21:45
View user's profile Send private message Visit poster's website Reply with quote
radarblue



Joined: 10 Oct 2016
Posts: 44
Location: Norway, Oslo

Quote:
Paul Hsieh wrote : Starting with version 11.0 WATCOM C/C++ supports the "_asm" language extension,

... He has to mean Watcom v1.1 ?

From the instructions I see used in the book of mine, mnemonics like CMOVBE, CMOVGE, when searching them up I see that these were introduced in the Pentium P5 (586) era of time. To get a CPU that match the examples in the book, Pentium is the platform. I got to get into the FASM structure, for this supports Pentium.

I have a question. when somebody makes a computer game for instance. Do they have to include the Compiler into the program. For as I understand it the OS doesnt come with compilers, neither can a computer game know where the different compilers are in the machine, if there are compilers installed ?
Post 06 Nov 2016, 01:38
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 254

radarblue wrote:

Quote:
Paul Hsieh wrote : Starting with version 11.0 WATCOM C/C++ supports the "_asm" language extension,

... He has to mean Watcom v1.1 ?

Before Watcom became OpenWatcom, it used a different set of version numbers.

radarblue wrote:
I have a question. when somebody makes a computer game for instance. Do they have to include the Compiler into the program. For as I understand it the OS doesnt come with compilers, neither can a computer game know where the different compilers are in the machine, if there are compilers installed ?

No. If a game is compiled with a compiler that converts source code into native machine code, as does virtually all C compilers, the compiler does not need to be packaged with the game. It will run by itself.

If a game comes with interpreted code (see scripting languages Python, Lua, JavaScript, etc.), then a interpreter needs to be included with the game in order to make sense of them.

If a game comes with code that has been compiled to intermediate bytecode, it needs a runtime to run the bytecode binaries. Most of the time, these will be installed separately on the operating system and don't need to be included. See the runtime environments JVM and CLR. Languages that compile to bytecode include Java, Kotlin, C#, and VisualBasic.
Post 06 Nov 2016, 03:33
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5, 6  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.