TITLE   MINIMAL DEMO PROGAM CALC4                          
        PAGE      ,132

;                 PHY353  HOMEWORK --  CALCULATOR
;---------------------------------------------------------;
; Author: Raymond Ng                                      ;
; Class : Phy353                                          ;
; I.D.  :                                                 ;    
; Date  : 10/1/96                                      ;
; Purpose: To demonstrate the simplest program structure  ;
;          and  write a  program to add, subtract, divide ;
;          and multiply two 16-bit numbers.               ;                    ;
;          Note: program will handle only positive numbers;
;          The program subtracts a smaller from a larger  ;
;          number.
;          The program divides a larger number by a small-;
;          er number.
;          The above simplification is simply chosen to   ;
;          so that you can learn to run your first program;
;          fast.
;**********************************************************
STACK   SEGMENT   PARA STACK 'STACK'
        DB 64 DUP('STACK')
STACK   ENDS
;**********************************************************
DSEG    SEGMENT   PARA PUBLIC 'DATA'
;DATA1      DW   0FFh     ;  decimal 255
;DATA2      DW   0FFFh    ;  decimal 4095               
DATA1      DW   10
DATA2      DW   100
DATA3      DW   0FFFFh   ;  decimal 65535
SUM        DW   ?        ;  reserved for the sum
DIFF       DW   ?        ;  reserved for the diff
HIGHM      DW   ?        ;  holds the high bits for multiplication
LOWM       DW   ?        ;  holds the low  bits for multiplication
REMAINDER  DW   ?        ;  holds the high bits for division
QUOTIENT   DW   ?        ;  holds the  low bits for division
DSEG    ENDS
;*********************************************************
SUBTTL  The main program starts here
;---------------------------------------------------------
CSEG     SEGMENT   PARA PUBLIC 'CODE'
OUR_PROG PROC  FAR
         ASSUME CS:CSEG, DS:DSEG, SS:STACK
;  Set up the stack to contain the proper values 
;  so this program can return to debug.
;  
         PUSH DS           ; Put return seg. addr on stack
         MOV AX,0          ; Clear a register AX
         PUSH AX           ; Put zero return address on stack

;  Initialize the data segment address
         MOV AX,DSEG      ;Initialize DS
         MOV DS,AX
;  -------------------------------------------------------------
;  Perform the addition
;
         MOV AX,DATA1     ; Load first word to reg AX
         MOV CX,DATA2     ; Load second word to reg BX
         ADD AX,CX        ; Add data at mem loc DATA1 AND DATA2
;  Store the sum in memory
;
         MOV SUM,AX       ; Store the result at mem loc SUM
;  -------------------------------------------------------------
;  Perform the subtraction
         MOV AX,DATA1     ; Reload first word to reg AX
         XCHG AX,CX       ; Move large number to AX
         SUB AX,CX        ; Data at DATA2 - Data at DATA1
;  Store the difference in memory
;        
         MOV DIFF,AX      ; Store the result at mem loc DIFF
;  -------------------------------------------------------------
;  Perform the multiplication         
         MOV AX,DATA1     ; Reload first word to reg AX
         MOV CX,DATA2     ; Load second word
         MUL CX           ; Multiplies the contents of reg AX to CX
         MOV LOWM,AX      ; Move the low order bits into LOWM
         MOV HIGHM,DX     ; Move the high order bits into HIGHM
;----------------------------------------------------------------
;  Perform the division
         MOV DX,0         ; Initialize DX
         MOV AX,DATA1     ; Reload first word to reg AX
         MOV CX,DATA2     ; Load second word
         XCHG AX,CX       ; Move larger number to AX
         DIV CX           ; Data at DATA2 divided by data at DATA1
         MOV QUOTIENT,AX      ; Move low bits into LOWD
         MOV REMAINDER,DX     ; MOVE high bits into HIGHD
;----------------------------------------------------------------
         RET              ; Retrurn to DEBUG
OUR_PROG ENDP
CSEG     ENDS
         END OUR_PROG
;**********************************************************




