             ;******* Opcode 0x38 
             ;The DECO instruction. 
             ;Output format: If the operand is negative, the algorithm prints 
             ;a single '-' followed by the magnitude. Otherwise it prints the 
             ;magnitude without a leading '+'. It suppresses leading zeros. 
             ; 
             remain:  .EQUATE 0          ;Remainder of value to output 
             chOut:   .EQUATE 2          ;Has a character been output yet? 
             place:   .EQUATE 4          ;Place value for division 
             ; 
FF3B  C000FF opcode38:LDA     0x00FF,i   ;Assert i, d, n, s, sf, x, sx, sxf 
FF3E  E1FC53          STA     addrMask,d 
FF41  16FCCA          CALL    assertAd   
FF44  16FD19          CALL    setAddr    ;Set address of trap operand 
FF47  680006          SUBSP   6,i        ;Allocate storage for locals 
FF4A  C2FC55          LDA     opAddr,n   ;A := oprnd 
FF4D  B00000          CPA     0,i        ;If oprnd is negative then 
FF50  0EFF57          BRGE    printMag   
FF53  50002D          CHARO   '-',i      ;Print leading '-' and 
FF56  1A              NEGA               ;make magnitude positive 
FF57  E30000 printMag:STA     remain,s   ;remain := abs(oprnd) 
FF5A  C00000          LDA     FALSE,i    ;Initialize chOut := FALSE 
FF5D  E30002          STA     chOut,s    
FF60  C02710          LDA     10000,i    ;place := 10,000 
FF63  E30004          STA     place,s    
FF66  16FF91          CALL    divide     ;Write 10,000's place 
FF69  C003E8          LDA     1000,i     ;place := 1,000 
FF6C  E30004          STA     place,s    
FF6F  16FF91          CALL    divide     ;Write 1000's place 
FF72  C00064          LDA     100,i      ;place := 100 
FF75  E30004          STA     place,s    
FF78  16FF91          CALL    divide     ;Write 100's place 
FF7B  C0000A          LDA     10,i       ;place := 10 
FF7E  E30004          STA     place,s    
FF81  16FF91          CALL    divide     ;Write 10's place 
FF84  C30000          LDA     remain,s   ;Always write 1's place 
FF87  A00030          ORA     0x0030,i   ;Convert decimal to ASCII 
FF8A  F1FC50          STBYTEA byteBuff,d 
FF8D  51FC50          CHARO   byteBuff,d 
FF90  5E              RET6               
             ; 
             ;Subroutine to print the most significant decimal digit of the 
             ;remainder. It assumes that place (place2 here) contains the 
             ;decimal place value. It updates the remainder. 
             ; 
             remain2: .EQUATE 2          ;Stack addresses while executing a 
             chOut2:  .EQUATE 4          ;subroutine are greater by two becaus
             place2:  .EQUATE 6          ;the retAddr is on the stack 
             ; 
FF91  C30002 divide:  LDA     remain2,s  ;A := remainder 
FF94  C80000          LDX     0,i        ;X := 0 
FF97  830006 divLoop: SUBA    place2,s   ;Division by repeated subtraction 
FF9A  08FFA6          BRLT    writeNum   ;If remainder is negative then done 
FF9D  780001          ADDX    1,i        ;X := X + 1 
FFA0  E30002          STA     remain2,s  ;Store the new remainder 
FFA3  04FF97          BR      divLoop    
             ; 
FFA6  B80000 writeNum:CPX     0,i        ;If X != 0 then 
FFA9  0AFFB5          BREQ    checkOut   
FFAC  C00001          LDA     TRUE,i     ;chOut := TRUE 
FFAF  E30004          STA     chOut2,s   
FFB2  04FFBC          BR      printDgt   ;and branch to print this digit 
FFB5  C30004 checkOut:LDA     chOut2,s   ;else if a previous char was output 
FFB8  0CFFBC          BRNE    printDgt   ;then branch to print this zero 
FFBB  58              RET0               ;else return to calling routine 
             ; 
FFBC  A80030 printDgt:ORX     0x0030,i   ;Convert decimal to ASCII 
FFBF  E9FC4F          STX     wordBuff,d ;for output 
FFC2  51FC50          CHARO   byteBuff,d 
FFC5  58              RET0               ;return to calling routine 
