News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Visual Studio 2017 CPP with _asm - simple code not working?

Started by trent.mahaffey@gmail.com, January 02, 2020, 03:17:54 PM

Previous topic - Next topic

trent.mahaffey@gmail.com

//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

hutch--

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.

trent.mahaffey@gmail.com

 :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.

hutch--

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.

TimoVJL

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.
May the source be with you

Vortex

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.

avcaballero


JonasS

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.

TimoVJL

Microsoft Visual C++ Version 1.52c was the last product for 16-bit code ?
May the source be with you

Vortex

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.