PDP-11 Assembler (source)
.globl start
.text
start:
mov $0,(sp)
mov $27,-(sp)
jsr pc, lambda
print_r1:
mov $outbyte,r3
div_loop:
sxt r0
div $12,r0
add $60,r1
movb r1,-(r3)
mov r0,r1
tst r1
jne div_loop
mov $1,r0
sys 4; outtext; 37
mov $1,r0
sys 1
lambda:
mov 2(sp),r1
cmp $2,r1
beq gottwo
bgt gotone
sxt r0
div $2,r0
tst r1
beq even
odd:
mov 2(sp),r1
dec r1
sxt r0
div $2,r0
mov r0,-(sp)
jsr pc,lambda
add $2,sp
mov r0,r3
mov r1,r2
mov r3,r4
mul r2,r4
mov r5,r1
mov r3,r4
add r2,r4
mul r2,r4
add r5,r1
mul r3,r3
mov r3,r0
mul r2,r2
add r3,r0
rts pc
even:
mov 2(sp),r1
sxt r0
div $2,r0
dec r0
mov r0,-(sp)
jsr pc,lambda
add $2,sp
mov r0,r3
mov r1,r2
mov r2,r4
mul r2,r4
mov r5,r1
mov r2,r4
add r3,r4
mul r4,r4
add r5,r1
mov r2,r4
add r3,r4
mul r2,r4
mov r5,r0
mul r2,r3
add r3,r0
rts pc
gotone:
mov $1,r0
mov $1,r1
rts pc
gottwo:
mov $1,r0
mov $2,r1
rts pc
.data
outtext:
.byte 62,63,162,144,40,106,151,142,157,156
.byte 141,143,143,151,40,156,165,155
.byte 142,145,162,40,151,163,40
.byte 60,60,60,60,60
outbyte:
.byte 12