29
Programming is an art. Assembly Language. So why assembly language???? No programmer is complete without mastery over assembly language.. Your program ruins slow or there is some deep glitch. You work on it day and night and still the glitch remains a glitch. Here comes the assembly language. You analyse the processes and come at a diagnosis… Assembly language makes you powerful. It is the base on which everything is built. Without assembly language you will always remain a novice. Whatever you build or achieve. You must have heard that the: Assembly language is hard to learn and understand It’s difficult to debug It’s a messy outfit Why do you want to save a little space using assembly language when you have so much space? Assembly language has several benefits: Speed. Assembly language programs are generally the fastest programs around. Space. Assembly language programs are often the smallest.

amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

Embed Size (px)

Citation preview

Page 1: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

Programming is an art.Assembly Language.So why assembly language????                 

No programmer is complete without mastery over assembly language..

Your program ruins slow or there is some deep glitch. You work on it day and night and still the glitch remains a

glitch. Here comes the assembly language. You analyse the processes and come at a diagnosis… Assembly language makes you powerful. It is the base on which everything is built. Without assembly language you will always remain a novice. Whatever you build or achieve.

   You must have heard that the:

Assembly language is hard to learn and understand It’s difficult to debug It’s a messy outfit Why do you want to save a little space using assembly

language when you have so much space?   Assembly language has several benefits:

Speed. Assembly language programs are generally the fastest programs around.

Space. Assembly language programs are often the smallest.

Capability. You can do things in assembly which are difficult or impossible in HLLs.

Knowledge. Your knowledge of assembly language will help you write better programs,even when using HLLs.

Page 2: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

LESSON1 - THE REGISTERS AND SEGMENTS   Unlike other languages there is no predefined commands like  "writeln", "printf",…Assembly language does not provide those tools for you  So how does it work>? Assembly Language has predefined registers: All of these are the data holders AX - accumulator index BX - Base index CX - Count index DX - Data index

All of these are the pointing and index registers SP - Stack pointer BP - Base pointer SI - Source index storage DI - Destination indec IP - Instruction pointer

All of these are segments holder CS - Code segment DS - Data segment SS - Stack segment ES - Extra segment FLAGS - Holds some of the function conditions

Now to be more specific :  Data registers:

Page 3: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

They are the basic registers for all the computer calcs, and position Each of the registers is 16bit and they are divided into two registers high and low which are 8 bit : AX - ah (high), al (lo) BX - bh (high), bl (lo) CX - ch (high), cl (lo) DX - dh (high), dl (lo) High is MSB - most significant byte Low is LSB - least significant byte Pointing registers: Each of these registers has a unique job: SP - is the offset of the stack (-n-) BP - a pointer for the stack (-n-) SI - is the source index, uses as an offset in memory transfers DI - is the destination index, uses as an offset in memory transfers IP - is the offset of the current instruction (-n-) (-n-) means don't change unless you know what your'e doing

Segment registers: CS - is the segment of the code (-n-) DS - is the segment (usually) of the data SS - is the segment for the stack (-n-) ES - is an extra segment, uses for memory transfers Flags, will be discussed later

Assembly language  works with segments .each segment has a  maximum  limit which is 64K, Now we create a segment.

Page 4: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

when we have a segment we have to give it a definition, For this  we  need the command "Assume" which gives each one of the segments registers it's default segment, Here is a typical segment—- Sseg segment ; a semicolon (;) is a remark and will not be compiled db 10 dup (?) ends ; each segment has a name and the "segment" after it ; when we finished to define stuff in the segment ; we close it with ends (end segment) Dseg segment ends Cseg segment assume cs:cseg,ds:dseg,ss:sseg ends end

LESSON 2     Basic operations!!!!!In the last chapter we learned how an assembly language program is built.Now we move on to a higher level.The operators.MOV destination,source : lets say "mov ax,bx" ax will become the value which bx stores. ADD destination,count : lets say "add ax,bx" ax will be increased according to the value in bx - lets say ax = 10, bx = 2 then ax will become 12 (10+2) SUB destination,count : lets say "add ax,bx" ax will be decreased according to the value in bx - lets say ax = 10, bx = 2 then ax will become 8 (10-2)

Page 5: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

INC destination : lets say "inc ax" then ax will be ax+1 DEC destination : lets say "dec ax" then ax will be ax-1 AND destination,count : lets say "and ax,bx" then ax will be anded with bx, lets say ax = 1, bx = 0 then ax will be 0. OR destination,count : lets say "or ax,bx" then ax will be ored with bx, lets say ax = 1, bx = 0 then ax will be 1.              know after we learnt the basic command, what happened about the size of those registers well, you can't do one of those between registers which aren't not the same size : "mov ax,bl", "mov al,bx", "add cx,cl" and so on. simple example, if we want to preform subtraction, what will do, (before each example check if you can do it your self) : mov ax,20 ; ax will be 20 mov cx,10 ; cx will be 10 sub ax,cx ; ax will be 10 (ax-cx,20-10) know if we have a number in hex or bin and we want to put it as it is so we will have to put "h" after the number for hex and "b" for bin : mov ax,0a000h ; you must have a zero before a letter in hex mov ax,010010b ; a simple number in binary             

Page 6: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

 

LESSON3 - INTERRUPTS LABELS AND DB The example I showed above will run,but it will not exit.For a program to be a program,it must be complete.ie it must exit.we must tell dos we want to exit :It is done simply by using the operator "int" which calls to interrupt.(0..0FFH) and instruct him what to do, so lets discuss  some int's : 009h - the keyboard interrupt 010h - the screen interrupt 013h - the sectors, (format, read, write) interrupt 016h - the keyboard interrupt 017h - the printer interrupt 021h - the main dos command  each interrupt got many command and each one needs difrrent parameters (if you want to know get the complete int list from your local BBS) INT 21 - TERMINATE ah - 4ch al - errorlevel so in order to initiate this interrupt we will do : mov ah,4ch mov al,0 ; if you want it can every value int 21h ; and then the program will exit to dos but how will the compiler know where to start, well we have to tell him, the compiler will know to start excatly in the first, label - label is a name which you can jump to him, the label will be like : Name : - "start :", "now :", "rt :" all of those are labels, so this is a basic (working) assembly program :  Sseg segment db 10 dup (?) ; will be disscused late ends Dseg segment ends Cseg segment

Page 7: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

assume cs:cseg,ds:dseg,ss:sseg start : ; the compiler will start here mov ah,4ch mov al,0 int 21h ; terminate ends ; the segment must finish before the label end start ; close the label end ; tell compiler script ends here

That was easy.I hope.If you could not get it fair and square, I have some eBooks as links in the home page. Just check out them and come back. It is the main assembly struc, but it can be much more complex. now in the sseg (stack) there was "db". what is that?well if (most of the times) assembly registers are not enough so you (like pascal,c) can define variables, how ? well you have the operators - db,dw,dd,dt :  DB - define byte, the var will be 1 byte (8 bit) DW - define word, the var will be 2 bytes (word, 16 bit) DD - define double, the var will be 4 bytes (double word,32 bit) DT - define ten, then var will be 10 bytes (not used) the decleration goes like this : name type [number] value. examples : try db 1 - it will define "try" as 1 byte with starting value 1 tru dw 4 - it will define "tru" as 2 byte with starting value 4 ytu dw ? - it will define "ytu" as 2 byte with unknown starting value now lets say that you want to define an array (like pascal : a:array[1..10]of like c : int c[100]) you do as follow : name type number dup(value). lets say : gvr db 10 dup(2) - it will define "gvr" as 10 byte which each one has value of 2. but what if I want to define a messege or multiple values then what ?? then it should be like : messege - mes db "this is a messege",10,13,"$" now the numbers after the second """ are optional, it's needed only for some interrupt. multiple values (vectors, etc.) then : vec db 23,54,76,34,234,14,23,123,245 db 124,34,245,23,52,34,52,43,13

Page 8: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

db 213,213,123,123 the db can be dw,dd or dt, and you can do it for how much you want but you must not pass the 64k limit. but what if you want to write a messege then ??? you will search the int which do that : int 21h - write string ah - 9 ds:dx points to string (in the end "$" for termination) so how will we do it ???   Sseg segment db 10 dup (?) ends Dseg segment msg db "dr. encryption",10,13,"$" ; for termination ends Cseg segment assume cs:cseg,ds:dseg,ss:sseg start : ; the compiler will start here mov dx,offset msg ; ds is already pointing to dseg mov ah,9 int 21h ; whop there he is mov ah,4ch mov al,0 int 21h ; terminate ends ; the segment must finish before the label end start ; close the label end ; tell compiler script ends here   now what offset is, well offset will return the offset of the argument so if you write : mov dx,offset msg then dx will be the offset of the msg (offset is 16bit and so is segment ,so "mov al,offset ..." will be wrong) the operator seg will return the segment of the argument, but if you change ds and not return his original value the system will hang. so then the stack comes to buisness.

LESSON4 - STACK (PUSH,POP) AND MORE COMMANDS

Page 9: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

stack, how does it work ? the law is last in first out, the principle is if I enter a series of numbers like : 1 34 54 54 65 and then I take them out I will get : 65 54 54 34 1. in assembly the command is push (it can push only 16bit) and the reverse is pop. so lets say I want to save the ds and later get it back :  push ds . . . . pop ds mov ax,4c00h ; short cut for : mov ah,4ch mov al,0 int 21h  ok now you've got the basic of assembly (I hope). in order to pass to the next level we have to explore the structure of the 8 bit register !!!  now bit is a condition that can be 0 or 1 so if we have 8 bit so the number of combinations can be 2^8 which is 256 (0..255) the limit of one byte (or word 2^16 65535) so assembly gives us the tools to modify and alter those bits.  SHR destination,count : Shift arithmic right divide the number by count^2 so 1 is 2 and 2 is 4 and so on "shr ax,4" will divide ax by 16 (4^2) SHL destination,count : Shift arithmic left multiply the number by count^2 so 1 is 2 and 2 is 4 and so on "shr ax,4" will multiply ax by 16 (4^2) ROR destination,count : Rotate right rotates the bits right so bit 0 is now bit 7 (16 bit, bit 0 is bit 15) and does is by count.  

Page 10: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

"ror al,8" will not affect cause there are only 8 bits so a whole round will be preformed. ROL destination,count : Rotate left rotates the bits right so bit 7 is now bit 0 (16 bit, bit 15 is bit 0) and does is by count. "ror al,8" will not affect cause there are only 8 bits so a whole round will be preformed. DIV factor : Divide will divide ax (or al) by the factor ("dx" must be set to 0), "div cl" will divide al by cl, "div cx" will divide ax by cx. MUL factor : Multiply will multiply ax (or al) by the factor (dx will be altered), if the operation is 8 bit "div cl" then the sum will be stored in ax (if it passes 8 bit) "mul cl" will mul ax by cl, "mul cx" will multiply ax by cx. NEG destination : Negation what it does he reverses negativity lets say we have 4 so it will become -4 and vise verse (n*-1)

as you might have noticed no floating points nor integers has been discussed well assembly has no floating points (don't be shocked) because you can still use the precision well how ?there are fixed points. fixed points are precision that was shifted before and after the calc been shifted back. fixed points example : mov ax,100 ; our circle radios mov cx,181 ; 181/256 is 0.707 (sin(45)) mul cx ; multiply (result : 18,100) shr ax,8 ; now the number is shifted back (n / 256 = shr n,8 cause ; 2^8 is 256) so the result is 70.7 (the point disapears) ; number is trunced to 70 (if you check 100*0.707 is 70.7) the fixed points are much faster then real (double) and usually the sin cos table is being written onto a file predifined by pascal,c example for extracting cos(56) to fix : var a:integer ;

Page 11: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

begin a:=trunc(cos(56*pi/180)*256) ; end ; now first we converted deg to rad and then multiply it by our factor. but, but, but noticed shr,shl,ror,rol do not work on integers, it will get wacked and will bug you program, so we need to detect if it's lower/higher then zero so we go to next chapter (flags and jumps)

LESSON5 - FLAGS AND JUMPS

in the last chapter we talked about fixed points and their limitations (assembly has integers you just have to give them neg value) of shr,shl,ror,rol and the need to detect zero so what we have is flags, 16 bit register the each bit is a different status of something that happed.  major flags : CF - Carry flag is set when there is a borrow in some command lets say "sub ax,13" and ax is 21 so a borrow will apear. PF - Parity flag is set when the LSB of the operation is even, lets say "add ax,11" and ax is 11 so the flag will be set (even) ZF - Zero flag is set when the operation is zero lets say "dec ax" and ax is now 0 so ZF will be set. OF - Overflow flag is set when the operation is beyond the limitation of the register lets say "add ax,65535" (ax=100) so the flag will be set. there are more flags but much of them aren't used so (if you want to know open a book or norton guides to assembler) now before anything else a most important command is :

Page 12: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

CMP register,value - Compare a register to a certain value and set all needed flags. lets say "cmp ax,0" and ax is 0 so the ZF will be set. but (you may ask) how do we use those flags well the answer is conitional jumps !! JNE - Jump if not equal JZ - Jump if zero JE - Jump if equal JB - Jump if below JA - Jump if above JAE - Jump if above and equal JBE - Jump if below and equal JC - Jump if carry JNC - Jump if not carrt JS - Jump if sign JNS - Jump if not sign JMP - Unconditional jump note : all of these conditional jumps (not jmp) can jump only in the range of near (256/0ffh bytes) and only jmp can jump to the entire code !!!

use - JMP label example : mov ax,10 mov cx,20 mov dx,0 div cx ; does 10/20 result is 0 (if you don't know that so go back ; and repeat the commands. ) cmp ax,0 ; is ax 0 jz @iszero ; then it is so jump to label mov cx,ax mov dx,0 div cx ; it will never reach it cause it will never be larger then ; zero (if you comment the jz so you will get divide by 0) @iszero : ; this is a label the "@" before the label is optional mov ax,4c00h ; terminate

Page 13: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

int 21h now lets get back to our fixed points that we want to convert : mov ax,100 ; our circle radios mov cx,181 ; 181/256 is 0.707 (sin(45)) mul cx ; multiply (result : 18,100) cmp ax,0 ; is ax 0 jb @neg1 ; jmp below so if neg jump to label shr ax,8 jmp @done ; don't want to get with the div @neg1 : mov dx,0 mov cx,256 idiv cx ; ax/256 just use idiv it's a div for integers @done : mov ax,4c000h ; terminate int 21h so that's about it in jumps and flags, I sugest that you will train a bit about all the stuff that you have learned in those chapters cause it is very important to understand those (those are the needed basic) in the next chpaters we will start transfering memory blocks, and use graphics.                       

LESSON6 - MEMORY MOVING lets say I want to move from one memory point to another lets say for now the text screen, (seg is 0b800h and it's size is 4000 bytes) so we have to use some very special command : MOVSB - Moves string byte, moves one byte from DS:SI to ES:DI and if the CF is 0 (CLD is the command thats set is to 0) then both si and di are incremented, if CF is 1 then (STD) si and di are decremented. MOVSW - Moves string word, moves one word (2 bytes) from DS:SI to ES:DI

Page 14: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

the method of incrementing is the same like movsb just it does it by 2 and by 1 byte. REP command - Repeats a certain command lets say "rep movsw" it will preform movsw in a loop and which cx defines how much, if cx is 10 then the movsw will be done 10 times. now after we know those command lets implement them !!!!!!!!!!!!!!!!! sseg segment db 10 dup (?) ends cseg segment assume cs:cseg,ss:sseg,ds:cseg,es:nothing buf db 4000 dup (?) start : push ds ; we must save it mov ax,seg buf ; we cannot type into segment registers directly mov ds,ax ; it goes into simple register and then to the segment mov si,offset buf mov ax,0b800h ; adress of screen mov es,ax mov di,0 mov cx,2000 ; to speed up use movsw (4000 bytes/2) rep movsw pop ds mov ax,4c00h int 21h ends end start end and thats is, but what I will do if I want lets say clear the memory with out using buffer or clearing the buffer it self ????

STOSB - Store string byte, stores al in ES:DI if the CF is 0 then di is incremented, if CF is 1 then di is decremented.  STOSW - Store string word, stores ax in ES:DI if the CF is 0 then

Page 15: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

di is incremented, (by 2) if CF is 1 then di is decremented (by 2). ^ now the procedure is almost the same as the moving of a buffer sseg segment db 10 dup (?) ends cseg segment assume cs:cseg,ss:sseg,ds:cseg,es:nothing start : push ds ; we must save it mov ax,0b800h ; adress of screen mov es,ax mov di,0 mov cx,2000 ; to speed up use movsw (4000 bytes/2) mov ax,0 ; we want to clear it rep stosw ; stores ax 2000 times in ES:DI (screen) pop ds mov ax,4c00h int 21h ends end start end

LESSON7 - PROCEDURES AND MACROS

in assembly as in pascal,c and basic you have the option of using procedures, to declare a procedure you do : Proc name "proc" distance (far/near) . . . ret endp ; end proc and to call the proc you type "Call Procname" the ret must come because you have to return to the exact point you called the proc from, if you pushed registers and didn't pop them it might not return to the calling position.

Page 16: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

sseg segment db 10 dup (?) ends cseg segment assume cs:cseg,ds:cseg,ss:sseg,es:nothing clearscreen proc near mov ax,0b800h mov es,ax ; clear the screen, point to screen mov di,0 mov ax,0 mov cx,2000 rep stosw ; if don't understand go back to learn ret ; try to erase this and see what happends endp start : push ds call clearscreen pop ds mov ax,4c00h int 21h ends end start end  what is macro, macro is a type of semi procedure, the compiler will copy the code of the macro into the calling point and therefore increasing the code size and saving a few cycles. one problem the macro has is that you can't use labels becase if you will and call it number of times there will be duplicate labels and the compiler will return error message

macro declarating : Macro name "macro" parameters . . . endm ; end macro to call the macro you just write his name, the parameters is values to pass

Page 17: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

sseg segment db 10 dup (?) ends cseg segment assume cs:cseg,ds:cseg,ss:sseg,es:nothing macro clearscreen amount ; amount is a parameter mov ax,0b800h mov es,ax ; clear the screen, point to screen mov di,0 mov ax,0 mov cx,amount rep stosw ; if don't understand go back to learn endm ; go back start : push ds clearscreen 2000 ; the code will be copied to this point pop ds mov ax,4c00h int 21h ends end start end so when you write code you will have to deside what's better for you speed (not much) or size (it can go up to ....) I usually use procs a problem comes up, what happend if a want to use procs and save them in another file (like unit,lib) and use them in my code, the next chapter will disscuss that.

LESSON8 - EXTERNALS AND PUBLICS

now in order to call a proc from another file, the files which contains the proc will have to declare the proc as public : . .

Page 18: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

. public clearscreen clearscreen proc far . . . ret endp and in your file you will have to declare the proc as extrn : . . . extrn clearscreen:far . . call clearscreen you can also declare public/extrn global arguments. way of compiling : your file - prog.asm extrn file - clear.asm than tasm prog tasm clear tlink prog clear error can occure in tasm if you didn't define public/extrn and in tlink if you wont supply the extrns. in this point you know most of assembly but you are lacking of technics in this point you will have to get sources and analize them, in the next chapter we will talk about entering info into EXE

LESSON9 - INCLUDING INFO IN THE EXE

the method to this is almost the same as extrn/public, the way to this is using the prog "binobj" which comes with tp/bp or bc/tc and use is a following : "binobj" <InputFileName> <OutputFileName> <PublicName>

Page 19: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

lets say we have pic.dat and we want the public to be dat1 then : "binobj pic.dat pic.obj dat1" and <- lets say it was a data of screen made with pascal : program example ; uses dos,crt ; var z:file ; begin assign (z,'pic.dat') ; rewrite (z,1) ; blockwrite (z,mem[$b800:0],4000) ; close (z) ; end. this will give us a screen file, and now how to show it : sseg segment db 10 dup (?) ends cseg segment assume cs:cseg,ss:sseg,ds:cseg,es:nothing extrn dat1:far start : push ds ; we must save it mov ax,seg dat1 ; points to extrn seg mov ds,ax mov si,offset dat1 mov ax,0b800h ; adress of screen mov es,ax mov di,0 mov cx,2000 ; to speed up use movsw (4000 bytes/2) rep movsw pop ds mov ax,4c00h int 21h ends end start end this will write the pic to the screen, compiling goes like that : "binobj ...." "tasm filename.asm"

Page 20: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

"tlink filename pic.obj" and that's it, but what if we use a picture, then ???  well you will have to open a new segment for the extrn : newseg segment extrn dat1 ends

this way you will avoid passing the 64k, if your data passes 64k then split it or use protected mode (how, learn it, it ain't easy) ; writing a picture to screen (graphic) program example ; uses dos,crt ; var z:file ; begin assign (z,'pic.dat') ; rewrite (z,1) ; blockwrite (z,mem[$a000:0],64000) ; close (z) ; end. sseg segment db 10 dup (?) ends cseg segment assume cs:cseg,ss:sseg,ds:cseg,es:nothing extrn dat1:far start : push ds ; we must save it mov ax,13h int 10h ; goes to graphic mode 320*200*256 mov ax,seg dat1 ; points to extrn seg mov ds,ax mov si,offset dat1 mov ax,0a000h ; adress of screen mov es,ax mov di,0 mov cx,32000 ; and,,.... it's on the screen

Page 21: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

rep movsw mov ax,0 int 16h ; pause mov ax,3 int 10h ; goes back to text pop ds mov ax,4c00h int 21h ends end start end compiling : "binobj pic.dat pic.obj dat1" "tasm filename" "tlink filename pic" and run the program

LESSON10 - PORTS, TIPS, SUMMARY the way of the computer to communicate with it's cards is through the ports, lets say the screen data port is 3dah and the keyboard port is 60h,64h IN al,port ; al recieves the value in port OUT port,al ; port recieves the value in al basic listing of ports (can't get it on a list) : 0-7 : dma base ports 20h : pic, interrupt aknowlege 21h : interrupt masking port 40h : timer port 43h : timer init port 60h : keyboard keys port 64h : keyboard control port 3c8h : screen pal port 3dah : screen data port and there are more, non significent or that I don't know (and there a lot) TIPS :

Page 22: amaiu.wikispaces.comamaiu.wikispaces.com/file/view/assembly.docx  · Web viewProgramming is an art. Assembly Language. So why assembly language???? No programmer is complete without

- never use a source that don't know what it does. - take sources and learn them. - learn to use any debug program. - assembly is a language that every mistake can be important and the computer may hang, so don't give up. - use qemm is traps errors that you won't know . - get an interrupt list (very very important). - don't be a lamer. SUMMARY : you have learned in those quick 10 lessons, to code in assembly - this is realy the basic, currenly you can't do much but the hard work is behind you. now you will just have to learn the technics (no shortage of those) and maybe some day you will right a better guide than this. good programing to you all. reminder : don't be one of those lamers that uses lots of units/lib and say you are a good programmer, do it yourself that's the trick.