[Guide] ASM 101 - Introduction to the Assembly language

01/29/2014 12:49 KraHen#1
Hello, fellow epvpers.

In the last few weeks/months I have seen a steep rise on people who wanted to give reverse engineering a try, so I figured I help a few people with a basic introduction to the assembly language.

IMPROTANT! This is NOT a reverse engineering tutorial!!! These will be just a few assembly tutorials, then at the end I might show you some basic things you can do with OllyDBG. This series is intended to help you understand that nightmare of code which appears in Olly, then you apply this to Conquer Online

Update : (Thanks to a friend of mine :D)Do you need an editor to work in 8086 assembly and don`t like Notepad or Notepad++? Use Sublime_text. You will need [Only registered and activated users can see links. Click Here To Register...] to make it work.

If you find any errors, and I`m sure you will, probably multiple times, please PM me or post it here and I`ll fix it. Thanks you in advance. :)

This thread will be updated with more tutorials, of course.

So yeah, let`s get started!

Lesson 0 - Compiling your first 8086 assembly program and set up the dev enviroment


Lesson 1 - Basic arithmetic operations


Lesson 2 - Advanced arithmetic operations. Signed representations.


Lesson 3 - Loops, logical satements


Lesson 4 (really short one) - using arrays


Lesson 5 - some interrupts - print "Hello World"

01/29/2014 14:05 Y u k i#2
My brains :S This is worse than lisp.
01/29/2014 14:14 KraHen#3
Try Haskell.
01/29/2014 14:51 Lateralus#4
(((((Not even close to being worse than lisp.)))))()()()()

Not a bad tutorial. I certainly wouldn't start off learning x86 as an introduction to assembly though. I'd start off with a RISC architecture first for learning general assembly concepts (which is why they usually teach MIPS in school), then go to x86.
01/29/2014 19:18 KraHen#5
@Lateralus : Yeah, it would be a viable choice, but I`m not really familiar with either of them, and 8086 seems closer to 32-bit assembly as well. Also thank you. :)

Added lesson 2!
01/29/2014 22:55 Spirited#6
If I could recommend something, you can make and run assembly programs for windows using MASM and Textpad 7. I'll post a program that uses it, if I remember to get it off my college network drive tomorrow.
01/29/2014 22:57 KraHen#7
This code won`t run with a MASM compiler, nor will it run with a 8086 emulator. If someone wants to convert it to MASM though, it won`t be hard at all. :)
01/29/2014 22:58 Spirited#8
Quote:
Originally Posted by KraHen View Post
This code won`t run with a MASM compiler, nor will it run with a 8086 emulator. If someone wants to convert it to MASM though, it won`t be hard at all. :)
Right, which is why I was offering to post a program for it. Should I not then? I don't want to ruin your little tutorial. :p
01/29/2014 23:23 KraHen#9
Quote:
Originally Posted by Spirited Fang View Post
Right, which is why I was offering to post a program for it. Should I not then? I don't want to ruin your little tutorial. :p
You absolutely should, and welcome to do so. :)

Also added lesson 3 in the meantime!
01/30/2014 00:20 Spirited#10
Awesome! I'll do that tomorrow at the lab.
Btw, the lessons are looking really nice. Good job. Nothing I'll post will be at the level you're making lessons for, but hopefully it'll help for anyone interested in seeing it for Windows using MASM. :p
01/30/2014 14:08 KraHen#11
I`m eager to see it as well. :)

In the meantime, added a few more guides!
01/31/2014 17:10 OverKill.#12
keep it up, nice tutorials buddy
01/31/2014 17:37 Spirited#13
Alright. Sorry, I forgot yesterday. Here's the make file for my little program:
Code:
# Declare & Initialize Constants:
EXECUTABLE = Lab1.exe		# The executable file.
ASSEMBLY = Lab1.asm		# The assembly file.
LINKER_INPUT = Lab1.ilk		# The linker input file.
PROJ_DEBUG = Lab1.pdb		# The project debugger file.
OBJECT_FILE = Lab1.obj		# The object file for assembly.
LIST_FILE = Lab1.lst		# The list file.


ALL: $(EXECUTABLE)


CLEAN:
	-@erase $(EXECUTABLE)
	-@erase $(LINKER_INPUT)
	-@erase $(PROJ_DEBUG)
	-@erase $(OBJECT_FILE)
	-@erase $(LIST_FILE)

	
$(ASSEMBLY):


$(OBJECT_FILE): $(ASSEMBLY)
	ml /c /coff /Zi $(ASSEMBLY)

		
# If the object file, executable, kernel, or io object has changed, 
# remake the executable file:
$(EXECUTABLE): $(OBJECT_FILE) 
	link /debug /subsystem:console /out:$(EXECUTABLE) \
		/entry:start $(OBJECT_FILE) KERNEL32.LIB IO.OBJ
And here's the assembly file:
Code:
.386

; The memory model:
.MODEL FLAT

; We don't know where this prototype is, but it's in the address space
; (NEAR32), and we're passing in a dword parameter.
ExitProcess PROTO NEAR32 stdcall, dwExitCode:dword

include io.h

cr EQU 0dh; cr = carriage return
lf EQU 0ah; lf = line feed

; Remember, memory is broken up into four types:
; Stack, data, code, and heap.
.STACK 4096

.DATA
szPrompt1 BYTE "Enter first number: ",0
szPrompt2 BYTE "Enter second number: ",0
szLabel1 BYTE "The sum is:",0
dwNumber1 DWORD ? 		; numbers to be added
dwNumber2 DWORD ?
szString BYTE 16 DUP(?) 	; input string for numbers
szSum BYTE 12 DUP(0) 		; sum in string form
szNewline BYTE cr,lf,0

.CODE
_start:
	output szPrompt1 	; prompt for the first number
	input szString, 16 	; input first number as ASCII
	atod szString 		; convert to integer (ASCII to decimal)
	mov dwNumber1, eax 	; and store in memory.
	output szPrompt2 	; repeat for second number
	input szString, 16 	; input second number as ASCII
	atod szString 		; convert to integer - always goes to eax
	mov dwNumber2, eax 	; and store in memory.
	mov eax, dwNumber1
	add eax, dwNumber2 	; add second number to first number
	dtoa szSum, eax 	; convert to ASCII
	output szLabel1 	; output label and results
	output szSum
	output szNewline
	INVOKE ExitProcess,0
	
PUBLIC _start
END
01/31/2014 19:49 KraHen#14
Quote:
include io.h
I wish we had this in my lab as well lol.
01/31/2014 20:17 Spirited#15
Quote:
Originally Posted by KraHen View Post
I wish we had this in my lab as well lol.
The magic of the MASM linker.