Close

Cleanup And Optomization

A project log for Lunar Lander for the PDP-1

My PDP-1 Replica (PiDP-1) from Obsolescence Guaranteed has arrived and I want to do something cool with it.

michael-gardiMichael Gardi 9 hours ago0 Comments

I wanted to review the code I had written. When I started this project I was a complete noob to both the PDP-1 machine and assembly language. After about a month's effort I felt that I was beginning to "get it".

So I went back and reviewed an early piece of code, drawing the LEM, and sure enough there were a number of improvements to be had.

/ Draw the LEM based on an 18-bit by 18 word bitmap.
   
   
        OLD                                    NEW
        ===                                    ===    

                                               lac (400000 
                                               dac bit
                                               
                                               lac bsx
                                               dac tmp

lbn,    lac .                          lbn,    lac .       
        sza i                                  sza i       
        jmp lt1                                jmp lt1     

        dac bmr                                dac bmr     [-20]
        lac (400000         
        dac bit                        
                                       
nb0,    lac bit                        nb0,    lac bit     [0]
        and bmr                                and bmr     
        sza i                                  sza i       
        jmp nb1                                jmp nb1     
                                       
        lac bsx                                lac bsx     
        lio bsy                                lio bsy
        dpy-i 4700                             dpy-i 4700
                                           
nb1,    lac bit                        nb1,    lac bit     [-10]
        sad (1                                 rar 1s      
        jmp nrw                                dac bit 
                                               sad (400000 
        lac bit                                jmp nrw     
        rar 1s                         
        dac bit                                  
                                              
        lac bsx                                lac bsx  
        add scl                                add scl   
        dac bsx                                dac bsx
        jmp nb0                                jmp nb0  
                                       
nrw,    lac lbn                        nrw,    idx lbn     [-50]  
        add (1                         
        dac lbn                                
                                               
        lac bsy                                lac bsy    
        sub scl                                sub scl
        dac bsy                                dac bsy 
                                               
        lac scx                                lac tmp 
        sub (4400                              dac bsx 
        dac bsx 
                                               jmp lbn 
        lac (400000         
        dac bit
        jmp lbn

I'm not going to go into detail on the code above. Suffice it to say that I'm pretty happy with the improvements. The important thing is the numbers off to the right. They represent the number of microseconds I was able to eliminate from the OLD code when creating the NEW. Both of course do exactly the same thing.

PDP-1 instruction have the following performance characteristics:

In the above code comparison the numbers on the right indicate the how many "microseconds" were removed from that block of the code (demarked by the labels). Another thing to consider is how any times that block of code will be executed when drawing the LEM.  The lbn and nrw blocks only execute once per row of the bitmap, while the nb1 code executes once per pixel. So the total savings for optimizing this code is:

(20 + 50) x 18 rows =          1,260 microseconds
10 x 18 columns x 18 rows =    3,240 microseconds
                               ==================
                               4,500 microseconds

4.5 ms every time the LEM is drawn which is about 10 times per second.  That doesn't sound like much but it leaves more time to draw the other pixels and thus reduce flicker (say).

Discussions