Created
August 27, 2013 16:53
-
-
Save hjpotter92/6356116 to your computer and use it in GitHub Desktop.
2013-08-26: Systems programming lab assignment.
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
TITLE Lab05: Read array of integers and display recurring elements | |
.MODEL SMALL | |
.STACK 100H | |
.DATA | |
CR EQU 13 | |
LF EQU 10 | |
ARR DW 200 DUP(?) | |
N DW 0 | |
HALF DW 0 | |
SEP DB ", $" | |
LIM DB 10, 13, "How many elements? $" | |
START_STMT DB 10, 13, "Input array element: $" | |
OUT_STMT DB 10, 13, 10, 13, "Output: $" | |
NON_NUM DB 10, 13, "Non integer input detected.$" | |
.CODE | |
MAIN PROC | |
MOV AX, @DATA | |
MOV DS, AX | |
XOR CX, CX | |
LEA DX, LIM | |
LEA SI, N | |
MOV AH, 9 | |
INT 21H | |
CALL INDEC | |
MOV CX, AX | |
MOV [SI], CX | |
MOV BX, 2 | |
XOR DX, DX | |
DIV BX | |
LEA DI, HALF | |
MOV [DI], AX | |
LEA SI, ARR | |
READ_INP: | |
LEA DX, START_STMT | |
MOV AH, 9 | |
INT 21H | |
CALL INDEC | |
MOV [SI], AX | |
ADD SI, 2 | |
LOOP READ_INP | |
LEA DI, HALF | |
MOV DX, [DI] | |
LEA SI, ARR | |
LEA DI, N | |
MOV CX, [DI] | |
TO_END: | |
MOV AX, [SI] | |
CALL COUNTING | |
DEC CX | |
CMP BX, DX | |
JGE FOUND | |
ADD SI, 2 | |
CMP CX, 0 | |
JNLE TO_END | |
JMP LEAVING | |
FOUND: | |
LEA DX, OUT_STMT | |
PUSH AX | |
MOV AH, 9 | |
INT 21H | |
POP AX | |
CALL NEWLINE | |
CALL OUTDEC | |
ADD SI, 2 | |
JMP TO_END | |
LEAVING: | |
MOV AH, 76 | |
INT 21H | |
MAIN ENDP | |
COUNTING PROC | |
;; Input: | |
;; SI => current array index | |
;; AX => element to count | |
;; CX => size of array | |
;; Output: | |
;; BX => count of element | |
PUSH AX | |
PUSH CX | |
PUSH SI | |
XOR BX, BX | |
SUB SI, 2 | |
CUSTOM: | |
DEC CX | |
CMP CX, 0 | |
JLE QUITTING | |
ADD SI, 2 | |
CMP AX, [SI] | |
JNE CUSTOM | |
INC BX | |
CMP CX, 0 | |
JNLE CUSTOM | |
QUITTING: | |
POP SI | |
POP CX | |
POP AX | |
RET | |
COUNTING ENDP | |
INCLUDE INDEC.ASM | |
INCLUDE OUTDEC.ASM | |
INCLUDE NEWLINE.ASM | |
END MAIN |
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
INDEC PROC | |
;; Reads a decimal integer | |
;; and stores the value in | |
;; AX. Requires a string | |
;; under .DATA named as | |
;; `NON_NUM` | |
PUSH BX | |
PUSH DX | |
XOR BX, BX | |
XOR AX, AX | |
READ: | |
MOV AH, 1 | |
INT 21H | |
CMP AL, CR | |
JE END_READ | |
CMP AL, LF | |
JE END_READ | |
CMP AL, '0' | |
JNGE NON_INTEGER | |
CMP AL, '9' | |
JNLE NON_INTEGER | |
MY_LOOP: | |
AND AX, 000FH | |
PUSH AX | |
MOV AX, 10 | |
MUL BX | |
POP BX | |
ADD BX, AX | |
JMP READ | |
END_READ: | |
MOV AX, BX | |
POP DX | |
POP BX | |
RET | |
NON_INTEGER: | |
LEA DX, NON_NUM | |
MOV AH, 9 | |
INT 21H | |
JMP READ | |
INDEC ENDP |
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
NEWLINE PROC | |
PUSH AX | |
PUSH DX | |
MOV DL, 0AH | |
MOV AH, 2 | |
INT 21H | |
MOV DL, 0DH | |
INT 21H | |
POP DX | |
POP AX | |
RET | |
NEWLINE ENDP |
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
OUTDEC PROC | |
PUSH AX | |
PUSH BX | |
PUSH CX | |
PUSH DX | |
OR AX, AX | |
JGE QUIT | |
PUSH AX | |
MOV DL, '-' | |
MOV AH, 2 | |
INT 21H | |
POP AX | |
NEG AX | |
QUIT: | |
XOR CX, CX | |
MOV BX, 10 | |
REPEAT: | |
XOR DX, DX | |
DIV BX | |
PUSH DX | |
INC CX | |
CMP AX, 0 | |
JNE REPEAT | |
MOV AH, 2 | |
PRINT: | |
POP DX | |
ADD DL, '0' | |
INT 21H | |
LOOP PRINT | |
POP DX | |
POP CX | |
POP BX | |
POP AX | |
RET | |
OUTDEC ENDP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment