RPN Fixed point Calculator (HC12)

Discussion in 'Embedded Systems and Microcontrollers' started by mistercode, May 30, 2013.

  1. mistercode

    Thread Starter New Member

    May 30, 2013
    5
    0
    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:

    Code ( (Unknown Language)):
    1.  
    2. ;*****************************************************
    3. ; Lab 6 - Calculator
    4. ;*****************************************************
    5. ; EQUATES
    6. ;*****************************************************
    7. OUTCRLF     equ $0FC8   ; Output Carriage Return / line feed
    8. GETCHAR     equ $0FB3   ; Retrieve a character
    9. PUTSTRNG    equ $0FB9   ; Outputs a string
    10. OUTDECW     equ $0FBF   ; Outputs dec val of 16-bit word
    11.  
    12. ;*****************************************************
    13. ; Main Program
    14. ;*****************************************************
    15.         org $2000
    16.  
    17.  
    18. main    ldd     #Prompt    ;Enter Input (c>)
    19.         jsr     PUTSTRNG
    20.         jsr     GETCHAR    ;char input => B
    21.         cmpb    #$0D       ;'enter'
    22.         beq     checkz
    23.         beq     quit
    24. checkz  jsr     Display
    25.         bra     main   
    26. quit    swi
    27.  
    28. ;*******************************************************
    29. ; Display
    30. ;*******************************************************
    31.  
    32.  
    33. disp
    34.         std     ChkResult
    35.         ldd     #Answer    ;answer
    36.         jsr     PUTSTRNG
    37.         ldd     #ChkResult ;Address => D
    38.         jsr     OUTDECW
    39.         jsr     OUTCRLF
    40.         rts
    41.        
    42.  
    43. ;**********************
    44. ; Rand Num Gen
    45. ;**********************
    46. ;rnd
    47. ;     pshb                ;push b onto stack
    48. ;     andb    #MASK4      ;set number to use
    49. ;     lsrb
    50. ;     lsrb
    51. ;     lsrb
    52. ;     lsrb
    53. ;     eorb    crnt        ;xor current number
    54. ;     stab    crnt        ;store current number
    55. ;     ldab    0,sp       
    56. ;     andb    #MASK3
    57. ;     lsrb
    58. ;     lsrb
    59. ;     lsrb
    60. ;     eorb    crnt
    61. ;     stab    crnt
    62. ;     ldab    0,sp       
    63. ;     andb    #MASK2
    64. ;     lsrb
    65. ;     lsrb    
    66. ;     eorb    crnt
    67. ;     stab    crnt
    68. ;     ldab    0,sp       
    69. ;     andb    #MASK0
    70. ;     eorb    crnt
    71. ;     stab    crnt
    72. ;     ldaa    crnt
    73. ;     ldab    0,sp
    74. ;     lsrd
    75. ;      stab    0,sp    
    76. ;      pulb                ;pul b to balance stack
    77. ;      rts
    78.            
    79. ;*******************************************************
    80. ; Constants
    81. ;*******************************************************
    82. Prompt      dc.b    'c>',$0d,$0a,$00
    83. Answer      dc.b    '',$00
    84. ;*******************************************************
    85. ; Variables
    86. ;*******************************************************
    87. ChkResult   ds.w    1
     
  2. WBahn

    Moderator

    Mar 31, 2012
    17,737
    4,789
    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.
     
  3. mistercode

    Thread Starter New Member

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

    Code ( (Unknown Language)):
    1.  
    2. ;*****************************************************
    3. ; Lab 6 - Calculator
    4. ;*****************************************************
    5. ; EQUATES
    6. ;*****************************************************
    7. OUTCRLF equ $0FC8   ; Output Carriage Return / line feed
    8. GETCHAR     equ $0FB3   ; Retrieve a character
    9. PUTSTRNG  equ $0FB9          ; Outputs a string
    10. OUTDECW equ $0FBF          ; Outputs dec val of 16-bit word
    11.  
    12. ;*****************************************************
    13. ; Main Program
    14. ;*****************************************************
    15.         org $2000
    16.  
    17.  
    18. main   
    19.                 ldd     #Prompt       ;Enter Input (c>)
    20.                 jsr         PUTSTRNG    ;output string
    21.         jsr     GETCHAR          ;char input => B
    22.         cmpb    #$0D             ;'enter'
    23.         beq     checkz         ;branch to sub checkz
    24. checkz 
    25.                 jsr     Display
    26.                 bra     main   
    27.  
    28. ;*******************************************************
    29. ; Display
    30. ;*******************************************************
    31.  
    32.  
    33. disp
    34.                 std     ChkResult    ;16bit variable
    35.         ldd     #Answer     ;answer -> ACCD
    36.         jsr      PUTSTRNG    ;output string
    37.             ldd     #ChkResult  ;Address of answer => D
    38.         jsr      OUTDECW        ;output dec val of 16bit word
    39.         jsr      OUTCRLF        ;carriage return
    40.         rts                 ;returns to main
    41.  
    42. ;*******************************************************
    43. ; Constants
    44. ;*******************************************************
    45. Prompt  dc.b      'c>',$0d,$0a,$00
    46. Answer      dc.b    '',$00   ;simply displays the answer
    47. ;*******************************************************
    48. ; Variables
    49. ;*******************************************************
    50. ChkResult   ds.w    1
    51.  
     
  4. mistercode

    Thread Starter New Member

    May 30, 2013
    5
    0
    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.

    Code ( (Unknown Language)):
    1.  
    2. ldaa      num1      ;num1 -> ACCA
    3.  
    4. ; somehow retrieve user input for num1?
    5.  
    6. ldab      num2      ;num2 -> ACCB
    7.  
    8. ; somehow retrieve user input for num 2?
    9.  
    10. addd                   ; A+B -> D
    11.  
    12. daa                     ; decimal adjust?
    13.  
    14. ;Variables
    15. num1                  ds.w
    16. num2                  ds.w
    17.  
     
Loading...