Sorting algorithms/Bubble sort: Difference between revisions

Add 360 Assembly section
(Add 360 Assembly section)
Line 19:
* The article on [[wp:Bubble_sort|Wikipedia]].
* Dance [http://www.youtube.com/watch?v=lyZQPjUT5B4&feature=youtu.be interpretation].
 
=={{header|360 Assembly}}==
For maximum compatibility, this program use only the basic instruction set.
<lang 360 Assembly>* Bubble Sort for Rosetta Code - PG
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
ENDPRNT EQU *
CNOP 0,4
L R13,4(0,R13)
LM R14,R12,12(R13) restore context
XR R15,R15 set return code to 0
BR R14 return to caller
N DC A((AEND-A)/2) number of items in A, so N=F'80'
A DC H'223',H'356',H'018',H'820',H'664',H'845',H'927',H'198' 8
DC H'261',H'802',H'523',H'982',H'242',H'192',H'913',H'230' 16
DC H'353',H'565',H'195',H'174',H'665',H'807',H'050',H'539' 24
DC H'436',H'249',H'848',H'010',H'006',H'794',H'100',H'433' 32
DC H'782',H'728',H'259',H'358',H'206',H'081',H'701',H'997' 40
DC H'880',H'520',H'780',H'293',H'861',H'942',H'735',H'091' 48
DC H'503',H'582',H'716',H'836',H'135',H'653',H'856',H'142' 56
DC H'919',H'498',H'303',H'894',H'536',H'211',H'539',H'986' 64
DC H'356',H'796',H'644',H'552',H'771',H'443',H'035',H'780' 72
DC H'474',H'278',H'332',H'949',H'351',H'282',H'558',H'904' 80
AEND EQU *
P DS PL8 packed
Z DS ZL16 zoned
C DS CL16 character
WTOMSG CNOP 0,4
DC H'80' length of WTO buffer
DC H'0' must be binary zeroes
BUFFER DC 80C' '
LTORG
YREGS
END BUBBLE</lang>
 
=={{header|ACL2}}==
1,392

edits