assembly tutorials
assembly tutorials
r there any really good, explanatory ones around? i'm currently reading one that i like, but well u know, just does anyone have links?
Re:assembly tutorials
My advise is- READ READ READ manuals and tutorials of asembly language.There will come time when you will realize what it is and this that asembly language isn't hard
Re:assembly tutorials
Various tutorials:
http://www.programmingtutorials.com/tutorial.asp?id=Asm
There actually isn't much to assembly. The trouble comes from interfacing with the operating system. Also, different assemblers have idiosyncratic add-ons that are meant to help the experienced programmer, and these can cause considerable confusion.
The best teacher, IMO, is other people's code and Intel's own documentation. Unfortunately, the best little programming examples in assembly were written a long time ago in assembers that aren't as popular anymore. Today, NASM is the drug of choice. In the past, professionals used MASM and hackers used TASM. Even so, if you start with NASM examples, then branch into cool little TASM programs on simtel.net, you'll learn a lot.
If you have an Intel machine, you'll want this:
http://www.baldwin.cx/386htm/toc.htm
To get you started with a NASM example, here is an early version of something I wrote for an assembly tutorial a while ago (sorry, I couldn't find the final, neater version). Get NASM; have the docs close by; Ralf Brown's interrupt list (www.ctyme.com/intr/int.htm); the Instruction set above; and go crazy. You won't understand the algorithm, but you will like the result. This assumes you are generating a COM file in some kind of Microsoft environment.
org 0x0100
???mov???ax,13h
???int???10h
???
???mov dx, 03d4h ;this chunk modifies the VGA to be 320x100???
???mov al, 09h
???out dx, al
???inc dx ???
???mov al, 03h
???out dx,al
???
???
???mov ax, 0a000h
???mov es, ax
???
???mov al, 63
???mov ch,3
???mov di, 64*3
???rep stosb
???mov???si,2+63*3
???xor???ax,ax
???
???call???PaletteGenProc
???inc???bx
???call???PaletteGenProc
???mov???si,1+63*3
???call???PaletteGenProc
???
???xor???si,si
???call???PaletteGenProc
???mov???ax,1012h ;and set it
???mov???cl,255
???xor???dx,dx
???int???10h???
Render:???xor ???di, di
???mov???si,buffer
???mov???cx,16000
???rep???movsw??????;copy the buffer to screen
???call ???FireProc
???mov???ah,1??????;check if a key is pressed
???int???16h
???jz???Render??????;if not, jump to Render
???
???mov???ax,3h
???int???10h??????;set textmode 80*25
???ret?????????; short way to return to DOS from a COM
???
PaletteGenProc
???mov???cl,64
???xor???ax,ax
Paloop:???mov???[es:si],al
???add???al,bl
???add???si,3
???loop???Paloop
???ret
FireProc
???mov???cx,320
???mov???di, buffer+34560-320???;beginning of the bottom line
???mov???ax,[seed]
???mov???bl,ah
@@1:???mul???si?????????;generate "random" number
???inc???ax
???cmp???al,32??????;also try 64
???jnb???@@2
???mov???bl,ah
@@2:???mov???[di],bl
???mov???[di-320],bl
???inc???di
???loop???@@1
???mov???[seed],ax
???mov???di,buffer
???xor???ax,ax
???xor???dx,dx
???mov???cx,34560
;in this loop, the colors are smoothed and moved one pixel up
@@3:???mov???al,[di+640]
???mov???dl,[di]
???add???ax,dx
???mov???dl,[di+1+320]
???add???ax,dx
???mov???dl,[di-1+320]
???add???ax,dx
???shr???ax,2
???jz???@@4
???dec???ax???;the flames must be darker at the top
@@4:???mov???[di],al
???inc???di
???loop???@@3
ret
??????
seed???dw???5??????;seed for the random-generator
buffer:???times 34560 db 0
http://www.programmingtutorials.com/tutorial.asp?id=Asm
There actually isn't much to assembly. The trouble comes from interfacing with the operating system. Also, different assemblers have idiosyncratic add-ons that are meant to help the experienced programmer, and these can cause considerable confusion.
The best teacher, IMO, is other people's code and Intel's own documentation. Unfortunately, the best little programming examples in assembly were written a long time ago in assembers that aren't as popular anymore. Today, NASM is the drug of choice. In the past, professionals used MASM and hackers used TASM. Even so, if you start with NASM examples, then branch into cool little TASM programs on simtel.net, you'll learn a lot.
If you have an Intel machine, you'll want this:
http://www.baldwin.cx/386htm/toc.htm
To get you started with a NASM example, here is an early version of something I wrote for an assembly tutorial a while ago (sorry, I couldn't find the final, neater version). Get NASM; have the docs close by; Ralf Brown's interrupt list (www.ctyme.com/intr/int.htm); the Instruction set above; and go crazy. You won't understand the algorithm, but you will like the result. This assumes you are generating a COM file in some kind of Microsoft environment.
org 0x0100
???mov???ax,13h
???int???10h
???
???mov dx, 03d4h ;this chunk modifies the VGA to be 320x100???
???mov al, 09h
???out dx, al
???inc dx ???
???mov al, 03h
???out dx,al
???
???
???mov ax, 0a000h
???mov es, ax
???
???mov al, 63
???mov ch,3
???mov di, 64*3
???rep stosb
???mov???si,2+63*3
???xor???ax,ax
???
???call???PaletteGenProc
???inc???bx
???call???PaletteGenProc
???mov???si,1+63*3
???call???PaletteGenProc
???
???xor???si,si
???call???PaletteGenProc
???mov???ax,1012h ;and set it
???mov???cl,255
???xor???dx,dx
???int???10h???
Render:???xor ???di, di
???mov???si,buffer
???mov???cx,16000
???rep???movsw??????;copy the buffer to screen
???call ???FireProc
???mov???ah,1??????;check if a key is pressed
???int???16h
???jz???Render??????;if not, jump to Render
???
???mov???ax,3h
???int???10h??????;set textmode 80*25
???ret?????????; short way to return to DOS from a COM
???
PaletteGenProc
???mov???cl,64
???xor???ax,ax
Paloop:???mov???[es:si],al
???add???al,bl
???add???si,3
???loop???Paloop
???ret
FireProc
???mov???cx,320
???mov???di, buffer+34560-320???;beginning of the bottom line
???mov???ax,[seed]
???mov???bl,ah
@@1:???mul???si?????????;generate "random" number
???inc???ax
???cmp???al,32??????;also try 64
???jnb???@@2
???mov???bl,ah
@@2:???mov???[di],bl
???mov???[di-320],bl
???inc???di
???loop???@@1
???mov???[seed],ax
???mov???di,buffer
???xor???ax,ax
???xor???dx,dx
???mov???cx,34560
;in this loop, the colors are smoothed and moved one pixel up
@@3:???mov???al,[di+640]
???mov???dl,[di]
???add???ax,dx
???mov???dl,[di+1+320]
???add???ax,dx
???mov???dl,[di-1+320]
???add???ax,dx
???shr???ax,2
???jz???@@4
???dec???ax???;the flames must be darker at the top
@@4:???mov???[di],al
???inc???di
???loop???@@3
ret
??????
seed???dw???5??????;seed for the random-generator
buffer:???times 34560 db 0
Re:assembly tutorials
thanx. what i guess i'm trying to accomplish is learning assembly so that i can write a boot loader? i won't give my dramatic story of y i want to write an operating system, but i'v been looking around and have found some write a boot loader in asm, then the os in c/c++? correct me if i'm wrong, please. so i guess my point being is is there a tut out there that helps explain that? btw, would it be crazxy on my part to write the whole thing in assembly? is it impossible or just highly unlikely?
thank u.
P.S. i do have an intermediate level prior programming knowledge.
thank u.
P.S. i do have an intermediate level prior programming knowledge.
Re:assembly tutorials
Wouldn't change my recommendation. The way to learn assembly is to step through code, one line at a time, looking up the Instructions and figuring out how they are used. Even going through a small example like I gave will make you fairly conversant in the language. Of course, less dramatic examples might make an easier introduction. I just don't know of any offhand.
Actually, writing much of your os in assembly would be easier, or at least easier to design and debug. However, once you get to designing data structures and algorithms for the abstractions that the OS represents, and less into interfacing with the hardware, assembly would become pretty unwieldy.
However, you would then gain a newfound appreciation for why C was devised in the first place. That is, it is not so terribly different than assembly, but it certainly can make programming and maintenance more productive.
As for C++, you probably don't need the extra abstractions until you need the extra abstractions. That is, don't code for a problem which may not exist.
Actually, writing much of your os in assembly would be easier, or at least easier to design and debug. However, once you get to designing data structures and algorithms for the abstractions that the OS represents, and less into interfacing with the hardware, assembly would become pretty unwieldy.
However, you would then gain a newfound appreciation for why C was devised in the first place. That is, it is not so terribly different than assembly, but it certainly can make programming and maintenance more productive.
As for C++, you probably don't need the extra abstractions until you need the extra abstractions. That is, don't code for a problem which may not exist.
Re:assembly tutorials
Get the "16-bit/DOS version" of The Art of Assembly:
http://webster.cs.ucr.edu/
You probably won't find the whole book useful, but the first 4-5 chapters are good.
K.J.
http://webster.cs.ucr.edu/
You probably won't find the whole book useful, but the first 4-5 chapters are good.
K.J.
Re:assembly tutorials
Why don't you use one of the already existing bootloaders instead writing your own? It will take you much time to write your own one.Hawk wrote: thanx. what i guess i'm trying to accomplish is learning assembly so that i can write a boot loader? i won't give my dramatic story of y i want to write an operating system, but i'v been looking around and have found some write a boot loader in asm, then the os in c/c++? correct me if i'm wrong, please. so i guess my point being is is there a tut out there that helps explain that? btw, would it be crazxy on my part to write the whole thing in assembly? is it impossible or just highly unlikely?
thank u.
P.S. i do have an intermediate level prior programming knowledge.
Re:assembly tutorials
I agree with Poincar?. Unless you really want to learn assembly, it's not worth doing so just to write a boot loader. To write a boot loader from scratch involves learning a load of obscure techniques (e.g. programming the BIOS and gating A20)which you won't need to use again.