Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!


TUCoPS :: PC Hacks :: asmprog.txt

Introduction to Assembly Programming




.-= {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-}=-.
                  Introduction to Assembly Programming by Moe1
.-= {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-} {-=+=-}=-.

This will cover how to write your first program in assembly using DEBUG.COM as
shipped with Windows 9x and MS-DOS...

C:\party2k>debug
- a100

0C1B:0100 jmp 125
(Jumps to direction 125H)

0C1B:0102 [Enter]

- e 102  'Happy Birthday FK!!!' 0d 0a '$'
  [ In function 09 of Int 21, as with most functions of int 21, the string is
    terminated with a "$" character. - Ed]

- a125

0C1B:0125 MOV DX,0102
(Copies string to DX register) [Actually the Segment:Offset address of where
in memory the string is stored to DX:DS. Remember each register has a high
and low order byte? - Ed]

0C1B:0128 MOV CX,000F
(Amount of times the string will be displayed)

0C1B:012B MOV AH,09
(Copies 09 value to AH register) [09 is the function for MS-DOS to call - Ed]

0C1B:012D INT 21
(Displays string) [int 21h is the MS-DOS function call interrupt - Ed]

0C1B:012F DEC CX
(Reduces in 1 CX)

0C1B:0130 JCXZ 0134
(If CX is equal to 0 jumps to 0134)

0C1B:0132 JMP 012D
(Jumps to direction 012D)

0C1B:0134 INT 20
(Ends the program)

0C74:0136 [ENTER]

(Now we start compiling our lil codey, awww how kewt;)
- h 0136 0100

- n fkrulez.com

- rcx
CX 0000
: 0036

- w
Writing 00036 bytes

- q
c:\party2k>fkrulez

Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!
Happy Birthday FK!!!

So now as another practical example, let's look at how we would hide a program
from Windoze using masm32. To do this we simply pass the program's process ID
to the RegisterService() function thus registering the program as a service,
which wont show up in the windows task list.

.data               ; first we define in our data section

    szKernel32      db   "Kernel32.dll",0
    szRSP           db   "RegisterServiceProcess",0

.code               ; now we start the code
start:

    push   offset szKernel32
    call   GetModuleHandle       ; get Kernel32.dll handle
    push   offset szRSP
    push   eax
    call   GetProcAddress        ; get function address
    mov    ebx, eax              ; save our pointer into ebx

    call   GetCurrentProcessId   ; get current process id

    push   1                     ; 1 = Register Service, 0 = Unregister Serv.
    push   eax                   ; process id
    call   ebx                   ; call RegisterServiceProcess

end start

We could do this in any language which we can access the Win32 API from
really, I just used assembly as an example because it's what we're playing
with here. :)

[ Some more additions from Wyzewun: And there you have it. If you're
  interested in getting involved with Assembly Programming, look around at the
  stuff available in the programming tutorials section of Packetstorm Security
  and particularly the tutorial available there made by the University of
  Guadalajara (don't ask me where that is) which is quite detailed. As you get
  better you will find other resources for ASM coding all over the place, so
  look around and you shouldn't have much trouble finding what you want. :)

  PacketStorm also has some great resources for other programming languages
  like C/C++, Pascal, JavaScript, Perl, Python - you name it. :) Mm, no TCL/TK
  yet, but I s'pose you can pick that up at other places.

  Also, try and see if you can get hold of the SAMS MS-DOS Bible - it's what
  I learnt what I know about assembly from and it's a great reference for
  DOS/Windoze ASM. Mmm, I'm still using the Second Edition (Covers MS-DOS 3.3)
  but I'm sure there are newer versions lying around. Well, I hope. Otherwise
  it won't be much use, now will it? :) ]


TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2014 AOH