;*********************************************************
; ECE331 HW 2 Addressing Mode Homework

;  NAME: _____________________________	 Box #___________

; This is an 9S12C32 Assembly Program
; Fill in ALL blanks in the comment fields
; with the register value(s) AFTER the
; commented line has executed.
;**********************************************************

            XDEF Entry        ; export 'Entry' symbol
            ABSENTRY Entry    ; for absolute assembly
            
            ORG $3800		;$3800 = Start of RAM
var1:      rmb 1              	;(Reserve memory byte = DS.B)
vararray1: rmb 10
var2:      rmb 1

            ORG $4000			;$4000 = Start of Flash ROM
const1:    fcb 3,2,7,8      		;(Form constant byte = DC.B)
const2:    fcb %10011010,%01011100  	;"%" => binary
const3:    fcb 'ECE331',0	  ;(Note ASCII strings can be allocated)
const4:    fcb $0b,$ad,$fa,$d0
const5:    fdb $0bad,$deed  ;(Form double byte = DC.W)
adrconst1: fdb const1       
adrconst2: fdb const2
adrconst3: fdb const3

PTT:     EQU $240			;Port T Data I/O Register
DDRT:    EQU $242			;Port T Data Direction Register

Entry: ldd #4000     ;d = $_______ 
                     ;b = $____ a = $____ (careful!)
       ldd #$4000    ;d = $_______
       ldd $4000     ;d = $_______
       ldab #-1	    ;b = $______
       ldab #$ff	  ;b = $_____
       ldy Entry	  ;y = $______
       ldy #Entry      ;y = $______
       ldy #Entry-(3*2);y = $______
       ldx const1      ;x = $_____
       ldaa const1+2   ;a = $_______

       LDAA #$55  ;Note that assembler is case insensitive
       STAA DDRT  ;DDRT contains $_____
       LDAA #%01101100 ;"%" prefix => binary
       STAA PTT ;List the four Port T pins
       		;that are output pins, and indicate
       		;their value
			 ;___________  ____________  __________   __________
       ;Assume outside world drives the
       ;the following input signals into
       ;the four PTT input pins:
       ;PT7 = High, PT5 = Low, 
       ;PT3 = High, PT1 = Low.

      LDAA PTT ; a = $______

      ldx #const2
      ldaa 0,x  ;x = $______, a = $_______
      ldd  0,x  ;x = $______, d = $_______
      inx
      ldab 0,x  ;x = $______, b = $_______
      ldy #const4
      ldaa 1,y   ;y = $______ a = $_____
      ldd  2,y   ;y = $______ d = $________ 
      ldy  3,y   ;y = $______
      ldy  #2
      ldy  const1,y   ;y = $_______
      ldy  0,pc       ;y = $_______	;Recall PC points to op 
      ldy  3,pc       ;y = $_______	;code of next instruction.
      ldx #const4
      ldaa 1,+x       ;x = $_______  a = $______
      ldaa 1,+x       ;x = $_______  a = $______
      ldx #const4
      ldaa 1,x+       ;x = $_______  a = $______
      ldaa 1,x+       ;x = $_______  a = $______
      ldx #const5
      ldd  2,-x       ;x = $_______  d = $______
      ldd  2,-x       ;x = $_______  d = $______
      ldx #const5
      ldd  2,x-       ;x = $_______  d = $______
      ldd  2,x-       ;x = $_______  d = $______
      ldy  #var2
      ldd  #$1234
      std  2,-y       ;y = $_______
      ldd  const2     ;d = $_______
      std  2,-y       ;y = $_______
      ldd  const3     ;d = $_______
      std  2,-y       ;y = $_______	<------------Fill in contents
      ldd  2,y+       ;d = $_______, y = $______	of RAM after
      ldd  2,y+       ;d = $_______, y = $______	this instr
                                                        ADDR   Contents 
      ldd  2,y+       ;d = $_______, y = $______	$380B   -------
      ldx  #const3					$380A	_____
      ldaa #2						$3809	_____
      ldab  a,x       ;a = $______, b = $______		$3808	_____
      inca						$3807   _____
      ldab  a,x       ;a = $______, b = $______		$3806   _____
      ldd  #2						$3805   _____
      ldab  d,x       ;d = $______, b = $______
      ldx  #0                          
      ldaa [adrconst1,x] ;x = $______, a = $_____
      inx
      inx
      ldaa [adrconst1,x] ;x = $______, a = $_____
      inx
      inx
      ldd [adrconst1,x]  ;x = $_____, d = $______
      ldd  #adrconst1
      ldx #0
      ldy [d,x]  ;x = $_______, y = $_______
      inx
      inx 
      ldy [d,x]  ;x = $_______, y = $_______
      ldaa #1
      ldab #2
      ldx  #3   
      aba         ;b = $_____  a = $______
      nop	  ;b = $_____  a = $______
      abx         ;b = $_____  x = $_________
      exg a,b     ;a = $_____  b = $______
      inx         ;x = $_________
      dex         ;x = $_________
      ldaa #3
      ldab #0
      ldx #const4	
here: addb a,x
      deca
      nop
      nop
      nop
      bne here  ;Disp byte after OPCODE = $____
      bra skip  ;Disp byte after OPCODE = $____
      nop
      nop
      nop
      nop
skip:	nop	 ;a = $____, b = $_____
done:	bra done ;Disp byte after OPCODE = $____

;**************************************************************
;*                 Interrupt Vectors                          *
;**************************************************************
  ORG $FFFE
  fdb     Entry      ; Reset