;FILENAME: UNIT8.TXT ; ; ASSEMBLY LANGUAGE COURSE, UNIT 8 ; By Don Stoner Revision: 2008.06.25 ; ORG 100h ; Code Starts at 100h ; ; This program uses a pointer ; (in register SI) to access ; and display the part of the ; memory where this program is ; loaded. First, we cue the SI ; register to the beginning of ; the program (100h). ; MOV SI,100h ;LOAD SI WITH 100h ; ; Next we Load the DL register ; with the number of bytes of ; code to display. We calculate ; this by subtracting the start ; address (100h) from the end ; address (labeled below). ; MOV DL,END_ADDRESS-100h ; NEXT_BYTE_LOOP: ; Loop back here to ; output the next byte ; ; This instruction loads the AL ; register from the memory ; location pointed to by the SI ; register. This is called ; "indirect addressing." ; ; Load AL [indirectly] MOV AL,[SI] ; from memory INC SI ; Cue SI to the next ; next memory location. ; Output the byte (from AL) in CALL HEX_OUT ;Hexadecimal CALL SPACE_OUT ;& Print a space ; ; Next we decriment the byte ; counter (in DL) to see if ; there are more bytes to print ; DEC DL ; One less byte. ; ; Loop back and print ; ; another byte until ; ; the DL count becomes JNZ NEXT_BYTE_LOOP ; = to 0 ; ; Then we're done. ; INT 20h ;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 ; This is to mark the end of the code ; for the byte count: END_ADDRESS: