;FILENAME: UNIT3.TXT ; ; ASSEMBLY LANGUAGE COURSE, UNIT 3 ; By Don Stoner Revision: 2008.06.17 ; ; ; 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. ; ; To assemble, type: ; ; MAKE UNIT3 ; ; To run, type: ; ; UNIT3 ; ; Tell NASM where the code goes: ORG 100h ;code at 100h ; Next, the real code: ; This time we'll output four ; letters - and make it look ; easier: ; Output an "A" (same as before) ; MOV AL,41h ;ASCII "A" MOV AH,0Eh ;select "output" MOV BL,0 ;select page and MOV BH,0 ;graphics color INT 10h ;BIOS routines ; Output a "B", but this time ; we'll let the assembler figure ; out the ASCII codes for us: ; MOV AL,"B" ;ASCII "B" MOV AH,0Eh ;select "output" MOV BL,0 ;select page and MOV BH,0 ;graphics color INT 10h ;BIOS routines ; Instead of writing all of the ; details required by the BIOS ; routine over again each time, ; well just move them to a ; subroutine at the bottom of ; this file, which we will name ; "ASCII_OUT" The name is ; arbitrary, we choose it, but ; we do have to spell it the ; same way every time we use ; it; with NASM, we even have ; to make sure we match all ; upper and lower case letters. ; ; But here all we need is the ; command to "call" that ; subroutine: MOV AL,"C" ;Choose a "C" CALL ASCII_OUT ;call subroutine ; Same thing for last letter: MOV AL,"d" ;lowercase "d" CALL ASCII_OUT INT 20h ;back to DOS ; end of main program ;-------------------------------------- ; but ... ; Down here, past the end of the main ; program, where it won't get executed ; at the wrong time, is where we put ; the subroutine: ; This is the label we have chosen. The ; colon at the end helps identify it as ; a label so NASM won't get confused. ASCII_OUT: ; The rest of this is just the routine ; we had copied three times before. We ; don't load the AL register here ; because it contains whatever letter ; we decide to print - and that is ; selected in the main code above MOV AH,0Eh ;select "output" MOV BL,0 ;select page and MOV BH,0 ;graphics color INT 10h ;BIOS routines ; Finally, instead of just falling off ; the end of the world, we have to tell ; the computer to return to just after ; whichever "CALL" instruction sent us ; here: RET ; And this is the end of the code