The MASM Forum

General => The Campus => Topic started by: trent.mahaffey@gmail.com on January 02, 2020, 03:17:54 PM

Title: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: trent.mahaffey@gmail.com on January 02, 2020, 03:17:54 PM
//EXAMPLE 7–1
//Accepts and displays one character of 1 through 9,
//all others are ignored.
void main(void)
{
   _asm
   {
      mov ah, 8; read key no echo
      int 21h;
      cmp al, '0'; filter key code
      jb big;
      cmp al, '9';
      ja big;
      mov dl, al; echo 0 – 9
      mov ah, 2;
      int 21h;
      big :
   }
}

My compiler says there are the following problems:
example7_1.cpp(10): error C2443: operand size conflict
example7_1.cpp(12): error C2443: operand size conflict

those lines are the compare instructions. I don't understand, the ASCII value of '0' in binary is 00110000 and '9' is 00111001. This are only 8 bits, so how is there a size conflict with AL - an 8-bit register?

Here is a snip of the textbook example I copied. Thanks in advance

https://imgur.com/37DlBdK
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: hutch-- on January 02, 2020, 03:57:28 PM
It is 16 bit MS-DOS real mode code, it will not work in 32 or 64 bit protected mode. VS2017 should only be 32 or 64 bit code, to use assembler in 32 bit code you can use inline assembler, with the 64 bit version you must use ML64 to create 64 bit code.
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: trent.mahaffey@gmail.com on January 03, 2020, 02:23:00 PM
 :rolleyes:
So, my textbook has the code I just posted above demonstrating the inline assembler using Visual Studio 2008, and your saying this is MS DOS 16-bit code!? What is going on here!?

Here's the book I'm using. Page 224 is the sample code using Visual Studio in Widows:

https://electrobian.files.wordpress.com/2016/07/prentice-the-intel-microprocessors-8th-edition-0135026458.pdf

Thanks again.
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: hutch-- on January 03, 2020, 02:33:23 PM
Trent,

I simply don't have time to read out of date books for MS-DOS 16 bit assembler. The code is easily recognisable as 16 bit, 16 bit registers which cannot hold 32 or 64 bit addresses and it uses very old MS-DOS interrupts which simply don't work in protected mode software and operating systems. Save yourself the hassle of playing with this old junk, depending on whether you are writing 32 or 64 bit C, write assembler for the either 32 bit or 64 bit. It is far more powerful than old DOS junk.
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: TimoVJL on January 03, 2020, 09:01:45 PM
page 224:
QuoteTo build a 16-bit DOS application, you will need the legacy 16-bit compiler usually found
in the C:\WINDDK\2600.1106\bin\win_me\bin16 directory of the Windows DDK. (The
Windows driver development kit can be obtained for a small shipping charge from Microsoft
Corporation.) The compiler is CL.EXE and the 16-bit linker program is LINK.EXE, both located
in the directory or folder listed.
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: Vortex on January 04, 2020, 04:57:55 AM
Hi trent,

Nowadays, 16-bit coding has very narrow usage area and it's outdated. Better to move to 32-bit and 64-bit programming.
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: avcaballero on January 04, 2020, 05:51:22 AM
If you want to use 16 bits programs, maybe you should use DosBOX (https://www.dosbox.com/)
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: JonasS on January 04, 2020, 11:27:54 PM
I like coding 16-bit with a simple editor then assemble with MASM 6. Forget Visual Studio. I think Visual Studio never handled 16-bit inline, even 2005, but can not guarantee.
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: TimoVJL on January 05, 2020, 01:38:29 AM
Microsoft Visual C++ Version 1.52c was the last product for 16-bit code ?
Title: Re: Visual Studio 2017 CPP with _asm - simple code not working?
Post by: Vortex on January 05, 2020, 03:07:57 AM
Quote from: JonasS on January 04, 2020, 11:27:54 PM
I like coding 16-bit with a simple editor then assemble with MASM 6.

For your information, Masm Version 6 can assemble 16-bit code. You can try ml.exe coming with the Masm32 package.