Created
January 4, 2012 16:53
-
-
Save andrewrcollins/1560940 to your computer and use it in GitHub Desktop.
#TJHSST ~ Misc assembly programs from "Computer Architecture" class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;-----------------------------------------------------------------------; | |
; XLAT and XLATB ; | |
; What are they? ; | |
;-----------------------------------------------------------------------; | |
.MODEL SMALL | |
.STACK ; Allocate space for a stack, 1K | |
.DATA | |
DIGIT_TABLE DB '0123456789ABCDEF' ; Hex digit table | |
JUMP_TABLE DB 1 ; Table of jumps, array of pointers | |
DB 9 ; They folow the sequence | |
DB 3 ; 1,2,3,4,5,6,7,8,9,0,1,2,... | |
DB 7 | |
DB 5 | |
DB 4 | |
DB 6 | |
DB 8 | |
DB 2 | |
DB 8 | |
.CODE | |
;-----------------------------------------------------------------------; | |
; WRITE_HEX_DIGIT ; | |
; Entry: DL Hex digit to print out ; | |
; Effect: Prints out the digit ; | |
; Return: Nothing ; | |
;-----------------------------------------------------------------------; | |
WRITE_HEX_DIGIT PROC | |
PUSH AX ; Save AX and BX | |
PUSH BX | |
MOV AL,DL ; Make DL an address into a table | |
MOV BX,OFFSET DIGIT_TABLE ; Set DS:BX up for the XLAT | |
XLATB ; Load character into AL | |
MOV DL,AL ; Restore DL | |
MOV AH,2h ; Print character function | |
INT 21h | |
POP BX ; Restore BX and AX | |
POP AX | |
RET | |
WRITE_HEX_DIGIT ENDP | |
;-----------------------------------------------------------------------; | |
START_HERE: | |
MOV AX,@DATA | |
MOV DS,AX | |
MOV BX,OFFSET JUMP_TABLE | |
MOV AL,0 | |
MOV CX,70 | |
;-----------------------------------------------------------------------; | |
POINTER_LOOP: ; Loop the print out procedure | |
XLATB | |
MOV DL,AL | |
CALL WRITE_HEX_DIGIT ; Actually print out the hex digit. | |
LOOP POINTER_LOOP | |
;-----------------------------------------------------------------------; | |
MOV AH,04Ch | |
INT 21h | |
END START_HERE | |
;-----------------------------------------------------------------------; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;-----------------------------------------------------------------------; | |
; XLAT and XLATB ; | |
; What are they? ; | |
; Part II ; | |
;-----------------------------------------------------------------------; | |
.MODEL SMALL | |
.STACK ; Allocate space for a stack, 1K | |
.DATA | |
GREETINGS DB 'Enter a number from 1 to 5, 0 quits',13,10,'$' | |
BASE_STR DB 'Function # ','$' | |
END_STR DB 13,10,'$' | |
NUMBERS DB '0123456789' | |
JUMP_TABLE DB OFFSET FUNCTION0 ; The table of jumps | |
DB OFFSET FUNCTION1 | |
DB OFFSET FUNCTION2 | |
DB OFFSET FUNCTION3 | |
DB OFFSET FUNCTION4 | |
DB OFFSET FUNCTION5 | |
.CODE | |
;-----------------------------------------------------------------------; | |
; WRITE_DIGIT ; | |
; Entry: DL Decimal digit to print in range '0'...'9' ; | |
; Effect: Prints out the digit ; | |
; Return: Nothing ; | |
;-----------------------------------------------------------------------; | |
WRITE_DIGIT PROC | |
PUSH AX ; Save AX and BX | |
PUSH BX | |
MOV AL,DL ; Make DL an address into a table | |
MOV BX,OFFSET NUMBERS ; Set DS:BX up for the XLAT | |
XLATB ; Load character into AL | |
MOV DL,AL ; Restore DL | |
MOV AH,2h ; Print character function | |
INT 21h | |
POP BX ; Restore BX and AX | |
POP AX | |
RET | |
WRITE_DIGIT ENDP | |
;-----------------------------------------------------------------------; | |
; WRITE_STR ; | |
; Entry: DL Number to print out in the string ; | |
; Effect: Prints out the function header and number ; | |
; Return: Nothing ; | |
;-----------------------------------------------------------------------; | |
WRITE_STR PROC | |
PUSH AX | |
PUSH DX | |
MOV AH,9h ; Print string function | |
MOV DX,OFFSET BASE_STR ; Print out the Function # part | |
INT 21h | |
POP DX | |
CALL WRITE_DIGIT ; Write the digit | |
PUSH DX | |
MOV DX,OFFSET END_STR ; Print out CR,LF sequence | |
INT 21h | |
POP DX | |
POP AX | |
RET | |
WRITE_STR ENDP | |
;-----------------------------------------------------------------------; | |
; Group of functions ; | |
FUNCTION0 PROC | |
MOV AH,04Ch ; Exit program gracefully | |
INT 21h | |
FUNCTION0 ENDP | |
FUNCTION1 PROC | |
MOV DL,1 | |
RET | |
FUNCTION1 ENDP | |
FUNCTION2 PROC | |
MOV DL,2 | |
RET | |
FUNCTION2 ENDP | |
FUNCTION3 PROC | |
MOV DL,3 | |
RET | |
FUNCTION3 ENDP | |
FUNCTION4 PROC | |
MOV DL,4 | |
RET | |
FUNCTION4 ENDP | |
FUNCTION5 PROC | |
MOV DL,5 | |
RET | |
FUNCTION5 ENDP | |
;-----------------------------------------------------------------------; | |
; The main part of the program ; | |
START_HERE: | |
MOV AX,@DATA ; Have to do this first | |
MOV DS,AX | |
LOOP_BEGIN: | |
MOV AH,9h ; Print string function | |
MOV DX,OFFSET GREETINGS | |
INT 21h | |
MOV AH,7h ; Get character | |
INT 21h | |
SUB AL,'0' ; Convert AL into decimal value | |
MOV BX,OFFSET JUMP_TABLE ; Prepare for XLATB | |
XLATB ; Get table value | |
XOR AH,AH ; Clear out all of AH | |
CALL AX ; Call the function | |
CALL WRITE_STR ; Display message | |
JMP LOOP_BEGIN | |
END START_HERE | |
; The end of the program ; | |
;-----------------------------------------------------------------------; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;-----------------------------------------------------------------------; | |
; XLAT and XLATB ; | |
; What are they? ; | |
; Part III ; | |
;-----------------------------------------------------------------------; | |
.MODEL TINY | |
.CODE | |
JMP START_HERE ; Jump to beginning of program | |
MY_DATA: ; Give label for a data area | |
GREETINGS DB 'Enter a number from 1 to 5, 0 quits',13,10,'$' | |
BASE_STR DB 'Function # ','$' | |
END_STR DB 13,10,'$' | |
NUMBERS DB '0123456789' | |
JUMP_TABLE DB OFFSET FUNCTION0 ; The table of jumps | |
DB OFFSET FUNCTION1 | |
DB OFFSET FUNCTION2 | |
DB OFFSET FUNCTION3 | |
DB OFFSET FUNCTION4 | |
DB OFFSET FUNCTION5 | |
MY_STACK DW 32 DUP(?) ; Make space for a stack | |
;-----------------------------------------------------------------------; | |
; WRITE_DIGIT ; | |
; Entry: DL Decimal digit to print in range '0'...'9' ; | |
; Effect: Prints out the digit ; | |
; Return: Nothing ; | |
;-----------------------------------------------------------------------; | |
WRITE_DIGIT PROC | |
PUSH AX ; Save AX and BX | |
PUSH BX | |
MOV AL,DL ; Make DL an address into a table | |
MOV BX,OFFSET NUMBERS ; Set DS:BX up for the XLAT | |
XLATB ; Load character into AL | |
MOV DL,AL ; Restore DL | |
MOV AH,2h ; Print character function | |
INT 21h | |
POP BX ; Restore BX and AX | |
POP AX | |
RET | |
WRITE_DIGIT ENDP | |
;-----------------------------------------------------------------------; | |
; WRITE_STR ; | |
; Entry: DL Number to print out in the string ; | |
; Effect: Prints out the function header and number ; | |
; Return: Nothing ; | |
;-----------------------------------------------------------------------; | |
WRITE_STR PROC | |
PUSH AX | |
PUSH DX | |
MOV AH,9h ; Print string function | |
MOV DX,OFFSET BASE_STR ; Print out the Function # part | |
INT 21h | |
POP DX | |
CALL WRITE_DIGIT ; Write the digit | |
PUSH DX | |
MOV DX,OFFSET END_STR ; Print out CR,LF sequence | |
INT 21h | |
POP DX | |
POP AX | |
RET | |
WRITE_STR ENDP | |
;-----------------------------------------------------------------------; | |
; Group of functions ; | |
FUNCTION0 PROC | |
MOV AH,04Ch ; Exit program gracefully | |
INT 21h | |
FUNCTION0 ENDP | |
FUNCTION1 PROC | |
MOV DL,1 | |
RET | |
FUNCTION1 ENDP | |
FUNCTION2 PROC | |
MOV DL,2 | |
RET | |
FUNCTION2 ENDP | |
FUNCTION3 PROC | |
MOV DL,3 | |
RET | |
FUNCTION3 ENDP | |
FUNCTION4 PROC | |
MOV DL,4 | |
RET | |
FUNCTION4 ENDP | |
FUNCTION5 PROC | |
MOV DL,5 | |
RET | |
FUNCTION5 ENDP | |
;-----------------------------------------------------------------------; | |
; The main part of the program ; | |
START_HERE: | |
MOV AX,@CODE ; Have to do this first | |
MOV DS,AX | |
MOV AX,OFFSET MY_STACK | |
MOV SS,AX | |
LOOP_BEGIN: | |
MOV AH,9h ; Print string function | |
MOV DX,OFFSET GREETINGS | |
INT 21h | |
MOV AH,7h ; Get character | |
INT 21h | |
SUB AL,'0' ; Convert AL into decimal value | |
MOV BX,OFFSET JUMP_TABLE ; Prepare for XLATB | |
XLATB ; Get table value | |
XOR AH,AH ; Clear out all of AH | |
CALL AX ; Call the function | |
CALL WRITE_STR ; Display message | |
JMP LOOP_BEGIN | |
END START_HERE | |
; The end of the program ; | |
;-----------------------------------------------------------------------; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set of assembler programs found on old 5.25 floppy disks from when I was a huge nerd at Thomas Jefferson High School for Science and Technology in the computer systems lab between 1988 and 1992.
It appears to be work for my "Computer Architecture" class.
Anyone can do whatever they'd like to with them--if anything.
And, yes, I remain a crushingly huge nerd.