360 Assembly
For maximum compatibility, this program uses only the basic instruction set.
* Bubble Sort
BUBBLE CSECT
USING BUBBLE,R13,R12
SAVEAREA B STM-SAVEAREA(R15) skip savearea
DC 17F'0'
DC CL8'BUBBLE'
STM STM R14,R12,12(R13) save calling context
ST R13,4(R15)
ST R15,8(R13)
LR R13,R15 set addessability
LA R12,4095(R13)
LA R12,1(R12)
MORE EQU *
LA R8,0 R8=no more
LA R1,A R1=Addr(A(I))
LA R2,2(R1) R2=Addr(A(I+1))
LA R4,0 to start at 1
LA R6,1 increment
L R7,N R7=N
BCTR R7,0 R7=N-1
LOOP BXH R4,R6,ENDLOOP for R4=1 to N-1
LH R3,0(R1) R3=A(I)
CH R3,0(R2) A(I)::A(I+1)
BNH NOSWAP if A(I)<=A(I+1) then goto NOSWAP
LH R9,0(R1) R9=A(I)
LH R3,0(R2) R3=A(I+1)
STH R3,0(R1) A(I)=R3
STH R9,0(R2) A(I+1)=R9
LA R8,1 R8=more
NOSWAP EQU *
LA R1,2(R1) next A(I)
LA R2,2(R2) next A(I+1)
B LOOP
ENDLOOP EQU *
LTR R8,R8
BNZ MORE
LA R3,A R3=Addr(A(I))
LA R4,0 to start at 1
LA R6,1 increment
L R7,N
PRNT BXH R4,R6,ENDPRNT for R4=1 to N
LH R5,0(R3) R5=A(I)
CVD R4,P Store I to packed P
UNPK Z,P Z=P
MVC C,Z C=Z
OI C+L'C-1,X'F0' ZAP SIGN
MVC BUFFER(4),C+12
CVD R5,P Store A(I) to packed P
UNPK Z,P Z=P
MVC C,Z C=Z
OI C+L'C-1,X'F0' ZAP SIGN
MVC BUFFER+10(6),C+10
WTO MF=(E,WTOMSG)
LA R3,2(R3) next A(I)
B PRNT

