I was just wondering if anyone knows of any MASM tutorials that teach pure assembly? I don't want any of this .IF and .WHILE stuff, I want a tutorial that uses just assembly. I've tried looking around, and searching the forums, but everything I have come across seem to be what I am NOT looking for. Thanks for any help.
"I don't want any of this .IF and .WHILE stuff, I want a tutorial that uses just assembly. "
Me too... :lol
The Opcodes Help file that comes with MASM32 gives a good explanation of individual instructions,
with the flags that are affected and hints for the use of the instruction.
The ASM Intro Help file gives low level descriptions/examples of basic loop design.
Assembling short test pieces of code with NOPs before and after then either disassembling them
or running them through a debbuger such as ollydbg will show how conditional code and loops are done.
For example .if .endif and the disassembled version.
.code
start:
nop
nop
.if eax > 3
mov ecx, edx
.endif
nop
nop
invoke ExitProcess, NULL
end start
code.
start:
nop
nop
cmp eax,3
jbe @F
mov ecx,edx
@@:
nop
nop
push 0
call ExitProcess
end start
For code using .repeat .until
nop
nop
mov eax, 63
.repeat
dec eax
.until eax == 0
nop
nop
becomes
nop
nop
mov eax, 3Fh
@@:
dec eax
or eax, eax
jnz @B
nop
nop
or using fixed labels instead of relative ones
nop
nop
mov eax, 3Fh
back:
dec eax
or eax, eax
jnz back
nop
nop
Eklipz,
many people make the assumption that they should start at the lowest level of assembler programming but it has a very poor track record in terms of success rate. Pure memonic coding is an advanced area and few starting off can code this type of application because of its complexity. Below is a very simple example of pure mnemonic coding in assembler but its hardly beginners material because it manually codes the stack frame, manually loads structures and does all of its API calls with push/call syntax.
There is good sense in starting with some of the higher level constructs as they get you a working program a lot faster and a lot more reliably and this is the difference between succeeding and failing while learning assembler. Once you understand how it works, you can start to try out lower level bits where it matters, a traditional dispatch table instead of an .IF block and later you can try out things like a jump table where it can be used. Assembler programming can do all of this stuff well but you have to be able to get it to work first or you will get nowhere in a hurry.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
comment * -------------------------------------------------------------
This example is written in pure Intel mnemonics to demonstrate that
Pelle's Macro Assembler can build code at the lowest level possible
----------------------------------------------------------------- *
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include poasm1k.inc ; local includes for this file
.code
szClassName db "POASM 1k", 0
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
push ebp ; set up a stack frame
mov ebp, esp
sub esp, 96 ; create stack space for locals
xor edi, edi
mov esi, 400000h ; use constant for the hInstance
mov ebx, OFFSET szClassName
push IDC_ARROW
push edi
call LoadCursor
; -----------------------------------
; manually coded WNDCLASSEX structure
; -----------------------------------
mov DWORD PTR [ebp-96], 48
mov DWORD PTR [ebp-92], CS_VREDRAW or CS_HREDRAW
mov DWORD PTR [ebp-88], OFFSET MyWndProc
mov DWORD PTR [ebp-84], edi
mov DWORD PTR [ebp-80], edi
mov DWORD PTR [ebp-76], esi
mov DWORD PTR [ebp-72], edi
mov DWORD PTR [ebp-68], eax
mov DWORD PTR [ebp-64], COLOR_BTNFACE+1
mov DWORD PTR [ebp-60], edi
mov DWORD PTR [ebp-56], ebx
mov DWORD PTR [ebp-52], edi
lea eax, [ebp-96]
push eax
call RegisterClassEx ; register the window class
mov ecx, CW_USEDEFAULT
push edi
push esi
push edi
push edi
push edi
push ecx
push edi
push ecx
push WS_OVERLAPPEDWINDOW
push ebx
push ebx
push edi
call CreateWindowEx ; create the main window
push SW_SHOWNORMAL
push eax
call ShowWindow ; display it
lea ebx, [ebp-48] ; load stack space for the
; MSG structure in EBX
StartLoop:
push ebx
call DispatchMessage
push edi
push edi
push edi
push ebx
call GetMessage ; process messages until
; GetMessage returns zero
test al, al
jnz StartLoop
leave ; exit the stack frame
retn ; make a NEAR return
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
MyWndProc:
push ebp ; set up a stack frame
mov ebp, esp
cmp DWORD PTR [ebp+12], WM_DESTROY
jne @F
push NULL
call PostQuitMessage
@@:
push DWORD PTR [ebp+20]
push DWORD PTR [ebp+16]
push DWORD PTR [ebp+12]
push DWORD PTR [ebp+8]
call DefWindowProc
leave ; exit the stack frame
ret 16 ; balance stack on exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
This lowest level example make the use of high level syntax very pertinent.
I think this way of coding should be used only when it comes to code loops where speed is important.
Readability is not a minor quality.
You can search this database for skeleton, that should prove an interesting beginning for you.
Also, if you can find any books on Assembly Language, most of them start off with the basic stuff.
Windows Programming can be very complex, just to get the window up on the screen...watch out! Start with a few dos interrupt calls, or something very small.
If you find any books on DEBUG.EXE , that might help you also!
You can run debug.exe by creating DOS window, and typing debug.
later,
jeff cummings
:P
buy a used copy of peter nortons assembly language for the 8088. The original, and still the best. I use it just as much as Petzolds Windows book.
alan
i think Redscull meant Norton Guides (198x-199x an oldy ones but still useful) - great thing. but you shouldn't forget that any algorithm is firstly written on a paper in pseudo language and only after is written in appropriate assembly opcodes.
If you can find it, Michael Abrash's Zen of Assembly is a fun read. It was later incorporated into his rather large Black Book of Computer Graphics Programming, which is the version I have. It's old school, but interesting reading and his writing style is relaxed. It's also got a discussion of the original Quake's source code (included on the CD), which is fun because hardware 3D accelerators weren't readily available back then so everything was done in software.
As one who started with coding entire applications in low-level assembly because that was the only option way back when, I really appreciate the simplified high level constructs and macro functions MASM offers. Such shortcuts are useful in roughly 98% of an application's code, and they generate the same instructions you'd type in yourself if you were doing it manually. Thus you can spend more time debugging your code than you do typing it in, and as previously noted, there is less chance of error because the automatically generated instructions are always the same and don't suffer from typos and potentially bad local jump/stack variable references.
Hi to all: My English is poor. But I try.
Mr. Eklipz:
Search button google: "td_win32asm_all.rar"
I saw like 50 examples of assembler. It is very impressive.
These examples are in pure assembler.(WIN32)
First you must read the file 000???.asm.
Thanks for your patience.
Bye ('_').
IAO has pointed at great tutorials by Test Department (aka TD) i also recommend them to everybody. they are really good.
asmfan,
Peter Norton started a company with Socha that eventually became Symantec. I forget Socha's first name but I know that they had a falling out over a program called SideKick.
EDIT: I think it was James.
Paul
"John" Socha
Thank you, it has been years, senile decay.
"td_win32asm_all.rar" does not seem to work.
Paul
Paul,
what the symptomes?
i know the link to their site(TD) is broken and i dont know new one...
asmfan,
I patched it into Google and searched. It returns one result, http://win32asm.pl/wyswietl.php?co=teksty&warunek=wszystkie, which is a link that does not work. It looks like it is trying to run a perl script but I am unsure.
Paul
I have the test department stuff in one of my archives. I remember grabbing it when we were warned that the plug was going to be pulled but I thought it would be easier to just grab the archive again instead of searching through a dozen CDs.
Oh well, now where are those CDs ...
Paul
Hopefully these are what you are looking for:
https://masmforum.com/download/td_win32asm_all.zip
Alphred
EDIT:
There is a New reviewed & updated version, provided by 'elC' here:
https://masmforum.com/download/td_win32asm_all_reviewed_by_elC.zip
Alphred,
They certainly are and a great big thank you to you! I never even thought to look there! ::)
Paul
Paul, it seems we dont know the good things we have in our hands:)
Igor,
You are SO right and Hutch and Ghirai have worked very hard to make it so.
Paul