;FILENAME: UNIT4.TXT ; ; ASSEMBLY LANGUAGE COURSE, UNIT 4 ; 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 UNIT4 ; ; To run, type: ; ; UNIT4 ; ; Code Starts Here: ORG 100h ;code at 100h ; Next, the real code: ; This time we'll output four ; letters - but we'll get them ; from the keyboard instead of ; putting them directly into ; the code: ; INPUT A KEYSTROKE USING THE ; BIOS INTERRUPT: MOV AH,0 ;the 0 code tells ;the BIOS routine ;which keyboard ;system to use INT 16H ;Use interrupt ;number 16h (22) ;to read a key into ;the AL register ;NOW OUTPUT THAT SAME KEY CALL ASCII_OUT ; DO THE SAME THING AGAIN ; FOR THE SECOND KEY MOV AH,0 INT 16H ;READ A KEY CALL ASCII_OUT ;AND ECHO IT ; THIRD KEY: BUT HERE WE'LL ; MAKE A SUBROUTINE (BELOW) ; FOR THE INPUTS AS WELL AS ; FOR THE OUTPUTS: CALL ASCII_IN ;KEY FROM SUB. CALL ASCII_OUT ;AND ECHO IT ;AND ONE MORE KEY: CALL ASCII_IN ;read a key ; BUT, JUST FOR FUN, THIS TIME ; WE'LL CHANGE THE CODE BEFORE ; WE OUTPUT IT: INC AL ;THIS "INCRIMENTS" ;(ADDS ONE TO) AL ; NOW OUTPUT THE CHANGED CODE: CALL ASCII_OUT ; and of course, INT 20h ;back to DOS ; end of main program ;-------------------------------------- ; Subroutines: ; Subroutine to output an ASCII ; character from AL to the monitor: ; ASCII_OUT: MOV AH,0Eh ;select "output" MOV BL,0 ;select page and MOV BH,0 ;graphics color INT 10h ;BIOS routines RET ;return to main code ; ; New subroutine to input an ASCII ; character from the keyboard into AL: ; ASCII_IN: MOV AH,0 ;use normal ;keyboard system ;BIOS routine to INT 16H ;read a key into ;the AL register RET ;return to main code ; And this is the end of the code