Sunday, July 24, 2011
Assembly Language Textbook
Introduction to 64 Bit Intel Assembly Language Programming
I have written the first version of my 64 bit Assembly Language text book for Intel and AMD CPUs. I will be teaching from the textbook this fall (2011) and by that time I will have slides for the book, errata and code at my web site at seyfarth.tv/asm.
The web site is not very functional today. I have replaced my main computer with a new Core i7 computer which I have used for testing code for the text book. The web site needs a little work...
I managed to get 20.5 GFLOPS on my double precision correlation computation which is a testament to the design of the Core i series. I used the AVX instructions which allow me to specify instructions which can perform 4 double precision operations at a time. These operations take more than 1 cycle, so it is a little surprising to me to achieve about 6 double precision results per cycle. The CPU is performing out-of-order execution pretty nicely. I did make some effort to make a lot of the instructions within the main loop independent of each other to allow the CPU to do its job, but given the complexity of x86-64 instruction decoding I find it to be pretty impressive.
The AVX instructions were nice. Finally there are 16 fully general purpose floating point registers which can be used as scalar or vector registers in an orthogonal syntax. If the CPU makers were to prepare another set of similar integer registers and instructions, it would tickle my fancy.
The primary goal of the text book is to teach people how a compiler like C or C++ works through learning to write C compatible programs and functions. I believe that the 64 bit environment is a little easier to write assembly for the the 32 bit one (and much easier than the 16 bit one). I have tried as much as possible to ignore the antiquities of the 16 bit instruction set. There are some extant features like using the rcx register as a count register for the repeat instructions. These instructions also use the rsi register as the source index and the rdi register as the destination index.
I have ignored the segment registers. It is an interesting part of computer history that you once could use the cs (code segment), ss (stack segment), ds (data segment) and es (extra segment) registers to overcome the fundamental problem of 16 bit addressing. It makes no difference to 64 bit programming, though the registers still exist and some use could be made of fs and gs.
My book focuses on using the yasm assembler and the the gdb debugger under Linux. I have made a few comments about the differences between function calls between Windows and Linux, but WIndows and Mac OS/X have not received much attention. I haven't tried using the same code under Mac OS/X, but from what I have read the function call semantics are identical, so there is basically some hope of success.
Linux programs start with _start which is probably not true for Windows and Mac. C and C++ programs start with main. It is possible that an underscore prefix might be used on another system, but I expect that my assembly programs which use main as the main function and use the C library would be portable to the Mac quite easily and not too hard to port to Windows. Perhaps a little later I will experiment with WIndows or Mac OS/X, but current goals are preparing Kindle and Nook versions of the book and preparing slides for teaching the course. At this point I have 2 chapters done on the slides and expect success there.
I tried conversion of my Latex-generated PDF file with mostly useless results as a possible Kindle book. A PDF document is basically page layout while a Kindle document is a markup document description language like HTML. The htlatex command converts most of the book quite nicely to HTML, though I need to learn something about bypassing htlatex's \incudegraphics (or how to use it). Then I should be off to the races on a Kindle book. I hope to get this done real soon now. I would prefer to give my students a cheaper option for a book this fall.
Downstream a little further I wish to follow up on an excellent suggestion by my friend, Dr. Michael Scott of Dublin City University, to prepare some lectures to have available for free. This sounds pretty sensible and I will try to post some videos on youtube, though not for several weeks...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment