;;; program to convert degrees celsius C into farenheit F ;;;
;;;;; formula: F = (9*C/5) + 32
;;; This program will even take care of the decimal point in the answer

INCLUDE PCMAC.INC
		
		.MODEL SMALL
		.586
		.STACK 100H

		.DATA

MSG1		DB	"Please input temperature in Celsius:$"
MSG2		DB	"The equivalent temperature in Farenheit is:$"
PT0		DB	".0$"
PT2		DB 	".2$"
PT4		DB	".4$"
PT6		DB	".6$"
PT8		DB	".8$"
CEL		DW	?   ;variable to store value in celsius
REM		DW	?   ;variable to store the remainder after the division by 5
		.CODE
		EXTERN GETDEC:NEAR, PUTDEC:NEAR
DIOGO		PROC
		_BEGIN
		_PUTSTR MSG1
		CALL 	GETDEC	;temperature C entered is stored in AX
		MOV	BX, 9	; MUL 9 is not allowed
		MUL	BX     	; AX = BX * AX  i.e AX = 9*C		
		MOV	BX, 5	; DIV 5 is not allowed
		DIV 	BX 	; AX = AX/5	i.e AX = 9*C/5 (quotient only)

;;;; we have to take the second row in the division table (why?)
;;;; the remainder is found in DX	
		
		MOV	REM, DX	;copy remainder in variable REM		
		ADD	AX, 32	;add 32 to the quotient	
		MOV 	CEL, AX	;save the answer without the decimal bit in variable CEL
		_PUTSTR MSG2	;the reason we have to do this is because _PUTSTR destroys the value in AX
		MOV 	AX, CEL	;put back the saved value in AX so that we can print it using PUTDEC
		CALL 	PUTDEC
;;; now this bit is just to print the appropriate decimal value based on the remainder after the division
		CMP	REM,0 
		JE	PRINT0		;if remainder equals 0 append .0
		CMP	REM,1
		JE	PRINT2		;if remainder equals 1 append .2
		CMP	REM,2
		JE	PRINT4		;if remainder equals 2 append .4
		CMP	REM,3
		JE	PRINT6		;if remainder equals 3 append .6
		CMP	REM,4
		JE	PRINT8		;if remainder equals 4 append .8
PRINT0:		_PUTSTR PT0
		JMP FINITO
PRINT2:		_PUTSTR PT2
		JMP FINITO		
PRINT4:		_PUTSTR PT4
		JMP FINITO
PRINT6:		_PUTSTR PT6
		JMP FINITO
PRINT8:		_PUTSTR PT8

FINITO:		_EXIT	0
DIOGO		ENDP
		END	DIOGO