If you know how to use Visual Studio and Irvine's resources for masm, help me!

Started by RedSkeleton007, February 03, 2016, 06:55:53 PM

Previous topic - Next topic

RedSkeleton007

I've been trying to learn x86 assembly, but instead of learning to program, I've been struggling with INCLUDE libraries, and problems with MASM32 Editor and Visual Studio 2013 compilers fighting each other. I can't even get a simple DumpRegs directive to work for s*** sake:

; Program template

.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
;INCLUDE C:\Irvine\Irvine32.inc
INCLUDE Irvine32.inc

.data
; declare variables here
.code
main proc
; write your code here
     mov eax,5
add eax,6
     call DumpRegs

invoke ExitProcess,0
main endp
end main

The errors in Visual Studio:
1>c:\Irvine\SmallWin.inc(11): error A2071: initializer magnitude too large for specified size

1>c:\Irvine\SmallWin.inc(11): warning A4011: multiple .MODEL directives found : .MODEL ignored

1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\masm.targets(50,5): error MSB3721: The command "ml.exe /c /nologo /EP /Sa /Sg /WX /Zi /Fo"Debug\SamZone.obj" /Fl"Project.lst" /I "c:\Irvine" /W3 /errorReport:prompt  /Ta..\ch03\SamZone.asm" exited with code 1.

I don't know what to do. But I do know that I can never truly learn and blossom with masm knowledge until this is resolved. I've already wasted nearly two weeks on this issue, unable to test (and, consequently, unable to learn) basic masm syntax.

jj2007

You are experiencing exactly what I experience every time I touch C++ - a complete mess. The fault is not with Masm, it's not your fault either, no, the culprits are Visual Crap and, to a lesser extent, Kip Irvine who cooks his own soup for his teaching.

My advice: Drop VS and the Irvine lib. Instead, use qEditor's Console build all menu and start with hello world proggies:

include \masm32\include\masm32rt.inc

.data
MyArray dd 25, 18, 23, 17, 9, 2, 6
HelloW$ db "Hello World", 0

.code
start:
  xor ebx, ebx ; set two non-volatile
  xor esi, esi ; registers to zero
  .Repeat
add esi, MyArray[4*ebx]
inc ebx
  .Until ebx>=lengthof MyArray
  MsgBox 0, cat$(str$(esi), " is the sum"), offset HelloW$, MB_OK
  exit

end start


Let me know if it works. If you want to see what the CPU does in this proggie, download Olly and extract it to \Masm32\OllyDbg\ollydbg.exe, then open your helloworld.exe and start hitting F8. Much better than dumpreg.

RedSkeleton007

Quote from: jj2007 on February 03, 2016, 07:32:00 PM
My advice: Drop VS and the Irvine lib. Instead, use qEditor's Console build all menu and start with hello world proggies:
Ugh... what a waste of money. To make matters worse, I just scratched off the pearson highered code and activated it too, so Irvine's text book resale value is already lower :(
But I suppose I will have to just cut my losses and try QEditor's Console. It's also called MASM32 Editor, right?

However, there's one more problem. Every time I try to open a .asm file, Visual Studio automatically opens, and displays a text file copy of that same .asm file. I already asked this in my other thread, but didn't get an answer that was straight enough for my taste, so let me ask that same question again:

How do I get Visual Studio to shut up (and mind it's own C++ purpose business), and get the .asm file to compile where it needs to?

jj2007

- open \Masm32\qeditor.exe
- copy the code I posted above, and paste it
- save the file as \Masm32\MyTest.asm (you need to specify the .asm extension)
- click menu Project/Console Build All
- check the output window for errors
- click menu Project/Run program

If that works, right-click in Explorer on MyTest.asm, then Open With, predefined program, pick qEditor. That should block Visual Crap from interfering with your asm dreams 8)


Fred Harris

I've been learning with just Hutch's masm32 download.  Everything works wonderfully RedSkeleton.  Its a really impressive piece of work.  All the demos in the tutorials work.  Just open them in QEditor and compile and link.

When I started out a couple months ago the first thing I struggled with was what you seem to be doing, i.e., figuring out how to print stuff.  You know, anything.  Hello, World, whatever.  I've found I can use about a half a dozen ways to do it.  Also.  I compile from the command line a lot too.  I do that with Visual Studio too in C++.  I hate just about all Microsoft's Visual programming junk.  Anyway, here is one of my early endeavors to show how to print stuff...


; C:\Code\MASM\Projects\Demo3>ml /c /coff /Cp Test3.asm
; C:\Code\MASM\Projects\Demo3>link /SUBSYSTEM:CONSOLE Test3.obj
include \masm32\include\masm32rt.inc
IncrOne proto iNum:DWORD

.data?
dwNumber dd ?
pNumber  dd ?

.code
start:
  mov dwNumber, 5
  printf("dwNumber        = %u\n",dwNumber)
  printf("ADDR   dwNumber = %u\n",ADDR dwNumber);
  printf("OFFSET dwNumber = %u\n",OFFSET dwNumber);
  lea eax, OFFSET dwNumber
  printf("eax             = %d\n",eax);
  lea eax, OFFSET dwNumber
  mov pNumber, eax
  printf("pNumber         = %u\n",pNumber);
  lea eax, OFFSET dwNumber
  mov pNumber, eax
  push pNumber
  call IncrOne
  printf("eax           = %d\n",eax);
  invoke crt_getchar
  exit

  IncrOne proc pNum:DWORD
    LOCAL dwNum:DWORD
   
    printf("\nEntering IncrOne()\n")
    printf("  pNum          = %u\n",pNum)
    mov eax, pNum
    mov eax, [eax]
    printf("  eax           = %u\n",eax)
    printf("Leaving IncrOne()\n\n");
    mov eax, pNum
    mov eax, [eax]
    add eax, 1
    ret
  IncrOne endp
end start


dwNumber        = 5
ADDR   dwNumber = 4206832
OFFSET dwNumber = 4206832
eax             = 4206832
pNumber         = 4206832

Entering IncrOne()
  pNum          = 4206832
  eax           = 5
Leaving IncrOne()

eax           = 6


You can see my assembler and link command lines at top.  It ought to compile perfect in Hutch's QEditor too.  If you do use the command line syntax just execute a PATH command filling in the path to masm32/bin on your box.

To be truthful, I don't know how anyone could produce a better include file set than what's found here.

dedndave

i think Kip gives you a lot of help on his site, if you find and read the right pages   :P

http://www.kipirvine.com/asm/

RedSkeleton007

Quote from: jj2007 on February 03, 2016, 08:18:22 PM
If that works, right-click in Explorer on MyTest.asm, then Open With, predefined program, pick qEditor. That should block Visual Crap from interfering with your asm dreams 8)
Thanks so much :biggrin: I'm excited to finally get started.

RedSkeleton007

Quote from: jj2007 on February 03, 2016, 07:32:00 PM
If you want to see what the CPU does in this proggie, download Olly and extract it to \Masm32\OllyDbg\ollydbg.exe, then open your helloworld.exe and start hitting F8. Much better than dumpreg.
I did that and I'm hitting F8, but nothing seems to be happening. Where do I need to look to view what's in the registers and flags?

TouEnMasm

********** Where do I need to look to view what's in the registers and flags? *********

You need to debug your prog in source mode.
Add /Zi /Zd options to the compiler (ml or jwasm).
Add /DEBUG /DEBUGTYPE:CV to the linker      (Verify the syntax)
Then follow your prog,line by line in a debugger,you will see the values of the register and the compiled code.

If you prefer Visual Studio to do that:
http://masm32.com/board/index.php?topic=4489.msg47997#msg47997
Fa is a musical note to play with CL

TouEnMasm

Fa is a musical note to play with CL

jj2007

Quote from: RedSkeleton007 on February 04, 2016, 05:20:26 PMI'm hitting F8, but nothing seems to be happening. Where do I need to look to view what's in the registers and flags?

Extract the attachment as \Masm32\makeit.bat, then use the Project/Makeit.bat command. Olly must sit in \Masm32\OllyDbg\ollydbg.exe, of course.

RedSkeleton007

Quote from: jj2007 on February 05, 2016, 04:19:35 AM
Extract the attachment as \Masm32\makeit.bat, then use the Project/Makeit.bat command. Olly must sit in \Masm32\OllyDbg\ollydbg.exe, of course.
Still nothing happens. Am I not supposed to build and run my program first? And if I do get it to work, where are the registers and flags going to be displayed?

dedndave

dowload OllyDbg - as i recall, installation is merely a matter of creating a folder and placing the program in it

you want to make Olly the "default just-in-time" handler
if you open Olly, there is an Options menu
under Debugging, Just-in-time - Set OllyDbg button
it takes care of it for you, and saves previous settings if you want to reverse it

now, any program that generates an exception will cause Olly to pop up
we generally insert
    int     3
into the code where we want execution to generate an exception

Olly has a few different panes
one has your code
one has data
one has registers and stack trace

Olly keys...

Program reset             Ctrl + F2
Close program             Alt + F2
Open EXE file             F3
Bring Olly to top         Alt + F5
Step into                 F7
Animate into              Ctrl + F7
Step over                 F8
Animate over              Ctrl + F8
Run program               F9
Execute till return       Ctrl + F9
Execute till user code    Alt + F9
Run trace into            Ctrl + F11
Stop execution            F12
Run trace over            Ctrl + F12
Stop anim. or tracing     Esc


my understanding is that Visual Studio has a debugger (never used it - lol)
i think it's WinDbg or something similar
maybe someone else can fill you in about how to use that one

jj2007

Quote from: RedSkeleton007 on February 05, 2016, 05:24:36 AM
Quote from: jj2007 on February 05, 2016, 04:19:35 AM
Extract the attachment as \Masm32\makeit.bat, then use the Project/Makeit.bat command. Olly must sit in \Masm32\OllyDbg\ollydbg.exe, of course.
Still nothing happens. Am I not supposed to build and run my program first? And if I do get it to work, where are the registers and flags going to be displayed?

Build & run is done by the makeit.bat attached above. Open it in Notepad to see the details.

Quote from: jj2007 on February 03, 2016, 07:32:00 PMIf you want to see what the CPU does in this proggie, download Olly and extract it to \Masm32\OllyDbg\ollydbg.exe

See Dave's post for details. As a beginner, you really need only the F8 key.