jhdobbins 0 Junior Poster

can someone help with this issue? Anytime an operation is performed, the output is random characters and/or numbers...

.MODEL TINY
.CODE
ORG	100H

START:	JMP BEGIN

; DEFINED VARIABLES

PORT_A          EQU 140H
PORT_B          EQU 141H
PORT_C          EQU 142H
PORT_CR         EQU 143H

DIR_MODE        EQU 2
OP_MODE         EQU 3

EON     EQU 01000000B
EOFF    EQU 10111111B

RSDATA  EQU 00010000B
RSINSTR EQU 00000000B

RS      DB RSINSTR
HELPMSG DB 'F5 TO TOGLE MODES, F1 FOR HELP,'
        DB 'F10 TO QUIT, ENTER A TWO DIGIT'
        $' ;FINISH LATER
SWITCHB DB ' INPUT MODE: BINARY DIP $ '
SWITCHK DB ' INPUT MODE: KEYBOARD $ '
IN1     DB ' $'
IN2     DB ' $'
INOP    DB ' $ '
ERRMES  DB ' UNKOWN ERROR   $'

; SUB-ROUTINES

SPACE PROC NEAR
        MOV AH, 02H
	MOV DL, 0DH
	INT 21H
	MOV DL, 0AH
	INT 21H
	RET
SPACE ENDP

FKEY PROC NEAR
	CMP AH, 3BH
        JE HELP

        CMP AH, 44H   
        JE EXIT

        CMP AH, 86H
        JE TOGGLE

EXIT:	MOV AH, 4CH
	INT 21H

TOGGLE: LEA DX, SWITCHB
	MOV AH, 09H
	INT 21H
	JMP DIPIN

HELP:	CALL SPACE
	
	PUSH AX
	LEA DX, HELPMSG
	MOV AH, 09H
	INT 21H
	POP AX
	RET
FKEY ENDP   

ERRS PROC NEAR
	LEA DX, ERRMES
	MOV AH, 09H
	INT 21H
	CALL SPACE
	JMP GETNUM
ERRS ENDP
	

PAUSE300US PROC NEAR
        PUSH BX
        MOV BX, 0FFH
LOOP1:  NOP
        DEC BX
        CMP BX, 0
        JNZ LOOP1
        POP BX
        RET
PAUSE300US ENDP

PAUSE3MS PROC NEAR
        PUSH BX
        MOV BX, 00AH

LOOP2:  CALL PAUSE300US
        DEC BX
        CMP BX,0
        JNZ LOOP2
        POP BX
        RET
PAUSE3MS ENDP

PAUSE20MS PROC NEAR
        PUSH BX
        MOV BX, 007H
LOOP3:  CALL PAUSE3MS
        DEC BX
        CMP BX, 0
        JNZ LOOP3
        POP BX
        RET
PAUSE20MS ENDP

OUTPUTNIBBLE PROC NEAR
        PUSH AX
        PUSH DX
        AND  AL, 0FH
        OR   AL, [RS]
        MOV  DX, 140H
        OUT  DX, AL
        CALL PAUSE300US
        OR   AL, EON
        OUT  DX, AL
        CALL PAUSE300US
        CALL PAUSE300US
        AND  AL, EOFF
        OUT  DX, AL
        CALL PAUSE3MS
        POP  DX
        POP  AX
        RET
OUTPUTNIBBLE ENDP

OUTPUTBYTE PROC NEAR
        PUSH AX
        PUSH BX
        PUSH CX
        MOV BL, AL
        MOV CL, 4
        SHR AL, CL
        CALL OUTPUTNIBBLE
        MOV AL, BL
        AND AL, 0FH
        CALL OUTPUTNIBBLE
        POP CX
        POP BX
        POP AX
        RET
OUTPUTBYTE ENDP

LCD_INIT PROC NEAR
        PUSH AX
        MOV AL, 0
        MOV DX, 140H
        OUT DX, AL
        CALL PAUSE20MS
        MOV [RS], RSINSTR
        MOV AL, 00000011B
        CALL OUTPUTNIBBLE
        CALL PAUSE3MS
        CALL PAUSE3MS

        MOV AL, 00000011B
        CALL OUTPUTNIBBLE
        CALL PAUSE300US

        MOV AL, 00000011B
        CALL OUTPUTNIBBLE
        CALL PAUSE300US

        MOV AL, 00000010B
        CALL OUTPUTNIBBLE
        CALL PAUSE3MS

        MOV AL, 00101000B
        CALL OUTPUTBYTE
        CALL PAUSE300US

        MOV AL, 00001111B
        CALL OUTPUTBYTE
        CALL PAUSE300US

        MOV AL, 00000001B
        CALL OUTPUTBYTE
        CALL PAUSE3MS

        MOV AL, 00000110B
        CALL OUTPUTBYTE
        CALL PAUSE300US

        MOV [RS], RSDATA
        POP AX
        RET
LCD_INIT ENDP

LCD_GOTOXY PROC NEAR
        PUSH AX
        PUSH BX
        MOV [RS], RSINSTR
        MOV BL, 0
        CMP AH, 0
        JZ LINE1
        MOV BL,40H
LINE1:  ADD AL, BL
        OR AL, 80H
        CALL OUTPUTBYTE
        MOV [RS], RSDATA
        POP BX
        POP AX
        RET
LCD_GOTOXY ENDP

EXPONENT PROC NEAR
	PUSH CX
	MOV CL, AH
	MOV AH, AL
MULT:	MUL AH
	JO ERT
	DEC CL
	CMP CL, 0
	JNZ MULT
	JMP DONE
ERT:	MOV BL, 12H
DONE:	POP CX
	RET
EXPONENT ENDP	

ASCII2BCD PROC NEAR	;2 ASCII NUM IN AX -> BCD IN AL
        PUSH CX
	SUB AL, 030H
	SUB AL, 030H
        MOV CL, 4
        SHL AH, CL
	OR  AL, AH
        POP  CX
	RET
ASCII2BCD ENDP

BCD2HEX PROC NEAR	;BCD IN AL -> HEX IN AL
	PUSH BX
        PUSH CX
	MOV  BL, AL
	AND  BL, 0FH
        MOV  CL, 4
        SHR  AL, CL
	MOV  BH, 0AH
	MUL  BH
	ADD  AL, BL
        POP  CX
	POP  BX
	RET
BCD2HEX ENDP

BCD2ASCII PROC NEAR	;BCD IN AL -> ASCII IN AX, AH LOST
	PUSH BX
        PUSH CX
	MOV  BL, AL
        MOV  CL, 4
        SHR  AL, CL
	ADD  AL, 030H
	MOV  AH, AL
	MOV  AL, BL
	AND  AL, 0FH
	ADD  AL, 030H
        POP  CX
	POP  BX
	RET
BCD2ASCII ENDP

HEX2BCD PROC NEAR	;HEX IN AL -> BCD IN AL
	PUSH BX
        PUSH CX
	MOV BH, 00H
	MOV BL, 0AH
	DIV BL
        MOV CL, 4
        SHL AL, CL
	OR  AL, BH
        POP CX
	POP BX
	RET
HEX2BCD ENDP

;MAIN PROGRAM

BEGIN:  MOV AX, CS
        MOV DS, AX
        MOV AL, 2
        MOV DX, 143H
        OUT DX, AL
        MOV AL, 0FFH	;INIT
        MOV DX, 140H
        OUT DX, AL
        MOV AL, 3
        MOV DX, 143H
        OUT DX, AL
        CALL LCD_INIT
	MOV BL, 0FH
	MOV AX, 0100H
	CALL LCD_GOTOXY

;KEYBOARD INPUT

GETNUM: LEA DX, SWITCHK
	MOV AH, 09H
	INT 21H 
        MOV CL, 02H
        LEA DX, IN1
        MOV AH, 09H
        INT 21H

GETKEY1:MOV AH, 0H
        INT 16H
                       
        CMP AL, 0H
	JE FKEY1	

	CMP AL, 30H
        JL GETKEY1
	CMP AL, 39H
        JG GETKEY1

        MOV DL, AL
        MOV AH, 02H
        INT 21H
        
        PUSH AX
	DEC CL
        CMP CL, 0H
        JNE GETKEY1

        POP AX
	POP BX
	MOV AH, BL
	CALL ASCII2BCD
	CALL BCD2HEX
        PUSH AX
	JMP GETOP

FKEY1:	CALL FKEY
	CALL SPACE
	JMP GETKEY1
        
GETOP:  LEA DX, INOP
        MOV AH, 09H
        INT 21H

        MOV AH, 0H
	INT 16H

	CMP AL, 0H
        JE FKEYOP

        CMP AL, 2AH
        JE  PUSHOP
        CMP AL, 2FH
        JE  PUSHOP
        CMP AL, 2BH
        JE  PUSHOP
        CMP AL, 2DH
        JE  PUSHOP
        CMP AL, 25H
        JE  PUSHOP
        CMP AL, 5EH
        JE  PUSHOP
	 
        ;ELSE
        JMP GETOP

FKEYOP: CALL FKEY
	CALL SPACE
	JMP GETOP

PUSHOP: MOV DL, AL
        MOV AH, 02H
        INT 21H
        PUSH AX

GETNUM2:MOV CL, 2
        LEA DX, IN2
        MOV AH, 09H
        INT 21H

GETKEY2:MOV AH, 0H
        INT 16H

	CMP AL, 0H
	JE FKEY2

	CMP AL, 30H
        JL GETKEY2
	CMP AL, 39H
        JG GETKEY2
        
	MOV DL, AL
        MOV AH, 02H
        INT 21H
        
        PUSH AX
	DEC CL
        CMP CL, 0H
        JNE GETKEY2
        
	POP AX
	POP BX
	MOV AH, BL
	CALL ASCII2BCD
	CALL BCD2HEX
        PUSH AX
        JMP SOLVE

FKEY2:  CALL FKEY
	CALL SPACE
	JMP GETNUM2

; BINARY INPUT SECTION

DIPIN:	MOV DX, PORT_C
	IN  AL, DX
TOG:	MOV CX, 0FFFH
WAIT1:	NOP
	LOOP WAIT1
	MOV AH, AL
	AND AH, 080H
	MOV BL, AH
	IN  AL, DX
	MOV AH, AL
	AND AH, 080H
	CMP BL, AH
	JE TOG
	AND AL, 00FH
	PUSH AX
TOG2:	MOV CX, 0FFFH
WAIT2:	NOP
	LOOP WAIT2
	MOV AH, AL
	AND AH, 080H
	MOV BL, AH
	IN  AL, DX
	MOV AH, AL
	AND AH, 080H
	CMP BL, AH
	JE TOG2
	AND AL, 00FH
        POP CX    ;HUH?
	MOV AH, CL
        MOV CL, 4
        SHL AH, CL
	OR  AL, AH
	CALL BCD2HEX
	PUSH AX

TOGOP:	MOV CX, 0FFFH
WAITOP:	NOP
	LOOP WAITOP
	MOV AH, AL
	AND AH, 080H
	MOV BL, AH
	IN  AL, DX
	MOV AH, AL
	AND AH, 080H
	CMP BL, AH
	JE  TOGOP
	AND AL, 070H
        MOV CL, 4
        SHR AL, CL
	PUSH AX
	
TOG3:	MOV CX, 0FFFH
WAIT3:	NOP
	LOOP WAIT3
	MOV AH, AL
	AND AH, 080H
	MOV BL, AH
	IN  AL, DX
	MOV AH, AL
	AND AH, 080H
	CMP BL, AH
	JE TOG3
	AND AL, 00FH
	PUSH AX
TOG4:	MOV CX, 0FFFH
WAIT4:	NOP
	LOOP WAIT4
	MOV AH, AL
	AND AH, 080H
	MOV BL, AH
	IN  AL, DX
	MOV AH, AL
	AND AH, 080H
	CMP BL, AH
	JE TOG4
	AND AL, 00FH
	POP CX
	MOV AH, CL
        MOV CL, 4
        SHL AH, CL
	OR  AL, AH
	CALL BCD2HEX
	POP BX		;OPERATER INTO BX
	POP CX
	MOV AH, CL
	JMP CALC

; CALCULATIONS SECTION

SOLVE:  POP CX
        POP BX
        POP AX
        
CALC:	CALL SPACE
	
	CMP BL, 0H
	JE  MINUSG
	CMP BL, 02DH
	JE  MINUSG

	CMP BL, 01H
	JE  PLUSG
	CMP BL, 2BH
	JE  PLUSG

	CMP BL, 02H
	JE  PARTG
	CMP BL, 2FH
	JE  PARTG

	CMP BL, 03H
	JE  TIMESG
	CMP BL, 2AH
	JE  TIMESG

	CMP BL, 04H
	JE  MODG
	CMP BL, 25H
	JE  MODG

	CMP BL, 05H
	JE  POWG
	CMP BL, 5EH
	JE  POWG

        CALL ERRS

MINUSG: SUB AL, CL
        DAS
        MOV DL, AL
        MOV AH, 02H
        INT 21H
        ;JO  OVER
	JMP DISP

PLUSG:  CLC
        ADC AL, CL
        DAA
        MOV DL, AL
        MOV AH, 02H
        INT 21H
	JO  OVER
	JMP DISP

PARTG:	DIV CL
	JO  OVER
	JMP DISP

TIMESG: MUL CL
	CMP AH, 0
	JNZ OVER
	JMP DISP

MODG:   CALL PARTG
	XCHG AL, AH
	JMP DISP

POWG:   CALL EXPONENT
	CMP BL, 12H
	JE OVER
	JMP DISP

; DISPLAY SECTION

DISP:	MOV DX, PORT_B
	OUT DX, AL
	CALL HEX2BCD
	CALL BCD2ASCII
	XCHG AL, AH
	CALL OUTPUTBYTE
        PUSH AX
        MOV DL, AL
        MOV AH, 02H
        INT 21H
        POP AX
        XCHG AL, AH
	CALL OUTPUTBYTE
        PUSH AX
        MOV DL, AL
        MOV AH, 02H
        INT 21H

	JMP GETNUM

OVER:	MOV DX, PORT_B
	MOV BL, 3

BLINK:	MOV AL, 0FFH
	OUT DX, AL
	MOV CX, 0FFFFH

ONLED:	NOP
	LOOP ONLED
	MOV AL, 000H
	OUT DX, AL
	MOV CX, 0FFFFH

OFFLED:	NOP
	LOOP OFFLED
	DEC BL
	CMP BL, 0
	JNZ BLINK
	JMP GETNUM

END BEGIN
.END
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.