Skip to content
The Chat Archive
claude-2.1· Anthropic Arena Human Preference 55K

Write a program in PDP-11 assembly that shows a loop

  1. User

    Write a program in PDP-11 assembly that shows a loop

  2. Assistant

    Here is a PDP-11 assembly program that shows a simple loop:

    .data
    msg: .ascii "In the loop\n"
    
    .text 
    .globl main 
    
    main:
        mov #10, r0    # r0 will be our loop counter  
    
        loop:
            dec r0
            bge loop    # branch if r0 >= 0
            br print
    
        print:
            mov $msg, r1
            mov $len, r2
            jsr $print
            br end
    
        end:
            halt
    
    len = . - msg
    

    This program does the following:

    • Sets up a loop counter in r0, initializing it to 10
    • Enters a loop that decrements r0 each iteration and branches back to the top as long as r0 >= 0
    • When r0 goes negative, it exits the loop and calls a print routine
    • The print routine prints the message "In the loop"
    • After printing, the program halts

    So this shows a simple DEC-based loop in PDP-11 assembly. The key parts are setting up the loop counter, comparing it to branch back to the top, and decrementing it each iteration. Let me know if you have any other questions!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.