;FILENAME: UNIT7.TXT ; ; ASSEMBLY LANGUAGE COURSE, UNIT 7 ; By Don Stoner Revision: 2008.06.25 ; ; WARNING: Assembly language programs, ; can do absolutely anything! ; Eventually, 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! ; ; To edit, assemblem and test, type: ; ; MAKE UNIT7 ; UNIT7 ; ; Code Starts at 100h ; ORG 100h ; ; This time we echo the typed ; keys in both ASCII and "hex." ; To make things easier, we'll ; make subroutines for "HEX" ; output, for "Space," and for ; "Carriage return." ; ; Tell NASM where to loop back: ; LOOP_BACK_TO_HERE: ; ; First, we read a key into AL ; CALL ASCII_IN ; ; We won't bother saving AL; ; we'll have the subroutines ; take care of that. ; ; Next, we echo it in ASCII: ; CALL ASCII_OUT ;AL out ; CALL SPACE_OUT ;Output a space ; CALL HEX_OUT ;in Hexadecimal ; CALL CRLF_OUT ;And output a ; ;Carriage Return ; ;and a Line Feed ; ; Finally, we either loop back, ; or exit. ; CMP AL,"x" ;Loop if "x" JNE LOOP_BACK_TO_HERE INT 20h ;Else, back to DOS ; End of Main code ;-------------------------------------- ; Subroutines: ; ; Output a Space ; ; (PUSH and POP commands "save data on" ; and "restore data from" the "stack." ; SPACE_OUT: PUSH AX ;save AL (and AH) MOV AL," " ;output an " " CALL ASCII_OUT ;ASCII space POP AX ;restore AL (and AH) RET ; ; Output a "Carriage Return" and a ; "Line Feed" ; CRLF_OUT: PUSH AX ;save AL (and AH) MOV AL,13 ;output a C.R. CALL ASCII_OUT MOV AL,10 ;output a L.F. CALL ASCII_OUT POP AX ;restore AL (and AH) RET ; ; Output AL in Hexadecimal ; HEX_OUT: PUSH AX ;save AL (and AH) SHR AL,4 ;step 1: MSN -> LSN CALL LSN_OUT ;LSN (MSN) out POP AX ;restore AL (and AH) LSN_OUT: PUSH AX ;save AL (and AH) AND AL,0FH ;step 2 OR AL,"0" ;step 3 CMP AL,":" ;step 4 JC HEXOK2 ;step 4 ADD AL,"A"-":" ;step 4 HEXOK2: CALL ASCII_OUT ;step 5 POP AX ;restore AL (and AH) RET ; ; Output AL in ASCII ; 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 ; ; Input AL in ASCII ; ASCII_IN: MOV AH,0 ;normal keyboard INT 16H ;key into AL RET ;return to main code