The MASM Forum

Miscellaneous => Irvine Book Questions. => Topic started by: ISM34 on October 21, 2016, 04:22:54 AM

Title: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: ISM34 on October 21, 2016, 04:22:54 AM
I am trying to run the following code in Visual Studio 2015 that has MASM built in to it. I am trying to link the Irvine library files to the program. However, I get like 49 of the following errors.


A2C \Irvine\SmallWin.inc(11)or specified size
A2C \Irvine\SmallWin.inc(12)or specified size
A2C \Irvine\SmallWin.inc(299)for specified size


Here is my code


ExitProcess PROTO

includelib C:\Irvine\Kernel32.Lib
includelib C:\Irvine\User32.Lib
includelib C:\Irvine\Irvine32.lib
include Irvine32.inc

.data
str1 BYTE "This line is displayed in color",0

.code
main PROC

mov eax, black + (white * 16) ; black on white backgrouund
mov ecx,4 ; loop counter

L1: call SetTextColor
mov edx,OFFSET str1
call WriteString
call Crlf
add eax,2 ; add 2 to foreground color
loop L1

call ExitProcess
main ENDP
END

Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: jj2007 on October 21, 2016, 05:06:15 AM
Quote from: ISM34 on October 21, 2016, 04:22:54 AM
A2C \Irvine\SmallWin.inc(12)or specified size

Garbled error messages... looks suspiciously like a known bug in the latest MASM version (http://masm32.com/board/index.php?topic=5662.msg60775#msg60775) ::)

Anyway, unless you have a really convincing excuse for using a) the Irvine lib on b) that VS behemoth, you'd better switch to Masm32. Assembler is fun, but you need the right tools for it :bgrin:

Welcome to the forum :icon14:
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: ISM34 on October 21, 2016, 08:04:26 AM
Do you suggest I download the MASM32 software to write my code? Should I download the MASM32 SDK Version 11 from masm32.com (http://masm32.com)? Are there tutorials or videos that provide help on how to use the software? I am new to programming in assembly language. I assume with MASM32 I can still import the Irvine libraries to compile my programs?

Thank you.

Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: hutch-- on October 21, 2016, 08:30:16 AM
> I assume with MASM32 I can still import the Irvine libraries to compile my programs ?

Not necessarily, the entire masm32 system is designed around proper compliance with the Intel ABI for production code where the Irvine libraries are designed for undergraduates who are doing a term in assembler language. Also the API call "ExitProcess" has an error code argument. You should be using,

push 0
call ExitProcess
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: mineiro on October 21, 2016, 08:38:42 AM
Quote from: ISM34 on October 21, 2016, 08:04:26 AM
Do you suggest I download the MASM32 software to write my code?
Masm32 is in my opinion the best assembly package that I ever see. No doubt about this.
Have good assemblers around the world, but about a package, masm32 is the best.
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: jj2007 on October 21, 2016, 09:50:31 AM
Quote from: ISM34 on October 21, 2016, 08:04:26 AM
Do you suggest I download the MASM32 software to write my code? Should I download the MASM32 SDK Version 11 from masm32.com (http://masm32.com)? Are there tutorials or videos that provide help on how to use the software? I am new to programming in assembly language. I assume with MASM32 I can still import the Irvine libraries to compile my programs?

4 x YES. As Hutch writes above, the Irvine libraries are not the best choice, but you can import them indeed. After the installation (detailed steps here (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm)), you should open one of the examples in \Masm32\examples in \Masm32\qeditor.exe and check the build menus.
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: ISM34 on October 22, 2016, 02:34:05 AM
Can you do 64 bit programming in MASM32?
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: jj2007 on October 22, 2016, 02:52:15 AM
Yes. But you should learn walking before trying to run the marathon :bgrin:
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: rrr314159 on October 22, 2016, 03:40:06 AM
Quote from: jj2007 on October 22, 2016, 02:52:15 AM
Yes. But you should learn walking before trying to run the marathon :bgrin:

I'd say "yes and no". The best way for a student to get to 64-bit is to learn 32-bit first with masm32. Then 64 is a natural evolution, pretty straightforward. But by the time you replace the 32-bit libraries with 64, and so forth, it's a stretch to say you're still using "masm32".

Also, I think a better analogy might be: 32-bit is like learning to walk. 64-bit is like learning to walk with 40 pounds of lead in your backpack.
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: Zen on October 22, 2016, 08:14:59 AM
Hi, ISM34,
Here at the MASM Forum, we get a lot of questions from novice assembly programmers about problems they are having using the IRVINE32 Libraries and include files in very simple programs compiled with ml.exe (the COMPILER that comes with the MASM package) or Visual Studio.

Quote from: ZEN"I found the Fifth Edition [Assembly Language for x86 Processors, Kip Irvine] in the Library at the University of California,...and, I couldn't find anything else at that level, so I bought it.
It has many problems, though,...and, we get a lot of questions here at the MASM Forum from novices trying to use his source code examples and compiled libraries with the usual header files and libraries that are an integral part of the MASM package. They are not really compatible. Kip writes overly simplistic code, and his examples are designed to be used only with other routines from the Irvine library (his routines usually don't take any parameters, and don't return anything). This just confuses novice MASM programmers, who when compiling simple programs generate a lot of annoying errors, and, are lost when trying to call routines from Irvine's libraries that are included in the typical initial code of a MASM program."

Try the Forum Search feature, searching the Campus for the phrase IRVINE32.

Typical Irvine problem threads:
Irvine32 library, May 2016 (http://masm32.com/board/index.php?topic=5354.msg57371)
x86 Assembly Beginner: Need help debugging a mess, May 2016 (http://masm32.com/board/index.php?topic=5347.0)
If you know how to use Visual Studio and Irvine's resources for masm, help me!, Feb 2016 (http://masm32.com/board/index.php?topic=5096.0)
How to print out values in MASM syntax?, June 2015 (http://masm32.com/board/index.php?topic=4355.0)
need help getting started , Mar 2015 (http://masm32.com/board/index.php?topic=4092.0)
LNK2001 error Irvine32.inc , Feb 2015 (http://masm32.com/board/index.php?topic=4039.0)
My first post: Array of Strings in Assembly, Aug 2014 (http://masm32.com/board/index.php?topic=3519.0)
Some starter questions about assembly language, July 2013 (http://masm32.com/board/index.php?topic=2140.0)
Irvine32 library problem, June 2013 (http://masm32.com/board/index.php?topic=2029.0)

...It goes on and on,...:bgrin:
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: ISM34 on October 24, 2016, 10:51:32 AM
Thank you to everyone who has replied to my post. I appreciate the help. I went ahead and downloaded MASM32 and installed it. I tried running the following code:

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc

include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib


.data
str1 BYTE "This line is displayed in color",0

.code
start:

mov eax, black + (white * 16) ; black on white backgrouund
mov ecx,4 ; loop counter

L1: call SetTextColor
mov edx,OFFSET str1
call WriteString
call Crlf
add eax,2 ; add 2 to foreground color
loop L1


END start


I receive the following error message:

error A2006: undefined symbol: black
error A2006: undefined symbol: SetTextColor
error A2006: undefined symbol: WriteString
error A2006: undefined symbol: Crlf


Since I am trying to use the Irvine library functionality, do I need to include this line of code?

include \irvine\irvine32.inc


Do I also need to include this line of code?

includelib \irvine\irvine32.lib


Last question, is this line of code necessary, and what does it do?

include \masm32\include\windows.inc


Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: rrr314159 on October 24, 2016, 12:19:52 PM
The code as it stands should, indeed, give those error messages. You haven't defined "black" anywhere, for instance. But you've got the right idea: you need the correct includes and libraries.

The best way to start with masm32 is just this single include,

include \masm32\include\masm32rt.inc

which contains all the standard incs and libs you'll need. But it still doesn't define "black"! To do so, there's a missing line something like (not sure exactly)

black equ 1

If you put that line at the top that one error message will go away, but of course it still won't work. For one thing, it will give the same error message about "white". I'm guessing you must have glommed together some Irvine32 code with some masm32 headers. You certainly didn't find an example that was written just the way you present it.

I've never used irvine32 and don't want to, but others may be able to tell you how to fix this. Maybe you can simply throw in some more includes from irvine32, as you suggest, but I doubt it's that simple. There will be conflicts.

windows.inc often needs to be included. It defines a bunch of routines and symbols of general utility, just like other .inc files do. But masm32rt.inc takes care of that and all the other standard files automatically.

AFAIK it's no good to try to mix irvine32 and masm32. Once you understand both it can be done but it's not a beginner project. Therefore I, and probably everyone else here, recommend to just forget about irvine32 for the time being. Spend a week or a month getting used to masm32, by itself, see how that goes. You've got the right first step: find an example, and get it working. But this example wouldn't be the one to start with. There are lots of them in \masm32\examples. But I'd rather let jj2007, or others, recommend where to start. Many people are on top of beginner stuff, I'm not.

Perhaps the best reason to use masm32 is, all of us here can (and will) help you. But we can't do that with irvine32. It's not that masm32 is better (although I'm pretty sure it is) rather the user community is a lot better.

Good luck!
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: jj2007 on October 24, 2016, 07:10:47 PM
Quote from: ISM34 on October 24, 2016, 10:51:32 AMSince I am trying to use the Irvine library functionality, do I need to include this line of code?

include \irvine\irvine32.inc


Do I also need to include this line of code?

includelib \irvine\irvine32.lib

Why do you ask? Why don't you just try and see what happens? Is it laziness, or do you fear that the assembler might bite your hand if you do the wrong thing?

Some links for you:
http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm
http://masm32.com/board/index.php?action=search;advanced;search=
http://www.masmforum.com/board/index.php?action=search;advanced
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: Zen on October 25, 2016, 07:10:08 AM
ISM34,
When you are first starting out with MASM assembly language, you make a lot of errors just because there are a gizzlion little details that you must be aware of, and, you're not, so you typically neglect them. The MASM COMPILER will recognize these errors and generate error messages so that you can write a program that operates correctly. So, it makes sense to start simple, and, read and understand every line of code in your example program. We all made the same errors when we were just starting out, so, we know what you are going through.
The most obvious thing is to find which DLLs contain the routines that you are calling in your program (if you haven't written these routines yourself). So, correcting the error: error A2006: undefined symbol: SetTextColor, is straightforward. You can GOOGLE the Windows function, SetTextColor, and you will find this: SetTextColor function, MSDN (https://msdn.microsoft.com/en-us/library/windows/desktop/dd145093(v=vs.85).aspx). SetTextColor is located in Gdi32.dll, which you have not included at the beginning of your program. So, to solve the error, you can merely add the following lines somewhere in the beginning of your main asm file: 
include \masm32\include\gdi32.inc   
includelib \masm32\lib\gdi32.lib


Note: when listing your include (asm) files and your include library statements at the beginning of your program file, the listing order is important. The reason for this should be obvious,...types and routines must be defined before they can be used or referenced (this is true of most higher level languages too),...the listing of includes should look like the listing in: masm32rt.inc (this is why the masm32rt.inc file was created),...open this file in HUTCH's Quick Editor to see what I mean. So,...the listing of includes at the beginning of your asm project file should be:


include \masm32\include\windows.inc

include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib

include \masm32\include\gdi32.inc   
includelib \masm32\lib\gdi32.lib

include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib



To fix the error: error A2006: undefined symbol: WriteString, you can go either of several ways. WriteString is one of Kip Irvine's routines. It is prototyped in Irvine32.inc, the complete source code is in Irvine32.asm, and, is compiled (presumably) in Irvine32.lib. The simplest way to fix this error is just to copy the original source code for WriteString into your asm project file (from, Examples\Lib32\Irvine32.asm): 

;--------------------------------------------------------
WriteString PROC
;
; Writes a null-terminated string to standard
; output. Input parameter: EDX points to the
; string.
; Last update: 9/7/01
;--------------------------------------------------------
pushad

CheckInit

INVOKE Str_length,edx    ; return length of string in EAX
cld ; must do this before WriteConsole

INVOKE WriteConsole,
    consoleOutHandle,      ; console output handle
    edx, ; points to string
    eax, ; string length
    OFFSET bytesWritten,  ; returns number of bytes written
    0

popad
ret
WriteString ENDP


...However, you will notice, that if you read and understand every line of code, that WriteString calls other unknown routines: CheckInit (a macro defined in Irvine32.asm). Also, WriteString calls: Str_length. WriteConsole, the mystrerious, cld (Clear Direction Flag, actually a processor instruction), and references a number of variables (consoleOutHandle and bytesWritten). Where the heck are these items (in source code or in memory) ???   

From, the Intel Developer's Manual (Volume 2A, Instruction Set Reference, A to M, IA 32 Software Developer's Manual pdf):
QuoteCLD—Clear Direction Flag
Description
Clears the DF flag in the EFLAGS register. When the DF flag is set to 0, string operations increment the index registers
(ESI and/or EDI). Operation is the same in all non-64-bit modes and 64-bit mode.

...So,...it would be MUCH easier, in this case to just include the following lines in your main asm project file:   
include \irvine\irvine32.inc
includelib \irvine\irvine32.lib


...assuming that the path to include files and libraries is correct for the directory structure on your computer. And, this little bit of code will reference the WriteString routine, and reference the other dependencies in the WriteString code listing. So, the MASM COMPILER (ml.exe) should not generate error messages for SetTextColor and WriteString anymore. The irvine32.lib should contain all this code in compiled form, which the MASM COMPILER just loves,...:bgrin:

...So,...what's left ???
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: ISM34 on October 25, 2016, 12:52:01 PM
I appreciate everyone's help. After a lot of research and a lot of trial and error, I was able to build, compile and execute the program. I ran the program and it provided the desired output in the console window. My only question now is that does MASM32 come with a debugger? I would like a debugger to look at register values and memory values. Are there any suggestions on a good debugger program that I can download and run with MASM32?

Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: jj2007 on October 25, 2016, 08:42:07 PM
OllyDbg: http://masm32.com/board/index.php?topic=4044.msg42592#msg42592

There is also the option to use a debug macro included in the MasmBasic library (http://masm32.com/board/index.php?topic=94.0):

include \masm32\MasmBasic\MasmBasic.inc            ; ## little demo using Kip Irvine's library with Masm32 ###
include \masm32\MasmBasic\IrvineMb\Irvine32Mb.inc  ; needed to build Irvine's (many but not all) 32-bit examples
.data
somevar        dd 123                        ; hit F6 to build this example
somestring     db "MasmBasic rocks", 0
someQword      dq 123456781234567890
someOword      dq 1111111122222222h, 3333333344444444h
ThisIsIrvine   db "Just to confirm that this code is really using the Irvine library", 0
  Init
  mov edx, offset ThisIsIrvine
  call WriteString
  call Crlf
  or eax, -1          ; set sign flag
  stc                 ; set carry flag
  mov eax, 11111111     ; in \Masm32\qeditor.exe, use "Project/Console build all", then "Project/Run Program"
  mov ebx, 22222222     ; in \Masm32\RichMasm\RichMasm.exe, just hit F6 (detects console mode automatically)
  mov ecx, 33333333h    ; load ecx and edx with hex values
  mov edx, 44444444h    ; see below, displayed as x:ecx, x:edx
  movups xmm0, qword ptr someQword      ; you can display qwords
  movups xmm1, oword ptr someOword
  mov esi, offset somestring      ; see $esi below
  fldpi            ; load 3.14159 into the FPU
  deb 4, "This is the output of the deb macro:", eax, ebx, x:ecx, x:edx, $esi, xmm0, x:xmm1, ST(0), $esi, flags      ; deb (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1019) can display regs, variables, strings, flags, constants
  Inkey CrLf$, "bye"
  Exit
end start


Output:
Just to confirm that this code is really using the Irvine library
This is the output of the deb macro:
eax             11111111
ebx             22222222
x:ecx           33333333
x:edx           44444444
$esi            MasmBasic rocks
xmm0            123456781234567890
x:xmm1          33333333 44444444 11111111 22222222
ST(0)           3.141592653589793238
$esi            MasmBasic rocks
flags:          CzSo


I attach the Irvine-specific stuff; extract to \Masm32\MasmBasic\IrvineMB
Title: Re: Irvine library SmallWin.inc error MASM Visual Studio 2015
Post by: BugCatcher on October 26, 2016, 01:16:52 AM
Get the Win32 help file and start reading. I could not program with out it. My editor is RADasm version 2.2.2.0 . It has a simple debugger that comes in handy. For low level debugging I use Windbg or Olly. Study the examples in the masm sdk and learn how to copy and paste!