September 28, 2011

C Assembly Programming - Assembler

Assembly Programming Series by MyCFiles.com
Now this is what you guys were waiting for. This is where real assembly starts. . .

Before you read this part read privous 2 parts
Introduction to C Assembly Programming - Part 1
C Assembly Programming – Binary Oprations and Concept of Registers

This Part Consist
# ASSEMBLER
# ASSEMBLY INSTRUCTIONS
# A SHORT PROGRAM

ASSEMBLER
an assembler to assembly is what compiler is to c it is used to convert our .asm code into .obj and then linked to form .exe.



WHICH ASSEMBLER TO CHOOSE???

Though software stores are full of free assemblers but The BEST assembler is TASM its version i am using is 5.1 download it here
http://www.phatcode.net/downloads.php?id=280&action=get&file=tasm5.zip

I am leaving the headache of installing on you (but feel free to ask it).Special reason to use it is that it can be fully integrated with TURBO C(later in series) and quite good at debugging.


ASSEMBLY INSTRUCTIONS
No assembly program can be written until you are familiar with its instructions. they are used to do Specific(tiny) things in your program.
See the whole list here.

http://home.comcast.net/~fbui/intel.html

Its large i want you to learn following specifically. .
MOV,INT,INC,DEC,ADD,SUB,AND,OR,XOR,NOT,JMP,DIV,LEA,OUT,IN,PUSH,POP.

A SHORT PROGRAM
/*Assembly Programming By MyCFiles.com */
;a short assembly program
; call it first.asm
IDEAL ;set ideal mode
MODEL SMALL ;set model of .exe
CODESEG ;start of our code
STACK 256 ;set our programs stack

START:
;display letter A on screen
MOV ah , 0Ah
MOV al , "A"
MOV cx , 1
MOV bh , 0
INT 10h
;give control back to DOS
MOV ax ,4C00h
INT 21h
;end of start
END START
"START"
ohk its time to satisfy your enquiring minds. . .

IDEAL - there are basically 2 modes for assembly program ideal or masm mode.for OOP features of tasm we use ideal mode.

MODEL - every exe has a memory model deciding its memory access. Here we use small model (<64 kb).

CODESEG - this line tells assembler that now code begins.

STACK 256 - every program has a stack. this line allocates the stack of 256 bytes for our short program.

START: - the starting point of our code (feel free to use any name) just like main.

The rest is interrupt coding to write A on screen. (i wont explain it but you can ask as a query).

One thing to know is in assembly control needs to be explicitly given back to DOS. (via int 21h).

END START:
"START"
- this means our start label is ending. it implies a call to start in our code.

RUNNING THE CODE - following code. . . .

I know its bit short but i am not telling each and everything
You your selves need to dig out more on it. . best of luck, ask your queries :)

Related Posts :



1 comments:

hey hi
nice article
but its all about theory
can you explain us that how we will actually implement c in asembely level
ie
to embed with the register
can you give steps to implement practically

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Related Posts with Thumbnails