
;  --------------------------------------------------------------
;                EMBEDDED MICROCONTROLLER PROGRAMMING
;                       HOMEWORK #2 - PROBLEM 2
;
;                      Written by S.C.T.  1-10-99
;		    Modified by ALM: April 2, 2001
;  --------------------------------------------------------------

; This program demonstrates the use of 16 bit arithmetic and
; subroutine calls on the 8051.

; This is a shell program to demonstrate arithmetic for performing
; 16 bit addition and subtraction on the 8051.  The homework assignment
; is to fill in the missing subroutines which perform 16 bit adds on
; the values assigned to the respective program registers.

  $MOD52

  XH    EQU     R0              ; Define X High and Low Bytes
  XL    EQU     R1
  YH    EQU     R2              ; Define Y High and Low Bytes
  YL    EQU     R3
  ZH    EQU     R4              ; Define Z High and Low Bytes
  ZL    EQU     R5

  ORG   4000h                   ; Start Program execution at
                                ; Address 4000 hex

  MOV   XH, #0F0h               ; Load X High Byte with F0h
  MOV   XL, #73h                ; Load X Low Byte with 73h

  MOV   YH, #74h                ; Load Y High Byte with 74h
  MOV   YL, #65h                ; Load Y Low Byte with 65h

  ACALL ADD16                   ; Call ADD16 subroutine

; ---------------- ANSWER QUESTIONS HERE ----------------------
; 1) Assuming the 16 bit values in X and Y are UNSIGNED, what
; are the values in X and Y that we are adding (in decimal)?
; What will the value of Z be on return from the the
; subroutine (in decimal)?  Is this answer valid ? Why ?
;
; 2) Repeat 1 assuming X and Y are SIGNED values. 
; --------------------------------------------------------------


  ACALL SUB16  

; ---------------- ANSWER QUESTIONS HERE ----------------------
; 1) Assuming the 16 bit values in X and Y are UNSIGNED, what
; are the values in X and Y that we are subtracting (in decimal)?
; What will the value of Z be on return from the the
; subroutine (in decimal)?  Is this answer valid ? Why ?
;
; 2) Repeat 1 assuming X and Y are SIGNED values. 
; --------------------------------------------------------------


; ------------ FILL IN SUBROUTINES ADD16 and SUB16 Below -------
; 3) These two subroutines should perform 16 bit additions and
; subtractions (respectively) on the 16 bit values stored in
; X and Y and store the results in Z.  The high and low bytes
; in X,Y, and Z are denoted as XH,XL, YH,YL, and ZH,ZL.

  ADD16:

;       FILL IN THE ADD16 CODE HERE
;

  RET



  SUB16:

;
;       FILL IN THE SUB16 CODE HERE

  RET


  END
