Thread: ASM Programing?
View Single Post
  #4  
Old 08-27-2009
johndowe's Avatar
johndowe johndowe is offline
Senior Ladyboy Lover
 
Join Date: Nov 2008
Posts: 538
johndowe is infamous around these partsjohndowe is infamous around these partsjohndowe is infamous around these partsjohndowe is infamous around these parts
Default

Hi there.

Took a while but, i processed the info...

Sesame if you want to learn ASM, just to understand your computer better, then read the manual included with the assember i found (link et the end), but, if you want to become an assembly language programmer, then you will need a few things and a lot of patience and determination, the reason i stopped programing in asm was because my first XP was home and it didn't support dos programs then i ans many others complainned and the home version was dropped, but i only found out much later, also my asm only worked on FAT16, not FAT32 or XP Pro's NTFS, at the time i was a bit bumed out and went on to other pastures, to be poetic.

Learning asm to become an assembly language programmer, requires dedication, because you need to learn your cpu's processor's instructions, their addressing modes and the processor's structure and registers which is not too much to learn, many instructions you will use constantly, some you will use ocasionnally, and some you will rarely use, and there are some you will never use (unless you are programing an operating system).

Once you have learned that, you will have to learn about your computer system's Basic Input Output System, the BIOS, the CMOS Ram, the RTC (real time clock) the bios system calls, and the various BIOS, DOS, and Win memory usage loctions which WILL help you alot in your programing endeavors, you will also need to learn about I/O devices like the Serial Port, the Paralel Port and a few others, most of the newer I/O devices are usually well supported by windows, so you will need a reference manual or three or more, you will also need an assembler, a text editor, notepad is not that great but wordpad is better and will serve you well here, if you have office you could use word but the spellcheck IS a pain it the arse since we are not writing a letter but a program and you have to make sure you save your files as text files, and with a .ASM extension, you will also heve to learn about ASCII characters, binary, octal and Hexadecimal numbers, which will be very usefull in dealing with bits, bytes, data and addresses, you will also have to learn about bolean algebra, which is binary logic.

So you will need:

An assembler.
An X86+ processor reference. (registers, instructions, segments, flags etc.).
A text editor. (that one you already have, Yay).
A bolean logic guide of some kind.
A hardware reference, for all the IRQ's (hardware interupt requests) the int vectors, the reset, the I/O Chipsets etc.
A bios reference with all the memory locations & INT calls.
A DOS programing reference for all the DOS memory locations and interrupt calls.

These can be either a book (usually several books), as files from the internet, your choice but a book can be carried with you pretty much everywhere, but files can be searche more easily, you can also create your own files with the info you find in the previously mentionned sources, also computer electronic device manufacturers often suply free info about thier products that canbe very usefull, and you should as you progress, make a library of often used debuged and documented routines.

A simple memory clear loop:

CLRRAM: MOV AX,0
MOV CX,1024
MOV DI,AX
CLEARING: MOV [RAM+DI],AX
INC DI
INC DI
DEC CX
JNZ CLEARING
CLC
RETN

The first line you see a label, which is used to reference program entry points, loop points and data, the names can be anything you want, but id MUST begin with a letter and end with a ":" and you may not use names that are also ASM DIRECTIVES like BYTE, WORD etc, it is better to use label names that are reltive to the segment of code is used for, instead of an arbitrary name like banana, because a few months later you see " CALL BANANA", then you think what does BANANA do and where is it? but " CALL CLRRAM" is self explanatory. The ASM code "MOV AX,0" which puts 0 in the register called AX, that was the long and slower way, you could use "SUB AX,AX" substracting ax from itself will always = 0 it is faster and saves the 2 bytes from the program, but the fastest is "XOR AX,AX" why is it the fastest? Because unlik the first and like the second it doesn't have a second word of memory to fetch, but it is a logical operation instead of a mathematical one like the second one whitch has to set the carry and other flags, while the logical one only sets the zero and negative flag which makes it quicker, but one shoust not go crazy with the compactness or speed of execution, the fact that your progam is programmed in asm will ensure that it is way smaller and way faster than anything programmed with an "evolved" language, i just wanted to demonstrate that in asm there are more than one way to accomplish the same thing, but if you wanted to fill the memory block with "0101 0101 0101 0101" binary you would have to use " MOV AX,5555H", "0101 0101 0101 0101" is binary, HEXADECIMAL is grouping 4 bits togather which comes out to 5555 Hex, the AX register is the Accumulator and is used primarily for math, but not exclusively.

The second line sets the Register CX to 1024, and the loop will repeat 1024 times, the CX register is primarily used as a counter but again not exclusively.

The third line sets the regidter DI to the same value as AX, which in this case it is 0.

The fourth line is a bit different, why is there some square braclets? And RAM+DI? The square brackets mean that you are not using a register as a destination but a memeory location the label RAM is defined elsewhere and points to memory that this program uses for data, the DI is an index register and the effective address is: the value of RAM + the value of DI, the first time DI = 0, and stores the value of AX in it, and AX = 0.

The fifth and sixth lines increment DI, do that the next time it will be equal 2, why 2? because we are moving words (16 bit at a time) and the address is referenced in bytes (8 bits at a time).

The seventh line decrements CX.

The eight line uses the result of the previous instruction and Jumps if the result was NotZero JNZ, since the first time result was 1023 the jump is taken and the loop re-iterates...

The ninth line is "CLC" which clears the carry, i as many asm programers use the carry to check if there was an error, if the carry is clear there is no error, this sub routine is very simple and there are no possible errors, this instruction could be removed.

The last line RETurns to the sending instruction the N specifies that it is a Near CALL that used the routine as oposed to a Far CALL.



ASM With good doc: http://www.bestdiskrecovery.com/ngasm/index.html Follow it to D/L NGASM the tutorial is very good, all 275K's of it.


JohnDowe.

PS JohnDowe is MY CPU's name.
Reply With Quote