;FILENAME: UNIT1.TXT ; ; ASSEMBLY LANGUAGE COURSE, UNIT 1 ; By Don Stoner Revision: 2008.06.21 ; ; WARNING: Assembly language programs, ; like the ones you are going to be ; experimenting with here, can do ; absolutely anything! Eventually, as ; you progress through these units, ; YOU *WILL* CRASH the HARD DRIVE OF ; THE COMPUTER YOU ARE USING! Make sure ; that there is ABSOLUTELY NOTHING on ; that computer that you can't afford ; to loose! In fact, having a dedicated ; computer would be a very good idea. ; ; First thing, all lines that start ; with a simicolon (like these here) ; are merely comments. Since assembly ; language is somewhat cryptic, it is ; very important to explain what the ; code you write does and how it works. ; Otherwise, it will be very difficult ; to figure it all out again if you ; have to use the same code later. ; ; It is assumed that you will be using ; the Tiny Editor (TED) to write your ; code, the Netwide Assembler (NASM) to ; assemble it (convert it from text ; files like this one into executable ; machine language files), and that you ; will be running FreeDOS (a free REAL- ; MODE opreating system). All of these ; are free and should be installed on ; your computer. ; ; To edit this file, type: ; ; TED UNIT1.TXT ; ; at the FreeDOS command prompt. You ; will learn best by experimenting, ; so please try changing anything ; you are curious about. Make mistakes! ; To see what your changes have done, ; you need to assemble and run your ; program. To do this, first type: ; ; NASM -ounit.com unit1.txt ; ; at the command prompt. If there are ; errors, the assembler will tell you ; which line numbers contain mistakes ; and also give some rather cryptic ; clues regarding what is wrong. If ; there were no errors, then type: ; ; UNIT1 ; ; to run your program. Now we are ; ready for some code: ;(You can put ORG 100h ;comments over ;here too.) ; This first command tells NASM (the ; assembler) at which address to start ; the code it generates. "ORG" means ; point of origin. 100h is the point ; of origin NASM will use. The "h" ; in 100h means the number is written ; in hexadecimal (base 16, hereafter ; "hex") instead of in normal necimal ; numbers. The hex digits are: 0, 1, ; 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, ; E, and F (for 0-15 respectively). ; 10H means 16 and 100h means 16 x 16 ; or 256. Memory offset 256 (100h) is ; where FreeDOS is going to load this ; program (it always loads it in the ; same place) and NASM will sometimes ; need to know this to translate your ; assembly code into machine language. ; ; The ORG command is calles a pseudo- ; op (as opposed to a real operation) ; It doesn't generate any code; it ; just tells the assembler where to ; put any code that it does generate. ; ; Next: INT 20h ; This command really does generate ; some code; specifically, it makes ; two bytes of code. The first byte ; (it will be 0CDh, the leading zero ; is to identify it as a number instead ; of a mispelled word) is called the ; "operation code" (hereafter "op ; code"). It tells the computer what ; to do. In this case, the op code ; tells the computer to perform an ; "interrupt" - more specifically, ; interrupt number 32 (20h - which is ; the second byte of the instruction, ; called the operand). Interupt 20h has ; already been set up for us by the ; operating system (FreeDOS); all we ; have to do is use it. ; ; The INT 20h instruction causes the ; computer to jump to the 32nd (20h) ; entry in a table of 256 addresses ; which is stored at the bottom of the ; computer's memory. The 32nd address ; sends the computer to a routine in ; the FreeDOS operating system which ; will transfer control back to ; FreeDOS from our program. ; ; That's right; this two-byte program ; doesn't do anything except end ; itself!