C Tutorial Euclid on PDP-11
The C Language
C History
Euclid’s Algorithm in C
Euclid on the PDP-11

Pieces of C
C Types
Struct bit-fields
Code generated by bit fields
C Unions
Layout of Records and Unions
C Storage Classes
malloc() and free()
Dynamic Storage Allocation
Simple Dynamic Storage Allocation
malloc() and free() variants
Fragmentation and Handles
Automatic Garbage Collection
Lazy Logical Operators
The Switch Statement
setjmp/longjmp: Sloppy exceptions
Nondeterminism in C





Line 1:.globl gcd

Line 2:.text

Line 3: gcd:

Line 4: jsr r5, rsave

Line 5:L2: mov 4(r5), r1

Line 6: sxt r0

Line 7:div 6(r5), r0

Line 8:mov r1, -10(r5)

Line 9:jeq L3

Line 10: mov 6(r5), 4(r5)

Line 11: mov -10(r5), 6(r5)

Line 12: jbr L2

Line 13: L3: mov 6(r5), r0

Line 14: jbr L1

Line 15: L1: jmp rretrn


Line 1: GPRs: r0–r7

Line 2: r7=PC, r6=SP, r5=FP

Line 4: Save SP in FP

Line 5: r1 = n

Line 6: sign extend

Line 7: r0, r1 = m _ n

Line 8: r = r1 (m % n)

Line 9: if r == 0 goto L3

Line 10: m = n

Line 11: n = r

Line 12:

Line13: r0 = n

Line14: non-optimizing compiler

Line15: return r0 (n)


.globl gcd



jsr r5, rsave

L2: mov 4(r5), r1

sxt r0

div 6(r5), r0

mov r1, -10(r5)

jeq L3

mov 6(r5), 4(r5)

mov -10(r5), 6(r5)

jbr L2

L3: mov 6(r5), r0

jbr L1

L1: jmp rretrn


  • Very natural mapping from  C into PDP-11



  • Complex addressing modes make frame-pointer-relative

         accesses easy.


  • Another idiosyncrasy: registers were memory-mapped, so taking

         address of a variable in a register is straightforward.

Contact for more learning: webmaster@freehost7com