;; USMAN MALIK
;; CLASS CST 121 
;; MIDTERM 
;;DATE: 03/21/2013

INCLUDE PCMAC.INC

.MODEL SMALL
;.586
EXTRN GetDec : NEAR
EXTRN PutDec : NEAR
EXTRN PutHex : NEAR

.STACK 100h

.DATA
PromptP DB 'Please enter a number fo P: ','$'
PromptQ DB 'Please enter a number fo Q: ','$'
PromptR DB 'Please enter a number fo R: ','$'
PromptS DB 'Please enter a number fo S: ','$'
Sum 	DB 'The sum of the 4 numbers is: ','$'
Average	DB 'The Average of the 4 numbers is: ', '$'
NewP	DB 'The new value of P is: ', '$'
NewQ	DB 'The new value of Q is: ', '$'
NewR	DB 'The new value of R in Hex is: ','$'
NewS	DB 'The new value of S will increase by one always : ', '$'
P	DW 	?
Q	DW	?
R	DW	?
S	DW	?
.CODE
Midterm PROC
		;_Begin
        mov ax, @data
        mov ds, ax
		
		_PutStr PromptP		;Asking for the value of P
        	Call 	GetDec		;ax:= decimal from the keyboard
		mov P, ax  		;save ax in variable P
		
		_PutStr PromptQ		;Asking for the value of Q
		Call GetDec		;ax:= decimal from the keyboard
		mov Q, ax  		;save ax in variable Q
		
		_PutStr PromptR		;Asking for the value of R
		Call GetDec		;ax:= decimal from the keyboard
		mov R, ax  		;save ax in variable R
		
		_PutStr PromptS		;Asking for the value of S
		Call GetDec		;ax:= decimal from the keyboard
		mov S, ax  		;save ax in variable S
		
		_PutStr Sum		;displaying the sum of the 4 values
		mov 	ax,P		;ax = P	
		add	ax,Q		;adding Q to ax
		add	ax,R		;adding R to ax
		add	ax,S		;adding S to ax
		Call	PutDec		;displaying the value in decimal
		_PutCh 13,10
		
		_PutStr Average		;displaying the average of the 4 numbers
		;shr	ax,2		;moving the bits to right by 2
		;call	PutDec		;displaying the value in decimal
		_PutCh 13,10
		
		_PutStr NewP		;displaying the new P=P xor Q
		mov ax, p		;ax = P
		xor ax, Q		;performing the xor with Q
		mov P,ax		;saving the new value of P
		call	PutDec
		_PutCh 13,10
		
		_PutStr NewQ		;displaying the new Q=Q xor NewP
		mov ax, Q		;ax = Q
		xor ax, P		;performing the xor with P
		mov Q, ax		;saving the new value of Q
		call	PutDec
		_putCh 13,10
		
		_PutStr NewR		;displaying the masked R value
		mov ax, R		;ax= R
		and ax,0001111111111000B ;masking the first and last 3 bits
		call	PutHex
		_PutCh 13,10
		
		_PutStr NewS		;displaying the last bit of S as 1
		mov ax, S		;ax = S
		or ax,1B
		call PutDec
		
		
		
		_Exit
						
Midterm ENDP

		 END	Midterm

