The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Eklipz on March 29, 2006, 12:31:53 AM

Title: MASM Tutorial for Pure assembly?
Post by: Eklipz on March 29, 2006, 12:31:53 AM
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.
Title: Re: MASM Tutorial for Pure assembly?
Post by: lingo on March 29, 2006, 12:48:30 AM
"I don't want any of this .IF and .WHILE stuff, I want a tutorial that uses just assembly. "

Me too... :lol
Title: Re: MASM Tutorial for Pure assembly?
Post by: dsouza123 on March 29, 2006, 01:14:31 AM
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
Title: Re: MASM Tutorial for Pure assembly?
Post by: dsouza123 on March 29, 2006, 01:39:58 AM
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

Title: Re: MASM Tutorial for Pure assembly?
Post by: hutch-- on March 29, 2006, 01:43:08 AM
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
Title: Re: MASM Tutorial for Pure assembly?
Post by: jdoe on March 29, 2006, 02:23:52 AM
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.
Title: Re: MASM Tutorial for Pure assembly?
Post by: OceanJeff32 on March 29, 2006, 05:56:31 AM
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
Title: Re: MASM Tutorial for Pure assembly?
Post by: redskull on March 30, 2006, 02:56:39 AM
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
Title: Re: MASM Tutorial for Pure assembly?
Post by: asmfan on March 30, 2006, 09:21:36 AM
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.
Title: Re: MASM Tutorial for Pure assembly?
Post by: Wistrik on March 30, 2006, 07:28:46 PM
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.
Title: Re: MASM Tutorial for Pure assembly?
Post by: IAO on March 31, 2006, 01:28:29 PM
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 ('_').
Title: Re: MASM Tutorial for Pure assembly?
Post by: asmfan on March 31, 2006, 03:50:41 PM
IAO has pointed at great tutorials by Test Department (aka TD) i also recommend them to everybody. they are really good.
Title: Re: MASM Tutorial for Pure assembly?
Post by: PBrennick on April 02, 2006, 06:32:59 PM
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
Title: Re: MASM Tutorial for Pure assembly?
Post by: Shantanu Gadgil on April 02, 2006, 06:59:45 PM
"John" Socha
Title: Re: MASM Tutorial for Pure assembly?
Post by: PBrennick on April 02, 2006, 07:08:06 PM
Thank you, it has been years, senile decay.

"td_win32asm_all.rar" does not seem to work.

Paul
Title: Re: MASM Tutorial for Pure assembly?
Post by: asmfan on April 02, 2006, 07:20:23 PM
Paul,
what the symptomes?
i know the link to their site(TD) is broken and i dont know new one...
Title: Re: MASM Tutorial for Pure assembly?
Post by: PBrennick on April 02, 2006, 07:26:37 PM
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
Title: Re: MASM Tutorial for Pure assembly?
Post by: PBrennick on April 02, 2006, 07:29:28 PM
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
Title: Re: MASM Tutorial for Pure assembly?
Post by: alphred72 on April 02, 2006, 08:07:09 PM
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

Title: Re: MASM Tutorial for Pure assembly?
Post by: PBrennick on April 02, 2006, 08:34:15 PM
Alphred,
They certainly are and a great big thank you to you!  I never even thought to look there! ::)

Paul
Title: Re: MASM Tutorial for Pure assembly?
Post by: asmfan on April 02, 2006, 08:53:28 PM
Paul, it seems we dont know the good things we have in our hands:)
Title: Re: MASM Tutorial for Pure assembly?
Post by: PBrennick on April 02, 2006, 10:05:28 PM
Igor,
You are SO right and Hutch and Ghirai have worked very hard to make it so.

Paul