A newbie guide to Assembler programing
Common Instructions

© 1997 by Cruehead / MiB


Here...

we'll describe the instructions that you must know in order to understand whats going on. This is only the basics and if you want to become a serious cracker (and I hope you want to), you better learn more about the asm instructions.


MOV dest, source
This instuction simply moves a value into a location in the memory (register or variable).


EG : MOV AX, 1234h  ; AX = 1234h

     MOV BX, AX     ; BX = AX

First of all this would move the value 1234 hex (4660 dec) into the AX register. Then the value in AX (1234h) would be moved into the BX register. In a high level language this would be the same as AX:=$1234; BX:=AX; (pascal notation).


ADD dest, value
This simply add's something to the value stored in dest.


EG : MOV AX, 10h    ; Ax is now 10h

     ADD AX, 10h    ; Ax is now 20h

     ADD AX, 5h     ; Ax is now 25h


SUB dest, value
This substracts something from the value stored in dest.


EG : MOV AX, 10h    ; AX is now 10h

     SUB AX, 2h     ; Ax is now 8h


INC dest
Increments something (register, variable or anything).


EG : MOV AX, 10h    ; AX is 10h

     INC AX         ; Ax is now 11h


DEC dest
Decrements something (register, variable or anything).


EG : MOV AX, 10h    ; AX is 10h

     dec AX         ; Ax is now Fh


CMP source, dest
Compares source with dest.


EG : MOV AX, 10h    ; AX is 10h

     MOV BX, 11h    ; BX is 11h

     CMP AX, BX     ; Compares AX with BX

The line after CMP AX,BX will problaby be a conditional jump. If we wanted to jump if AX=BX, we would place a JE (Jump if equal) location (location would be an offset) after the CMP instruction. If we wanted to jump if AX was NOT equal to BX, we would place a JNE (Jump if not equal) location after the CMP instruction. There are alot of conditional jumps - here is a list of them.


JMP location
Jumps to another location in the code.


EG : JMP 200h       ; The program would here jump to offset 200h


MOVSB or MOVSW
Moves (well, copies really) either a byte (MOVSB) or a word (MOVSW) from DS:SI to ES:DI Increments SI.


EG : Lets say that DS:SI points to a byte which holds the value of 5h

     MOVSB          ;  Takes the byte that DS:SI points to and places it in ES:DI



     The byte that ES:DI points to now has the value of 5h

These instructions is very common in cracking, when a string is copied to another location. The instructions are then used together with the REP instruction.


LODSB or LODSW
Loads either a byte or a word from DS:SI and puts it in AL (LODSB) or AX (LODSW). Increments SI.


EG : Lets say that DS:SI points to a word which holds the value of EBh

     LODSW         ; Copies the word that DS:SI points to and places it in AX



     AX will now contain the value of EBh

These instructions are often used together with the REP instruction.


STOSB or STOSW
Takes the value in AL (STDSB) or AX (STDSW) and places it in DS:SI. Increments SI.


EG : Lets say that AX holds the value of EBh

     STOSW         ; Copies the value in AX and places it in the word that  DS:SI points to.

                   ; DS:SI now points to a word containing EBh

These instructions are often used together with the REP instruction.


REP
Repeat an instruction for the number of times specified in the CX register. A REP infront of a MOVSB,LODSB or STOSB (or infront of the word versions of these instructions) would cause that instruction to repeat itself.


EG : MOV AL,Bh     ; AL now contains bh

     MOV CX,5h     ; CX now contains 5h

     REP STOSB     ; This would copy the value of AL (5h) into whatever DS:SI points to 5 times

	           ; and increment SI for every time.


CALL procedure
Calls a procedure, and after the procedure is finnished, returns.


EG : CALL 4020     ; Jumps to the offset 4020 and continues the execution there until it

	           ; reaches a RET. Then it continues on the next line.

This was a near call. When a near call is executed you only jump to a diffrent offset. There are also far calls. They jump to a complete diffrent segment and offset.

EG : CALL 013f:2310    ; Jumps to segment 013f, and the offset points to 2310.


Back to Asm tutorial page!Back to Asm tutorial page...

Copyright © MiB 1998. All rights reversed.

--------------26EE308E7E7BCAA662FDB40E--