Some programming languages allow calculation of values at compile time.



Task

Calculate    10!    (ten factorial)   at compile time.

Print the result when the program is run.

Discuss what limitations apply to compile-time calculations in your language.




; Display the value of 10!, which is precomputed at assembly time
; on any Commodore 8-bit.
 
.ifndef __CBM__
.error "Target must be a Commodore system."
.endif
 
; zero-page work pointer
temp         = $fb
 
; ROM routines used
chrout       = $ffd2
 
    .code
 
    lda #<tenfactorial
    sta temp
    lda #>tenfactorial
    sta temp+1
    ldy #0
loop:
    lda (temp),y
    beq done
    jsr chrout
    iny
    bne loop
done:
    rts
 
    .data
 
; the actual value to print
tenfactorial: .byte 13,"10! = ",.string(10*9*8*7*6*5*4*3*2*1),13,0