News:

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

Main Menu

Introduction into MASM Q's

Started by c0mical, August 18, 2012, 09:52:54 PM

Previous topic - Next topic

c0mical

Hey whats going MASM32?

kk, lets jump into it:

1. I'm new to MASM so I was hoping to find some decent MASM papers/books. Ive had some problems with this because I'm wanting to find something that goes into deep explanation ASM writing. Format, Data structures, yada yada yada. I read over Iczelions papers (assuming you're familiar with his work(s)) and I wasn't really liking it, primarily because I was wanting a better understanding of control statements. I was wanting to learn how to write loops, if else statements, goto, etc using genuine ASM instructions using instructions like JMP. Although I hadnt read too far into his papers, I wasnt really finding much of that and it was disappointing. Can anyone point me in the right direction? I searched online and found a good paper awhile back, but I can't seem to find it anymore. Or, if theres a good thread on this forum I can read over I'd appreciate that too.

Good books, papers, personal advice, etc would be greatly appreciated.

2. I'm running a 64bit OS and it's virtually impossible to find papers regarding 64bit MASM (omit the manuals). I was wondering, the MASM32 assembler, if I write 32bit MASM on a 64bit OS, is that going to cause any actual problems? I'd assume it would. I've also heard 64bit ASM is different than 32bit ASM (omit things you could naturally assume like QWORD / DWORD) because register usage is different, am I correct? && If so, why is that?

I really appreciate all replies in advance. It's a little unsettling looking over forums, papers, etc because it's almost like there's no beginner ASM programmers like myself. There seems to be a giant skill gap.

hutch--

Hi,

32 bit code runs fine on Win7 64 bit, 64 bit code is harder to write and not that well supported yet. Printed books are generally old crap and badly written, the best is online and the manufacturers manuals.

It depends a bit on your background, if you have written C or similar compiler languages where direct addressing is normal, then you have the basic concepts of assembler, if you have only written OOP languages or soft languages like the old VB, the shift is a lot harder.

c0mical

Hutch, could you recommend any online papers then regarding MASM32? Ideally, I'd like to not read the 1000++ page manual.

&&

I code in C, so the concept of direct addressing isn't going to be a problem whatsoever.

jj2007

There are some essential links in my Tips, Tricks & Traps. Study in particular \masm32\help\opcodes.chm
To understand what your code is doing, either use Olly, or the deb macro.

Gunther

Quote from: c0mical on August 19, 2012, 01:14:18 AM
Hutch, could you recommend any online papers then regarding MASM32? Ideally, I'd like to not read the 1000++ page manual.

That's your point of view. But for a deep understanding, the manuals by Intel, AMD and Agner Fog are essential. There's no other way.

Gunther
You have to know the facts before you can distort them.

c0mical

Quote from: jj2007 on August 19, 2012, 02:50:40 AM
There are some essential links in my Tips, Tricks & Traps. Study in particular \masm32\help\opcodes.chm
To understand what your code is doing, either use Olly, or the deb macro.

Alright, I'll be sure to check those out then. I appreciate it.

Quote from: Gunther on August 19, 2012, 06:11:07 AM
That's your point of view. But for a deep understanding, the manuals by Intel, AMD and Agner Fog are essential. There's no other way.

Gunther

Well, that's unfortunate. But, if that's the only way to truly get a good understanding for it then I guess that's what I'll have to do. I appreciate the input as well.

jj2007

Quote from: c0mical on August 18, 2012, 09:52:54 PMI was wanting to learn how to write loops, if else statements, goto, etc using genuine ASM instructions

The MASM Programmer's Guide is very important, see the link in this post.

\masm32\help has lots of stuff inter alia on usage of macros like print "hello world", 13, 10
Search \masm32\examples\*.asm for these four strings:
Switch
.elseif
.While
.Repeat

c0mical

Quote from: jj2007 on August 19, 2012, 07:33:11 AM

\masm32\help has lots of stuff inter alia on usage of macros like print "hello world", 13, 10
Search \masm32\examples\*.asm for these four strings:
Switch
.elseif
.While
.Repeat

That's HLA, correct? I was hoping to stray away from that.

dedndave

welcome to the forum   :t

not HLA
"print" is a masm32 macro
which - i figure, as long as i know how the macro works, it's ok to use it
so - you can look in \masm32\macros\macros.asm to find the macro definition
it calls a masm32 lib function - so look in the appropriate file of masm32\m32lib to see how that works
that way, you don't miss learning how things work
and - macros do save you a lot of typing

typically, i use print when i am trying to learn other things
i want to see how some other function works - i use print to show results
and - when debugging, it makes things easy, too

jj2007

The debate whether one should use print "hello world" or "real" assembler is old and ideological. It is good to know what print does, but it's also good to be productive - ask somebody to produce the output of the snippet below in "real" assembler ;)

And you can use both versions, macros and "real" asm, in parallel.

include \masm32\MasmBasic\MasmBasic.inc   ; download
  Init      ; library initialisation
  fld1      ; push 1 on FPU
  fldpi      ; push 3.14159 on FPU
  push eax   ; create a slot with
  push eax   ; 8 bytes on the stack
  fst REAL8 PTR [esp]   ; transfer current FPU value (PI) to stack, as real
  movlps xmm0, [esp]   ; transfer PI to xmm0
  fld st         ; create a copy for display as ST(0) below
  mov word ptr [esp], 10000   ; move a word-sized integer into the stack
  fimul word ptr [esp]   ; multiply current ST with 10000
  fistp QWORD PTR [esp]   ; transfer current FPU value (PI*1000) to stack, as integer
  movlps xmm1, [esp]   ; transfer PI*10000 to xmm1
  mov ecx, 1111
  imul eax, ecx, 5
  deb 1, "On entry:", eax, ecx, edx, esi, edi, ebx, ST(0), ST(1), f:xmm0, xmm1, xmm2
  Exit
end start

On entry (comments added by hand):
eax             5555   ; result of imul
ecx             1111   ; set above
edx             -5   ; some value assigned by the OS
esi             0   ; Init sets
edi             0   ; esi, edi, ebx
ebx             0   ; to zero
ST(0)           3.14159265358979324   ; result of fldpi
ST(1)           1.00000000000000000   ; result of fld1
f:xmm0          3.141592653589793   ; xmm0 as float
xmm1            31416   ; result fimul
xmm2            1339184   ; some value assigned by the OS

Gunther

Good example and good explanation, Jochen.  :t

Gunther
You have to know the facts before you can distort them.