Back PDP 11 ASSEMBLY LANGUAGE PROGRAMS

Download PDP 11 Assembler


;1. program to initialise n*n array so that arr[i,j]=i+j

arr: .word 0,0,0,0,0,0,0,0,0
n: .word 3

mov #arr,r2
clr r0
clr r1

l1: inc r0
l2: inc r1
mov r0,r3
add r1,r3
mov r3,(r2)+
cmp r1,n
bne l2
clr r1
cmp r0,n
bne l1
halt
.end


;2. program to reverse the order of a string.Use autoincrement mode.

str: .ascii /abc*/
end: .ascii /*/
count: .word 2

mov #str,r1
mov #end,r2
dec r2
mov count,r4
go: movb (r1),r3
movb -(r2),(r1)+
movb r3,(r2)
dec r4
bne go
halt
.end

;3.program to convert binary to decimal

arr: .word 1,0,0,0
count: .word 4
temp: .word 0

    .macro bnd r1
mov #1,r2
mov #2,r1
mul count,r1
l2: sub #2,r1
cmp #0,arr(r1)
beq l1
add r2,temp
l1: add r2,r2
cmp #0,r1
bne l2
.endm
main:    mov #1,r2
    bnd r1
    halt
    .end main

;4. program to convert binary to octal

arr: .word 0,1,0,0
cnt: .word 4
temp: .word 0

start: mov cnt,r0
clr r1
clr r3
jsr r7,octal
halt

octal: clr r5
l3: mov arr(r1),r5
cmp #cnt,r1
beq res
mov #8.,r3
cmp #1,r5
bne l1
mov r0,r2
cmp #0,r0
beq hlt
l2: add r3,r3
dec r2
bne l2
add r3,temp
clr r3
l1: dec r0
inc r1
inc r1
bne l3
hlt: add r5,temp
res: mov temp,r4
clr r2
rts r7
.end start

;5. program to sort elements using bubble sort

n: .word 5
arr: .word 6,7,5,4,0
start: mov n,r3
dec r3
loop1: mov r3,r4
mov #arr,r5
loop: mov (r5)+,r1
cmp (r5),r1
bgt down
mov r1,r2
mov (r5),r0
mov r0,-(r5)
inc r5
inc r5
mov r2,(r5)
down: dec r4
bne loop
dec r3
bne loop1
halt
.end start

;6. Design and implement the procedure search,getvalue,setvalue for a
; simple unordered linear table.

ARR: .WORD 10,20,30,40,50
EOA: .WORD 0
POS: .WORD 2
STAT: .WORD 2
VAL: .WORD 60

START: MOV #START,R6
CMP STAT,#2
BGT LOOP1
BLT LOOP2
JSR R7,STORE
HALT

LOOP1: CLR R1
MOV VAL,R2

L1: CMP R2,ARR(R1)
BEQ DONE
ADD #2,R1
CMP EOA,R1
BNE L1
MOV #0,POS
HALT

DONE: MOV R1,POS
HALT

LOOP2: MOV POS,R0
ASL R0
SUB #2,R0
MOV ARR(R0),R2
MOV R2,VAL
HALT

STORE: MOV POS,R1
ASL R1
SUB #2,R1
MOV VAL,ARR(R1)
HALT
RTS R7
.END START

;7. program to swap the contents of memory location

gon: jsr r5,swap

loc1: .word 2
loc2: .word 4
halt

swap: mov r5,r0
mov (r0)+,-(r6)
mov (r0)+,-(r6)
mov (r6)+,(r5)+
mov (r6)+,(r5)+
rts r5
.end gon

;8. program to reverse the bits of a memory location and store the result
; in another memory location.

count: .word 111100
res: .word 0

mov #16.,r2
    clr r0
    mov count,r1
clc
up:    ror r1
rol r0
    dec r2
    bne up
    mov r0,res
    halt
    .end

;9. To count the number of words that starts with a specific character in
; a given string.

N: .WORD 0
A: .ASCII /MAD MAN MAKES MAX MONEY0/
KEY: .ASCII /M0/

BG: MOV #A,R0
CMPB (R0),KEY
BNE LOOP
INC N
LOOP: INC R0
CMPB (R0),#0
BEQ ENDS
CMPB (R0),#40
BEQ CHECK
BR LOOP
CHECK: INC R0
CMPB (R0),#0
BEQ ENDS
CMPB (R0),KEY
BNE LOOP
INC N
BR LOOP
ENDS: HALT
.END BG

;10. Write a PDP 11 ALP to search for a substring in a given string.

pos: .word 0
str: .ascii /the string is long$/
key: .ascii /long$/
end: .ascii /$/

begin: mov #str,r0
mov #1,r3
l2: mov #key,r2
mov r0,r1
l1: cmpb (r1),(r2)
bne goon
inc r1
inc r2
cmp (r2),end
bne l1
dec r3
mov r3,pos
br over
goon: inc r0
inc r3
cmp (r0),end
bne l2
over: halt
.end begin


Back   PDP 11 ASSEMBLY LANGUAGE PROGRAMS

Download PDP 11 Assembler

[codeeverywhere.com]