Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

assembly broken down session 1


010101010101010101010101010101010101010101
0 1
0 Assembly broken down 1
0 1
0 by rustymemory of uk2duohet 1
0 .we share thus we are one. 1
010101010101010101010101010101010101010101


Session 1 - introduction

what is assembly?

Assembly languages are processor-specific low-level languages. They are rarely used any more
except for handling very low-level machine-specific tasks, since languages like C can generally
satisfy most requirements, even low-level ones. The other main use of assembly language is to
provide the "glue" to enable different languages to be used in a single program. It is however
useful to know something about assembly language to get a feel for what goes on inside a
processor, as well as for understanding code generation in compilers and for debugging when there
is no source code available. -"BURKS version 6"

__________________Assembly___________________
| | |
instruction set BIOS interrupts Dos interrupts
-mov -ready subroutines
-add in bios
-jmp
-.....

Lets start by the features and draw-backs of the assembly language talking simple we can say.

[1]Features:
a- Speed.
b- Protection.
c- i/o access.
d- Size "it matters baby".
[2]Draw-Backs:
a- No 3d graphics.
b- not good with math calculations.
c- lack of documentation.

Splitting "Assembly" = i) Debugger ii) Assembler

a) debugger --> for editing, No variables , No lables.
types of debuggers --> gdb.
soft-ice.
periscope.
..........
b) Assembler --> Nasm "http://www.cryogen.com/Nasm/".
Tasm "http://home.comcast.net/~tasm/tasmdnl.htm".
Masm "http://webster.cs.ucr.edu/AsmTools/MASM/".

LETS REALLY START

[3]Registers:-
[i]General purpose registers: registers that can be divided into two equal parts of 8 bits each ,
each can be used individualy:

AX --> accumulator register -- divided gives AL "low" ,AH "high". think of AX "int a =5;", which
means that the register can hold a value. "EAX,AX,AH,AL"

BX --> Base address register -- divided gives BL, BH. think of BX "char *add = 0x45", which means
that BX is a pointer to memory address. "EBX,BX,BH,BL"

CX --> Counter register -- divided gives CL,CH. think of CX "for(i = 0; i <= 10; i++);" which
means that CX is used for loops. "ECX,CX,CH,CL"

DX --> Data register -- divided gives DL, DH.It is used for I/O port access, arithmetic, some
interrupt calls. "EDX,DX,DH,DL"

[ii]Index Registers " cannot be divided":

SI - Source index register
DI - Destination index register

these registeres are used to copy a block from a location to another.

[iii]Segment registers "pointers that point to of 64k each":-

DS - Data segment
CS - Code segment --> used for instructions
SS - Stack segment --> points to a stack segment
ES - Extra segment

*Pointer Registers______________________________________
SP - Stack pointer --> points to the top of the stack |______
BP - Base pointer -->points to a specific location in the stack|
IP - Instruction pointer - program counter. ___________________|

Flags register:
abv Flags Name bit n Description
OF Overflow Flag 11 indicates an overflow when set
DF Direction Flag 10 used for string operations to check direction
IF Interrupt Flag 9 if set, interrupt are enabled, else disabled
TF Trap Flag 8 if set, CPU can work in single step mode
SF Sign Flag 7 if set, resulting number of calculation is negative
ZF Zero Flag 6 if set, resulting number of calculation is zero
AF Auxiliary Carry 4 some sort of second carry flag
PF Parity Flag 2 indicates even or odd parity
CF Carry Flag 0 contains the left-most bit after calculations

Lets take an example to make things more clear :)

Example:
1 Mov BX,100
2 Mov AL,[bx] ----> hence [ ] == content of
3 Mov BX,0

lets analyse
line 1 : Mov BX,100 --> make BX point to memory address 100
line 2 : Mov AL,[BX] --> copy the content inside memory address 100 to the AL register
line 3 : Mov BX,0 --> forget about 100 ;)


Some notes:
F -->15
FF -->225
FFFF -->64k
FFFFF -->1024 "1mb"

*Dos can only view memory not more than 1mb.

BX is a 16-bit register, so it can only point to places up to 64k (2^16). sence a problem ?

solution is to divide memory into 64k segments(16 segments each 64k), locations in memory are
determined by:
[i] Segment number , [ii] offset inside the segment.
*Segment number = its from 1 > 16
HUH?
"art of determining a memory location >:D"
BX (offset) = 1000
DS (segment) = 3000
we add a 0 to the end of DS = 3000[0]
if we add it to BX
BX 1 0 0 0
+
DS 3 0 0 0 0
----------------
|3 1 0 0 0|
----------------
3 = segment number
1000 = offset


[4]Addressing modes:-

There are several type of addressing which we will talk about, we have :
[a] immediate addressing, [b] direct addressing, [c] indirect addressing{, [i] base addressing,
base relative addressing, [ii] indexed addressing, relative indexed addressing, [iii] base
indexed addressing, [iv]base indexed relative addressing}, [d] stack addressing. "OUCH"

*Immediate addressing: " addressing values to registers or memory"

correct example:
mov AX,5 AH AL
store value 5 in the the AX register [[00000000][00000101]]

wrong example:
mov DS,3000
you cannot store in a Segment register.

another wrong example:
mov 30,AL
30 is not a register nor a address location.

lets take a wrong example and solve it :)

mov [30],5 "wrong wrong wrong"
solution:
first of all we must determine the format of 5 either a byte or a word
in other words:-
mov byte ptr [30],5 ----> this means that at 30"address" there is a pointer to a byte.
mov word ptr [30],5 ----> this means that at 30"address" there is a pointer to a word.

5 = 05 byte ; 5 = 0005 word "2 bytes"

correct example:

mov ch,0

this doesnt affect the 0 flag register because this 0 stored in ch is not result of an operation
in the ALU. the zero flag is affected by the results of operation executed in the alu only.

*Direct addressing:- "addressing values from one register to another"

correct example:
mov AL,BL
store the value of BL in AL

wrong example:
mov BX,AL
if you do this slap your head for sometime and think AL = 8bit , BX = 16bit ... :)
solution:
mov BL,AL
mov BH,0
why ? --> it is not allowed to store 8 bits in 16 bits they have to have the same size

wrong example:

mov DS,3000
DS is not connected to the DATA bus its connected to the address bus.
in other words:
mov AX,3000
mov DS,AX

wrong example:
mov IP,AX
Instruction pointer is only changed by the processor.

i call this "HANDEL WITH CARE EXAMPLE":

mov [1234],CX
meaning:
the value of CX will be stored in memory in two locations (2bytes). so it will overwrite the value
of the location [1235] <--- handel with care :)

wrong example:
mov [1000],[1003]
it is not allowed to store from a memory location to another memory location directly.

*Indirect addressing:
[i] Base addressing: "think of it: BX = base address"
examples:
*mov BX,3FCF

*mov [BX],AX
No comments ofcourse "i wont spoon feed you"

[ii]Base relative addressing: "base addressing with addition(mov [BX+50],AL)"
example:
to transfer data from address 1000 to address 1050 ????
mov BX,1000
mov AL,[BX]
mov [BX+50],AL

[iii]indexed Addressing: "indexed??? ---> DI , SI umm index registers"
examples:
*mov [SI],DI

*mov cx,[DI]

use an index register if the segment number is different

[iv] relative indexed addressing " index addressing with addition(mov [SI],[SI+30])"
examples:
* mov [SI+50],DX

* mov [SI],[SI+30]

[v] Base indexed addressing:"using BX with SI or DI"
example:
mov DI,[BX+SI]

note: take a good look at base indexed relative addressing how it differes from base indexed
addressing.

[vi]base indexed relative addressing:"using BX with SI or DI along with addition"
example:
mov DI,[BX+SI+10]
hence the "10" ;)

note: keep in mind you wont be thinking while coding , ill do it via relative indexed
addressing or shall i use ase base indexed relative addressing no they are just some info
you would start to know for yourself so dont worry :).

*Stack Addressing:-"using SP and BP"
example:
lets say [sp] holds value 300 while DS holds 1000 and SS holds 2000 :)
*mov AL,[sp]
so this location is segment 2000 offset 300 :)

[5]SEGMENT OVERIDE:
I DONT WANT TO BE DEAULTY WRITTING TO THIS SEGMENT CAN I CHOOSE MINE ???? :) yes
examples:
*mov AX,ES:[DI]

*mov ES:[SI],AX
mov SS:[BX],CX
mov DS:[BP],DX
mov CS:[SI],AX

looks wierd? no
explanation:
":"-- Specify a segment override in a operand -- like CS:[SI],AX
so CS will be used instead of ES.

now its the end of our first session i hope you had fun.

"we share thus we are one"-uk2duohet


Sign In or Register to comment.