RPN Fixed point Calculator (HC12)

Thread Starter

mistercode

Joined May 30, 2013
8
Using an HC12 with Cygwin and TerraTerm, I am designing a fixed point calculator. Being a little late to start I am seeking some solid help. The lab wants the format (-)x.x for entry and the result to be (-)xx.x

This is an example for addition entry that will be of this format (in my terraterm window)

c> 1.0
c> 9.1
c> +
10.1
c>

The (-) is an optional negative sign. The calculator will add/subtract multiply/divide and also have the input R/r to generate a random number between 0.0 and 9.9

If anything is entered, an error message occurs.

I have a random num generator I have previously made before, it is commented out for the time being. I am working on the display. I guess I really need help on putting this together, and would like to start on add/subtract first. Here is what I have so far:

Rich (BB code):
;*****************************************************
; Lab 6 - Calculator 
;*****************************************************
; EQUATES
;*****************************************************
OUTCRLF		equ	$0FC8	; Output Carriage Return / line feed
GETCHAR  	equ	$0FB3	; Retrieve a character
PUTSTRNG    equ $0FB9   ; Outputs a string
OUTDECW		equ $0FBF   ; Outputs dec val of 16-bit word

;*****************************************************
; Main Program
;*****************************************************
		org	$2000


main	ldd	    #Prompt	   ;Enter Input (c>)
    	jsr     PUTSTRNG
		jsr     GETCHAR    ;char input => B
		cmpb    #$0D       ;'enter'
		beq     checkz
		beq     quit 
checkz	jsr     Display
        bra     main	
quit	swi

;*******************************************************
; Display
;*******************************************************


disp
        std     ChkResult
		ldd     #Answer    ;answer
		jsr     PUTSTRNG
	    ldd     #ChkResult ;Address => D
		jsr     OUTDECW
		jsr     OUTCRLF
		rts
		

;**********************
; Rand Num Gen
;**********************
;rnd
;     pshb		          ;push b onto stack
;	  andb    #MASK4      ;set number to use
;     lsrb
;	  lsrb
;	  lsrb
;	  lsrb
;	  eorb    crnt        ;xor current number
;	  stab    crnt        ;store current number
;	  ldab    0,sp	      
;	  andb    #MASK3
;	  lsrb
;	  lsrb
;	  lsrb
;	  eorb    crnt
;	  stab    crnt
;	  ldab    0,sp		  
;	  andb    #MASK2
;	  lsrb
;	  lsrb     
;	  eorb    crnt
;	  stab    crnt
;	  ldab    0,sp		  
;	  andb    #MASK0
;	  eorb    crnt
;	  stab    crnt
;	  ldaa    crnt
;	  ldab    0,sp
;	  lsrd
;      stab    0,sp    
;      pulb	               ;pul b to balance stack
;      rts 
			
;*******************************************************
; Constants
;*******************************************************
Prompt		dc.b	'c>',$0d,$0a,$00
Answer    	dc.b    '',$00
;*******************************************************
; Variables
;*******************************************************
ChkResult	ds.w	1
 

WBahn

Joined Mar 31, 2012
30,060
You might start by formatting your code so that it displays cleanly. As it is, it is very annoying to look at. You may have to do several edit/preview cycles to get it good.

Add as much commenting to the code as you can. Remember, we have no idea what each line is trying to accomplish. Don't make us have to reverse engineer your code.
 

Thread Starter

mistercode

Joined May 30, 2013
8
Okay, I will start by doing the display, which should display 'c>' for the input and a blank for the answer. Here it is:

Rich (BB code):
;*****************************************************
; Lab 6 - Calculator 
;*****************************************************
; EQUATES
;*****************************************************
OUTCRLF	equ	$0FC8	; Output Carriage Return / line feed
GETCHAR  	equ	$0FB3	; Retrieve a character
PUTSTRNG  equ $0FB9          ; Outputs a string
OUTDECW	equ $0FBF          ; Outputs dec val of 16-bit word

;*****************************************************
; Main Program
;*****************************************************
		org	$2000


main	
                ldd	    #Prompt	      ;Enter Input (c>)
    	        jsr         PUTSTRNG    ;output string
		jsr     GETCHAR          ;char input => B
		cmpb    #$0D             ;'enter'
		beq     checkz	       ;branch to sub checkz
checkz	
                jsr     Display
                bra     main	

;*******************************************************
; Display
;*******************************************************


disp
                std     ChkResult	 ;16bit variable
		ldd     #Answer     ;answer -> ACCD
		jsr      PUTSTRNG	 ;output string
	        ldd     #ChkResult  ;Address of answer => D
		jsr      OUTDECW		;output dec val of 16bit word
		jsr      OUTCRLF		;carriage return
		rts					;returns to main

;*******************************************************
; Constants
;*******************************************************
Prompt	dc.b	  'c>',$0d,$0a,$00
Answer    	dc.b    '',$00	 ;simply displays the answer
;*******************************************************
; Variables
;*******************************************************
ChkResult	ds.w	1
 

Thread Starter

mistercode

Joined May 30, 2013
8
Let's start with addition as well. I am experimenting with it and would like some help.

Assuming I need to use BCD instructions. I need to be able to use positive and negative numbers as well, so I would have to do a check then? I am confused.

Rich (BB code):
ldaa      num1      ;num1 -> ACCA

; somehow retrieve user input for num1?

ldab      num2      ;num2 -> ACCB

; somehow retrieve user input for num 2?

addd                   ; A+B -> D

daa                     ; decimal adjust?

;Variables
num1                  ds.w
num2                  ds.w
 
Top