Current location: Hot Scripts Forums » General Community » The Lounge » Assembler Coding


Assembler Coding

Reply
  #1 (permalink)  
Old 12-17-06, 08:35 PM
downsouth downsouth is offline
New Member
 
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Assembler Coding

Can someone please help me correct this code. It is giving me a read from unprogrammed RAM error. I am using the TEXAS assembler: The object of this code is to function as a calculator and output to a CRT. The

Error:
Read from unprogrammed ROM address 0xFFFF


Code:

Code:
***************************************************************************************************************************
*Initialize all ports and necessary memory for program
*
*
*
*
*
***************************************************************************************************************************
PIOC    equ $1002
PortC   equ $1003
PortD   equ $1008
DDRC    equ $1007

TCNT    equ $100E
SCCR1   equ $102C
SCCR2   equ $102D
BAUD    equ $102B
SCSR    equ $102E
SCDR    equ $102F
        org $0000
Total   		rmb 4
OperationASCII    rmb 1
count			rmb 1
placestocompute   rmb 1
countadd          rmb 1
Digit_Position    rmb 1

onesplace         rmb 2
tensplace         rmb 2
hundredsplace     rmb 2
thousandsplace     rmb 2
tenthousandsplace rmb 2
M		      rmb 2
N			rmb 2
Tot_Calculated     rmb 2
Total_Value1      rmb 2
Total_Value2      rmb 2
Total_Output       rmb 2
		       org   $D000

******Initialize Keyboard******************************************************************************
*Inputs: None
*Outputs: None
*******************************************************************************************************

Key_Init	ldaa #$20
	  	staa PIOC   ; set up PORTC as open connector
		ldaa #$F0   ;PC3-PC0 as input, Pc7-PC4 outputs
		staa DDRC   ;
       	rts
*******************************************************************************************************


*************InitSCI***********************************************************************************
* Initalize SCI
* This RITUAL is executed once
* Inputs: none    Outputs: none
* Registers modified: CCR
*******************************************************************************************************
InitSCI   psha
          ldaa #$0c
          staa SCCR2    enable SCI
          ldaa #0
          staa BAUD     baud rate=125000 bps
          pula
          rts
* * * * * * * End of InitSCI* * * * * * * * ************************************************************

******************************************************************************************************
*This routine reads values input from keyboard and ouputs them to the CRT as they are input
*After character output the ASCII character is saved its decimal equivalent.  For operations they are 
*as their ASCII keyboard value
*
*
*
*
*****************************************************************************************************

Key_In ldaa #%01110000             ;PortC value determines row to be scanned
     staa PortC  ;buy setting PC7=0 and PC6 through 4=0 Scans row0
     ldaa PortC
     anda #$0F
     cmpa #$07       ;"1" pressed?
     bne  not1    
     ldaa #'1'
     jsr OutCh
     ldaa #%00000001
     jmp  found


not1 cmpa #$0B       ;"2" pressed?
     bne  not2
     ldaa #'2'
     jsr OutCh
     ldaa #%000000010
     jmp  found


not2 cmpa #$0D       ;"3" pressed?
     bne  not3
     ldaa #'3'
     jsr OutCh
     ldaa #%000000011
     jmp  found


not3 cmpa #$0E
     bne  notPL
     ldaa #'+'
     staa OperationASCII
     jsr OutCh
      jmp found



notPL ldaa #%10110000 ;condition deactivates row0 and activates row 1
     staa PortC  ; x0xxx activates row1
     ldaa PortC
     anda #$0F
     cmpa #$07       ;"4" pressed?
     bne  not4
     ldaa #'4'
     jsr OutCh
     ldaa #%00000100
     jmp  found

not4 cmpa #$0B       ;"5" pressed?
     bne  not5
     ldaa #'5'
     jsr OutCh
     ldaa #%00000101
     jmp  found

not5 cmpa #$0D       ;"6" pressed?
     bne  not6
     ldaa #'6'
     jsr OutCh
     ldaa #%00000110
     jmp  found

not6 cmpa #$0E
	bne notMI
      ldaa #'-'
      staa OperationASCII
      jsr OutCh
	jmp found

notMI ldaa #%11010000
     staa PortC  ; xx0x activates row2
     ldaa PortC
     anda #$0F
     cmpa #$07       ;"7" pressed?
     bne  not7
     ldaa #'7'
     jsr OutCh
     ldaa #%00000111
     jmp  found

not7 cmpa #$0B       ;"8" pressed?
     bne  not8
     ldaa #'8'
     jsr OutCh
     ldaa #%00001000
     jmp  found

not8 cmpa #$0D       ;"9" pressed?
     bne  not9
     ldaa #'9'
     jsr OutCh
     ldaa #%00001001
     jmp  found

not9 cmpa #$0E
      bne notMU
      ldaa #'*'
      staa OperationASCII
      jsr OutCh
	jmp found

notMU ldaa #%11100000
      staa PortC  ; xxx0 activates row3
     ldaa PortC
     
     anda #$0F
     cmpa #$07       ;"c" pressed?
     bne  notC
     ldaa #'0'
     jsr OutCh
     jmp  found

notC cmpa #$0B
     bne not0
     ldaa #'0'
     jsr OutCh
     jmp found

not0	cmpa #$0D
	bne notEQ
    	ldaa #'='
      staa OperationASCII
      jsr OutCh
	jmp found

notEQ cmpa #$0E
	bne notDE
      ldaa #'/'
      staa OperationASCII
      jsr OutCh
	jmp found

notDE jmp  Key_In     ; wait for exactly one
found rts
******************************************************************************************************
******************************************************************************************************
******************************************************************************************************


******wait for release********************************************************************************
*inputs: none
*outputs: none
*
*This routine waits for the release of the key and for another to be pressed
******************************************************************************************************

Key_Release
     psha
     ldaa #$00
     staa PortC  ; activate all rows
wait ldaa PortC
     anda #$0F
     cmpa #$0F       ; none pressed?
     bne  wait
     pula
     rts
******************************************************************************************************
******************************************************************************************************
******************************************************************************************************

***************OutCh**********************************************************************************
* Output one character to SCI terminal
* Inputs: RegA is ASCII character    Outputs: none
* Registers modified: CCR
******************************************************************************************************
TDRE    equ  $80
OutCh   psha
OutWait ldaa SCSR
        anda #TDRE
        beq  OutWait    Gadfly wait for TDRE
        pula
                    * TDRE=1 when ready for more output
        staa SCDR   Start Output
        rts
* * * * * * * * End of OutCh * * * * * * * **********************************************************
*****************************************************************************************************



*****************************************************************************************************
*This routine pulls the digits that are stored on the stack and saves them to their corresponding
*decimal position.
*
*
*Routine Name: Pull Digits
*Input:
*Output:
*
*
*****************************************************************************************************
PullDigits	ldaa count			;count is the number of digits input from the keyboard
            staa placestocompute    ;save duplicate of count for the number of places to calculate
            pula
            staa onesplace          
            dec count
            beq Calc_Onesplace ;if no more digits on stack calculate decimal value
            pula
            staa tensplace
            dec count
            beq Calc_Onesplace  ;if no more digits on stack calculate decimal value
            pula
            staa hundredsplace
            dec count
            beq Calc_Onesplace  ;if no more digits on stack calculate decimal value
            pula 
            staa thousandsplace
            dec count
            beq Calc_Onesplace  ;if no more digits on stack calculate decimal value
            pula
            staa tenthousandsplace
            dec count
            beq Calc_Onesplace  ;if no more digits on stack calculate decimal value
            bne error         ;If count not equal to zero to many digits were input which is an error
******************************************************************************************************
******************************************************************************************************



*****************************************************************************************************
*This computes the decimal value of the numbers input and stores the Total in Tot_Calculated, which
*is a 16-bit memory location.
*
*Routine Name: Calc_Oneplace
*
****************************************************************************************************
Calc_Onesplace  	ldaa #0
                	cmpa placestocompute  ;placestocompute = number of characters input
                	beq error   ;if no digits are input give an error
              	
                  ldaa onesplace
                  ldab #1
                  mul
                  std Tot_Calculated  ;stores ones place total in Tot_Calculated
                 
Calc_Tensplace    dec placestocompute
                  ldaa #0
                  cmpa placestocompute
                  beq NoMoreDigits    ;no more digits were input total calculated
                  ldaa tensplace
                  ldab #10
                  mul
                  addd Tot_Calculated  ;add value of tens place to total
                  std  Tot_Calculated  ; saves value
                 
Calc_Hundredsplace dec placestocompute
                   ldaa #0
                   cmpa placestocompute
                   beq NoMoreDigits   ;no more digits were input total calculate
                   ldaa hundredsplace
                   ldab #100
                   mul
                   addd Tot_Calculated ; adds number of hundreds to value
                   std Tot_Calculated ;saves value

Calc_Thousands     dec placestocompute
                   ldaa #0
                   cmpa placestocompute
                   beq NoMoreDigits
                   ldaa thousandsplace
                   staa countadd
here	            ldd #1000
                  addd Tot_Calculated ; add 1000 to total for each thousand place
                  dec countadd ;decrease number of thousands to add to total
                  bne here     ; if not zero add another thousand
                  dec placestocompute  ;if no more thousands go to next place to compute
                  ldaa #0
                  cmpa placestocompute
                  beq NoMoreDigits    ;if no more places to compute go to no more digits
          
                 ldaa tenthousandsplace
                 staa countadd
here1            ldd #10000
                 addd Tot_Calculated
                 std  Tot_Calculated
                 dec countadd
                 bne here1
                 dec placestocompute
                 ldaa #0
                 beq NoMoreDigits
                 bne error   ;if more than 5 digits input gives an error
*****************************************************************************************************
*****************************************************************************************************


******************************************************************************************************
*This routine reinitializes all values and restarts code.  Also output error message for invalid 
*procedures!!!!
*
*
*Routine Name: Error
*
*
*
*
*
*******************************************************************************************************
error	      jmp Main

******************************************************************************************************



******************************************************************************************************
*This routine determines whether to save the value input into value 1 or value 2. 
*
*Routine Name: NoMoreDigits
*
*
*
*******************************************************************************************************
NoMoreDigits inc  Digit_Position
             ldaa Digit_Position      ;loads value of digit position in A
             cmpa #1		      ; checks to see if this is the first number
             bne Not_Postion1        ; if not check if it is the seconde
             ldd Tot_Calculated
             std Total_Value1       ;if first value it is saved in Total_Value1
             inc Digit_Position
             jmp  Scan        ;input 2nd digit
Not_Postion1 cmpa #2                ;checks to see if this is the second number
             bne Not_Postion2       ; if not second number then it is an error
             ldd Tot_Calculated
             std Total_Value2		; if second value it is saved in Total_Value@
             jmp PerformOperation         ; perform calculations
Not_Postion2 jmp error
******************************************************************************************************
******************************************************************************************************

******************************************************************************************************
*This routine takes Value1 and Value2 and performs the necessary operation on them
*The value of the opeation input is checked to see what operation to perform
*This routine handles 16 bit signed and unsigned operations
*
*Routine Name: Perform Operation
*
******************************************************************************************************
PerformOperation  ldaa OperationASCII
                  cmpa #'+'
                  bne Not_Add
                  ldd Total_Value1
                  addd Total_Value2
                  bvc SetP1
                  bpl Floor
Ceiling1          ldd #32767
                  bra SetP           
Floor			ldd #-32678
SetP1             std Total_Output
                  jsr OutputTotal

Not_Add		cmpa #'-'
                  bne Not_Sub
sub16s            ldd Total_Value1
                  subd Total_Value2                
                  bvc SetP
                  bpl Floor
Ceiling           ldd #32678
                  bra SetP 
floor             ldd #-32678
SetP	            std Total_Output
			jsr OutputTotal

Not_Sub		cmpa #'*'
                  bne Not_Mul
                  ldd Total_Value1
                  std M
                  ldd Total_Value2
                  std N
                  jsr 16bit_mul
                  std Total_Output
                  jsr OutputTotal

Not_Mul          cmpa #'/'
                 bne error
                 ldd Total_Value1
                 ldx Total_Value2
                 idiv
                 stx Total_Output
                 jsr OutputTotal

*****************************************************************************************************
*****************************************************************************************************
*****************************************************************************************************


****************************************************************************************************
*This routine performs 16-bit multiplication
*
*
*
*
*
*
****************************************************************************************************
16bit_mul  ldaa M+1
           ldab N+1
           mul
           std Total+2
           ldaa M
           ldab N
           mul
           std Total
           ldaa M
           ldab N+1
           mul
           addd Total+1
           std Total+1
           ldaa Total
           adca #0
           staa Total
           ldaa M+1
           ldab N
           mul
           addd Total+1
           ldaa Total
           staa Total
           rts
******************************************************************************************************
*****************************************************************************************************
*****************************************************************************************************
           



*****************************************************************************************************
*Routine Name: Output Total
*
*This routine reads the value stored in data converts it into BCD, then converts it to ASCII
*and finally outputs the digits
*
*
*
******************************************************************************************************
OutputTotal  ldd Total_Output
             ldx #10
             idiv 
             stab $06
             xgdx
             ldx #10
             idiv
             stab $05
             xgdx
             ldx #10
             idiv
             stab $04
             xgdx
             ldx #10
             idiv
             stab $03
             xgdx
             stab $02
BCD_ASCII    ldaa $02
             adda $30
		 jsr OutCh
             ldaa $03
             adda $30
             jsr OutCh
             ldaa $04
             adda $30
             jsr OutCh
             ldaa $05
             adda $30
             jsr OutCh
             ldaa $06
             adda $30
             jsr OutCh
             rts
*****************************************************************************************************
****************************************************************************************************
****************************************************************************************************
******************************************************************************************************
******************************************************************************************************
******************************************************************************************************

*******************************************************************************************************
*This routine clears all memory locations
*
*
*
*
******************************************************************************************************
ClearMemory 	ldd  #0
                  staa OperationASCII
                  staa count
                  staa placestocompute
                  staa countadd
                  staa Digit_Position
                  std onesplace
                  std tensplace
                  std hundredsplace
                  std thousandsplace
                  std tenthousandsplace 
                  std Tot_Calculated
                  std Total_Value1
                  std Total_Value2
                  std Total_Output
                  std Total
                  rts
********************************************************************************************************
**********************************************************************************************************
**********************************************************************************************************
*



********************************************************************************************************
*This is the main routine.  This calls all necessary operations.
*
*
*
************************************************************************************************************
	    
Main      
          jsr ClearMemory
          jsr Key_Init
          jsr InitSCI
Scan      jsr Key_In
          jsr Key_Release
          cmpa #$0E
          bne skip
          jmp PullDigits
skip      cmpa #'='
          bne skip1
          jmp PullDigits
skip1     inc count
          jsr Key_Release
          jmp Scan
Done      stop
          jmp Main
          org   $FFEE
          fdb   Main

Last edited by Nico; 12-18-06 at 02:54 AM. Reason: Please use [code] wrappers when posting code.
Reply With Quote
  #2 (permalink)  
Old 12-18-06, 02:58 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I moved your thread to the lounge 'cause I don't know what language that is. The "site suggestion and feedback" forum is not for code problems. If you tell me what language this is I'll move it to the correct forum. Thanks...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser Detect - will issue different coding joshlindem JavaScript 7 06-06-06 12:52 PM
MS Access - VB Coding MikeFairbrother Visual Basic 2 03-17-06 05:34 AM
Need website design or HTML coding help? website_help HTML/XHTML/XML 0 05-26-05 12:07 PM
PHP Coding Tips netbakers PHP 1 05-02-05 03:33 AM
Which language Java or Assembler beyercorpuz The Lounge 1 03-22-05 12:59 AM


All times are GMT -5. The time now is 03:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.