Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
(→‎{{header|360 Assembly}}: Replaced my old vervion with a more structured one)
Line 27: Line 27:
=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
For maximum compatibility, this program uses only the basic instruction set.
For maximum compatibility, this program uses only the basic instruction set.
<lang 360 Assembly>* Bubble Sort
<lang 360 Assembly>* Bubble Sort 01/11/2014 & 23/06/2016
BUBBLE CSECT
BUBBLE CSECT
USING BUBBLE,R13,R12
USING BUBBLE,R13,R12 establish base registers
SAVEAREA B STM-SAVEAREA(R15) skip savearea
SAVEAREA B STM-SAVEAREA(R15) skip savearea
DC 17F'0'
DC 17F'0' my savearea
DC CL8'BUBBLE'
STM STM R14,R12,12(R13) save calling context
STM STM R14,R12,12(R13) save calling context
ST R13,4(R15) link mySA->prevSA
ST R13,4(R15)
ST R15,8(R13) link prevSA->mySA
ST R15,8(R13)
LR R13,R15 set mySA & set 4K addessability
LR R13,R15 set addessability
LA R12,2048(R13) .
LA R12,4095(R13)
LA R12,2048(R12) set 8K addessability
LA R12,1(R12)
L RN,N n
BCTR RN,0 n-1
MORE EQU *
LA R8,0 R8=no more
DO UNTIL=(LTR,RM,Z,RM) repeat ------------------------+
LA R1,A R1=Addr(A(I))
LA RM,0 more=false |
LA R2,2(R1) R2=Addr(A(I+1))
LA R1,A @a(i) |
LA R4,0 to start at 1
LA R2,4(R1) @a(i+1) |
LA R6,1 increment
LA RI,1 i=1 |
L R7,N R7=N
DO WHILE=(CR,RI,LE,RN) for i=1 to n-1 ------------+ |
BCTR R7,0 R7=N-1
L R3,0(R1) a(i) | |
LOOP BXH R4,R6,ENDLOOP for R4=1 to N-1
IF C,R3,GT,0(R2) if a(i)>a(i+1) then ---+ | |
LH R3,0(R1) R3=A(I)
L R9,0(R1) r9=a(i) | | |
CH R3,0(R2) A(I)::A(I+1)
L R3,0(R2) r3=a(i+1) | | |
BNH NOSWAP if A(I)<=A(I+1) then goto NOSWAP
ST R3,0(R1) a(i)=r3 | | |
LH R9,0(R1) R9=A(I)
ST R9,0(R2) a(i+1)=r9 | | |
LH R3,0(R2) R3=A(I+1)
LA RM,1 more=true | | |
STH R3,0(R1) A(I)=R3
ENDIF , end if <---------------+ | |
STH R9,0(R2) A(I+1)=R9
LA RI,1(RI) i=i+1 | |
LA R8,1 R8=more
LA R1,4(R1) next a(i) | |
LA R2,4(R2) next a(i+1) | |
NOSWAP EQU *
LA R1,2(R1) next A(I)
ENDDO , end for <------------------+ |
LA R2,2(R2) next A(I+1)
ENDDO , until not more <---------------+
B LOOP
LA R3,PG pgi=0
LA RI,1 i=1
ENDLOOP EQU *
LTR R8,R8
DO WHILE=(C,RI,LE,N) do i=1 to n -------+
BNZ MORE
LR R1,RI i |
LA R3,A R3=Addr(A(I))
SLA R1,2 . |
LA R4,0 to start at 1
L R2,A-4(R1) a(i) |
LA R6,1 increment
XDECO R2,XDEC edit a(i) |
L R7,N
MVC 0(4,R3),XDEC+8 output a(i) |
PRNT BXH R4,R6,ENDPRNT for R4=1 to N
LA R3,4(R3) pgi=pgi+4 |
LH R5,0(R3) R5=A(I)
LA RI,1(RI) i=i+1 |
CVD R4,P Store I to packed P
ENDDO , end do <-----------+
UNPK Z,P Z=P
XPRNT PG,L'PG print buffer
MVC C,Z C=Z
L R13,4(0,R13) restore caller savearea
OI C+L'C-1,X'F0' ZAP SIGN
LM R14,R12,12(R13) restore context
MVC BUFFER(4),C+12
XR R15,R15 set return code to 0
CVD R5,P Store A(I) to packed P
BR R14 return to caller
A DC F'4',F'65',F'2',F'-31',F'0',F'99',F'2',F'83',F'782',F'1'
UNPK Z,P Z=P
DC F'45',F'82',F'69',F'82',F'104',F'58',F'88',F'112',F'89',F'74'
MVC C,Z C=Z
OI C+L'C-1,X'F0' ZAP SIGN
N DC A((N-A)/L'A) number of items of a *
MVC BUFFER+10(6),C+10
PG DC CL80' '
WTO MF=(E,WTOMSG)
XDEC DS CL12
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 DS 0F
DC H'80' length of WTO buffer
DC H'0' must be binary zeroes
BUFFER DC 80C' '
LTORG
LTORG
YREGS
YREGS
RI EQU 6 i
RN EQU 7 n-1
RM EQU 8 more
END BUBBLE</lang>
END BUBBLE</lang>
{{out}}
{{out}}
<pre>
<pre style="height:20ex">0001 000006
-31 0 1 2 2 4 45 58 65 69 74 82 82 83 88 89 99 104 112 782
0002 000010
</pre>
0003 000018
0004 000035
0005 000050
0006 000081
0007 000091
0008 000100
0009 000135
0010 000142
0011 000174
0012 000192
0013 000195
0014 000198
0015 000206
0016 000211
0017 000223
0018 000230
0019 000242
0020 000249
0021 000259
0022 000261
0023 000278
0024 000282
0025 000293
0026 000303
0027 000332
0028 000351
0029 000353
0030 000356
0031 000356
0032 000358
0033 000433
0034 000436
0035 000443
0036 000474
0037 000498
0038 000503
0039 000520
0040 000523
0041 000536
0042 000539
0043 000539
0044 000552
0045 000558
0046 000565
0047 000582
0048 000644
0049 000653
0050 000664
0051 000665
0052 000701
0053 000716
0054 000728
0055 000735
0056 000771
0057 000780
0058 000780
0059 000782
0060 000794
0061 000796
0062 000802
0063 000807
0064 000820
0065 000836
0066 000845
0067 000848
0068 000856
0069 000861
0070 000880
0071 000894
0072 000904
0073 000913
0074 000919
0075 000927
0076 000942
0077 000949
0078 000982
0079 000986
0080 000997</pre>


=={{header|ACL2}}==
=={{header|ACL2}}==