;FILENAME: UNIT2.TXT ; ; ASSEMBLY LANGUAGE COURSE, UNIT 2 ; By Don Stoner Revision: 2008.06.17 ; ; WARNING: Assembly language programs, ; can do absolutely anything! As you ; progress through these units, YOU ; *WILL* CRASH YOUR HARD DRIVE. ; Make sure that there is ABSOLUTELY ; NOTHING on your computer that you ; can't afford to loose! ; ; To save time, you should create a ; "batch file" titled MAKE.BAT: ; (ted make.bat) which first tells ; the computer to edit a file, then ; to assemble it: ; ; ted %1.txt ; nasn -o%1.com %1.txt ; ; To use it, just type: ; ; MAKE UNIT2 ; ; at the FreeDOS command prompt. This ; will first put you in the editor to ; make any changes you want, then it ; will assemble your file. If there ; were any errors which need fixing, ; just type "make unit2" again. If ; there weren't any errors, type: ; ; UNIT2 ; ; at the command prompt to run your ; program. Like before, we start with ; the ORG "pseudo op": ;tell NASM to ORG 100h ;put the code ;at 100h (256) ; Next, the first line of real code: MOV AL,41h ;ASCII "A" ; This is a "move" instruction. It ; tells the computer to put a 41h (65 ; decimal) into one of the registers in ; the computer. That register is the ; one named "AL" (the "low" byte of the ; two-byte "AX" register). There are ; several different registers in the ; computer which all have different ; purposes. The number 65 (41h), in the ; operand, happens to be the ASCII code ; for the capital letter "A". ("ASCII" ; stands for American Stardard Code for ; Information Interchange). ; ; The next line of code: MOV AH,0Eh ;select "output" ; is very similar to the previous one. ; It loads a 14 (0Eh) into the register ; named AH ("high" byte of the two-byte ; "AX" register). The "14" is not an ; ASCII code for a letter, instead it ; will be used, below, to tell the ; computer's BIOS code which one of a ; family of different BIOS routines we ; are going to want to use. ("BIOS" ; stands for Basic Input/Output System) ; 14 (0Eh) happens to be the code to ; output a letter (the ASCII "A" in the ; AL register) to the monitor. ; ; Next: MOV BL,0 ;select page and MOV BH,0 ;graphics color ; these two instructions are sometimes ; necessary to make the "A" display ; correctly. We won't be worrying about ; what they mean until later on. ; ; And: INT 10h ; Like the "INT 20h" (exit to FreeDOS) ; command, INT 10h executes one of the ; routines identified by the table of ; addresses at the bottom of memory. ; "Interrupt" 16 (10h) is the 16th ; entry in the table; it was set up by ; the BIOS ROM which is part of the ; computer's "motherboard" instead of ; by the operating system (FreeDOS). ; ; Interrupt 16 (10h), function 14 (0Eh) ; tells the BIOS routine to write the ; contents of register AL (which we ; loaded with an ASCII "A") onto the ; computer's monitor. This time, when ; you run the program, it should put ; an "A" on the monitor before it ; returns to the operating system. ; ; Can you guess how to display a "B"? ; ; This may seem like a whole lot of ; work for not getting very much done, ; but, as you will see, it gets much ; easier. We only have to do each ; thing the hard way once; after that ; we can just reuse it. ; ; And finally, like before, we exit: INT 20h ;back to FreeDOS ; See how much simpler this exit ; command looks this time than it did ; last time?