Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

5
Task/Arrays/00-META.yaml Normal file
View file

@ -0,0 +1,5 @@
---
category:
- Simple
from: http://rosettacode.org/wiki/Arrays
note: Basic language learning

27
Task/Arrays/00-TASK.txt Normal file
View file

@ -0,0 +1,27 @@
This task is about arrays.
For hashes or associative arrays, please see [[Creating an Associative Array]].
For a definition and in-depth discussion of what an array is, see [[Array]].
;Task:
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and
dynamic arrays, pushing a value into it).
Please discuss at Village Pump:   {{vp|Arrays}}.
Please merge code in from these obsolete tasks:
:::*   [[Creating an Array]]
:::*   [[Assigning Values to an Array]]
:::*   [[Retrieving an Element of an Array]]
;Related tasks:
*   [[Collections]]
*   [[Creating an Associative Array]]
*   [[Two-dimensional array (runtime)]]
<br><br>

View file

@ -0,0 +1,14 @@
[Int] array
array.append(1)
array.append(3)
array[0] = 2
print(array[0]) // retrieve first element in an array
print(array.last) // retrieve last element in an array
print(array.pop()) // pop last item in an array
print(array.pop(0)) // pop first item in an array
V size = 10
V myArray = [0] * size // create single-dimensional array
V width = 3
V height = 4
V myArray2 = [[0] * width] * height // create array of arrays

View file

@ -0,0 +1,30 @@
* Arrays 04/09/2015
ARRAYS PROLOG
* we use TA array with 1 as origin. So TA(1) to TA(20)
* ta(i)=ta(j)
L R1,J j
BCTR R1,0 -1
SLA R1,2 r1=(j-1)*4 (*4 by shift left)
L R0,TA(R1) load r0 with ta(j)
L R1,I i
BCTR R1,0 -1
SLA R1,2 r1=(i-1)*4 (*4 by shift left)
ST R0,TA(R1) store r0 to ta(i)
EPILOG
* Array of 20 integers (32 bits) (4 bytes)
TA DS 20F
* Initialized array of 10 integers (32 bits)
TB DC 10F'0'
* Initialized array of 10 integers (32 bits)
TC DC F'1',F'2',F'3',F'4',F'5',F'6',F'7',F'8',F'9',F'10'
* Array of 10 integers (16 bits)
TD DS 10H
* Array of 10 strings of 8 characters (initialized)
TE DC 10CL8' '
* Array of 10 double precision floating point reals (64 bits)
TF DS 10D
*
I DC F'2'
J DC F'4'
YREGS
END ARRAYS

View file

@ -0,0 +1,2 @@
Array:
db 5,10,15,20,25,30,35,40,45,50

View file

@ -0,0 +1,2 @@
Array:
db 5,10,15,20,25,30,35,40,45,50

View file

@ -0,0 +1,11 @@
Array:
db 5
db 10
db 15
db 20
db 25
db 30
db 35
db 40
db 45
db 50

View file

@ -0,0 +1,6 @@
Array:
db 5,10
db 15,20
db 25,30
db 35,40
db 45,50

View file

@ -0,0 +1,6 @@
Array:
db 5,10
db 15,20
db 25,30
db 35,40
db 45,50

View file

@ -0,0 +1,8 @@
LDA #3 ;desired row
ASL A ;Times 2 bytes per row (if the array's row size wasn't a multiple of 2 we'd need to actually do multiplication)
;which the 6502 doesn't have in hardware but can be simulated by repeated adding.
CLC
ADC #1 ;desired column (since it's 1 byte per column, we can skip the part where we multiply desired column by bytes per column)
TAX ;move A to X so we can use it as the index
LDA Array,x ;evaluates to LDA #40

View file

@ -0,0 +1,5 @@
char foo()
{
char array[5] = {3,6,9,12,15};
return array[2];
}

View file

@ -0,0 +1,7 @@
foo:
LDX #2 ;load the desired index
LDA array,x ;load the second (zero-indexed) entry in array, i.e. 9
RTS ;return. The return value is stored in A.
array: ;this is the array we're reading from.
db 3,6,9,12,15

View file

@ -0,0 +1,3 @@
LDX #$80
LDA $80,x ;evaluates to LDA $00
LDA $0480,x ;evaluates to LDA $0500

View file

@ -0,0 +1,2 @@
wordArray:
dw $ABCD,$BEEF,$CAFE,$DADA

View file

@ -0,0 +1,2 @@
wordArray:
db $CD,$AB,$EF,$BE,$FE,$CA,$DA,$DA

View file

@ -0,0 +1,7 @@
LDX #2 ;load the 1st (zero-indexed) WORD from the array (which is why this is 2 not 1)
LDA wordArray,X ;evaluates to LDA #$EF
STA $00 ;store in a zero page temporary variable
INX ;point X to the high byte
LDA wordArray,X ;evaluates to LDA #$BE
STA $01 ;store in a different zero page temporary variable. If your word data is a pointer you want to dereference,
;you'll need to store the low byte in $nn and the high byte in $nn+1 like I did here.

View file

@ -0,0 +1,5 @@
wordArray_Lo:
db $CD,$EF,$FE,$DA
wordArray_Hi:
db $AB,$BE,$CA,$DA ;both this version and the above versions are 8 bytes of memory.

View file

@ -0,0 +1,5 @@
LDX #1 ;with split arrays we DON'T need to double our index.
LDA wordArray_Lo,x ;evaluates to LDA #$EF
STA $00
LDA wordArray_Hi,x ;evaluates to LDA #$BE
STA $01

View file

@ -0,0 +1 @@
MOVE.L #$00100000,A0 ;define an array at memory address $100000

View file

@ -0,0 +1,18 @@
;8-bit data
MyArray:
DC.B 1,2,3,4,5
DC.B 6,7,8,9,10
DC.B 11,12,13,14,15
EVEN ;needed to ensure proper alignment after a byte array with an odd number of entries.
;16-bit data
MyArrayW:
DC.W 1,2,3,4,5
DC.W 6,7,8,9,10
DC.W 11,12,13,14,15
;32-bit data
MyArrayL:
DC.L 1,2,3,4,5
DC.L 6,7,8,9,10
DC.L 11,12,13,14,15

View file

@ -0,0 +1,7 @@
MyString:
DC.B "Hello World",0
even
MyString2:
DC.B 'H','e','l','l','o',' ','W','o','r','l','d',0
even

View file

@ -0,0 +1,7 @@
myArray equ $240000
LEA myArray,A0 ;load the base address of the array into A0
MOVE.W #3,D0 ;load the desired offset into D0
LSL.W #2,D0 ;this array is intended for 32-bit values.
MOVE.L #23,D1 ;load decimal 23 into D1
MOVE.L D1,(A0,D0) ;store #23 into the 3rd slot of the array (arrays are zero-indexed in assembly)

View file

@ -0,0 +1,2 @@
int myArray[];
myArray[3] = 23;

View file

@ -0,0 +1,7 @@
myArray equ $240000
;load element 4
LEA myArray,A0 ;load the base address of the array into A0
MOVE.W #4,D0 ;load the desired offset into D0
LSL.W #2,D0 ;this array is intended for 32-bit values.
MOVE.L (A0,D0),D1 ;load the 4th element into D1.

View file

@ -0,0 +1,29 @@
myArray equ $240000
;insert a new element into the 2nd slot and push everything behind it back.
LEA myArray,A0 ;load the base address of the array into A0
MOVE.W #2,D0 ;offset into 2nd slot
LSL.W #2,D0 ;this array is intended for 32-bit values.
MOVE.L #46,D1 ;this is our new element.
MOVE.L (A0,D0),(4,A0,D0) ;store the 2nd element into the 3rd slot
ADDA.L #4,A0 ;increment to next slot.
MOVE.L (A0,D0),(4,A0,D0) ;store the 3nd element into the 4th slot
ADDA.L #4,A0 ;increment to next slot.
MOVE.L (A0,D0),(4,A0,D0) ;store the 4th element into the 5th slot
ADDA.L #4,A0 ;increment to next slot.
MOVE.L (A0,D0),(4,A0,D0) ;store the 5th element into the 6th slot
LEA myArray,A0 ;restore the base address
MOVE.L D1,(A0,D0) ;store the new 2nd element over the 2nd slot.
;for a larger array we can use the following loop:
MOVE.W #3,D2 ;array length minus starting offset minus 1
LOOP:
MOVE.L (A0,D0),(4,A0,D0)
ADDA.L #4,A0
DBRA D2,LOOP

View file

@ -0,0 +1,90 @@
; constant array (elements are unchangeable) - the array is stored in the CODE segment
myarray db 'Array' ; db = define bytes - initializes 5 bytes with values 41, 72, 72, etc. (the ascii characters A,r,r,a,y)
myarray2 dw 'A','r','r','a','y' ; dw = define words - initializes 5 words (1 word = 2 bytes) with values 41 00 , 72 00, 72 00, etc.
; how to read index a of the array
push acc
push dph
push dpl
mov dpl,#low(myarray) ; location of array
mov dph,#high(myarray)
movc a,@a+dptr ; a = element a
mov r0, a ; r0 = element a
pop dpl
pop dph
pop acc ; a = original index again
; array stored in internal RAM (A_START is the first register of the array, A_END is the last)
; initalise array data (with 0's)
push 0
mov r0, #A_START
clear:
mov @r0, #0
inc r0
cjne r0, #A_END, clear
pop 0
; how to read index r1 of array
push psw
mov a, #A_START
add a, r1 ; a = memory location of element r1
push 0
mov r0, a
mov a, @r0 ; a = element r1
pop 0
pop psw
; how to write value of acc into index r1 of array
push psw
push 0
push acc
mov a, #A_START
add a, r1
mov r0, a
pop acc
mov @r0, a ; element r1 = a
pop 0
pop psw
; array stored in external RAM (A_START is the first memory location of the array, LEN is the length)
; initalise array data (with 0's)
push dph
push dpl
push acc
push 0
mov dptr, #A_START
clr a
mov r0, #LEN
clear:
movx @dptr, a
inc dptr
djnz r0, clear
pop 0
pop acc
pop dpl
pop dph
; how to read index r1 of array
push dph
push dpl
push 0
mov dptr, #A_START-1
mov r0, r1
inc r0
loop:
inc dptr
djnz r0, loop
movx a, @dptr ; a = element r1
pop 0
pop dpl
pop dph
; how to write value of acc into index r1 of array
push dph
push dpl
push 0
mov dptr, #A_START-1
mov r0, r1
inc r0
loop:
inc dptr
djnz r0, loop
movx @dptr, a ; element r1 = a
pop 0
pop dpl
pop dph

View file

@ -0,0 +1,14 @@
[ 1 , 2 ,3 ] \ an array holding three numbers
1 a:@ \ this will be '2', the element at index 1
drop
1 123 a:@ \ this will store the value '123' at index 1, so now
. \ will print [1,123,3]
[1,2,3] 45 a:push
\ gives us [1,2,3,45]
\ and empty spots are filled with null:
[1,2,3] 5 15 a:!
\ gives [1,2,3,null,15]
\ arrays don't have to be homogenous:
[1,"one", 2, "two"]

View file

@ -0,0 +1,145 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program areaString64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessStringsch: .ascii "The string is at item : @ \n"
szCarriageReturn: .asciz "\n"
szMessStringNfound: .asciz "The string is not found in this area.\n"
/* areas strings */
szString1: .asciz "Apples"
szString2: .asciz "Oranges"
szString3: .asciz "Pommes"
szString4: .asciz "Raisins"
szString5: .asciz "Abricots"
/* pointer items area 1*/
tablesPoi1:
pt1_1: .quad szString1
pt1_2: .quad szString2
pt1_3: .quad szString3
pt1_4: .quad szString4
ptVoid_1: .quad 0
ptVoid_2: .quad 0
ptVoid_3: .quad 0
ptVoid_4: .quad 0
ptVoid_5: .quad 0
szStringSch: .asciz "Raisins"
szStringSch1: .asciz "Ananas"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
sZoneConv: .skip 30
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // entry of program
// add string 5 to area
ldr x1,qAdrtablesPoi1 // begin pointer area 1
mov x0,0 // counter
1: // search first void pointer
ldr x2,[x1,x0,lsl 3] // read string pointer address item x0 (4 bytes by pointer)
cmp x2,0 // is null ?
cinc x0,x0,ne // no increment counter
bne 1b // and loop
// store pointer string 5 in area at position x0
ldr x2,qAdrszString5 // address string 5
str x2,[x1,x0,lsl 3] // store address
// display string at item 3
mov x2,2 // pointers begin in position 0
ldr x1,qAdrtablesPoi1 // begin pointer area 1
ldr x0,[x1,x2,lsl 3]
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
// search string in area
ldr x1,qAdrszStringSch
//ldr x1,qAdrszStringSch1 // uncomment for other search : not found !!
ldr x2,qAdrtablesPoi1 // begin pointer area 1
mov x3,0
2: // search
ldr x0,[x2,x3,lsl 3] // read string pointer address item x0 (4 bytes by pointer)
cbz x0,3f // is null ? end search
bl comparString
cmp x0,0 // string = ?
cinc x3,x3,ne // no increment counter
bne 2b // and loop
mov x0,x3 // position item string
ldr x1,qAdrsZoneConv // conversion decimal
bl conversion10S
ldr x0,qAdrszMessStringsch
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at @ character
bl affichageMess
b 100f
3: // end search string not found
ldr x0,qAdrszMessStringNfound
bl affichageMess
100: // standard end of the program
mov x0, 0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrtablesPoi1: .quad tablesPoi1
qAdrszMessStringsch: .quad szMessStringsch
qAdrszString5: .quad szString5
qAdrszStringSch: .quad szStringSch
qAdrszStringSch1: .quad szStringSch1
qAdrsZoneConv: .quad sZoneConv
qAdrszMessStringNfound: .quad szMessStringNfound
qAdrszCarriageReturn: .quad szCarriageReturn
/************************************/
/* Strings comparaison */
/************************************/
/* x0 et x1 contains strings addresses */
/* x0 return 0 if equal */
/* return -1 if string x0 < string x1 */
/* return 1 if string x0 > string x1 */
comparString:
stp x2,lr,[sp,-16]! // save registers
stp x3,x4,[sp,-16]! // save registers
mov x2,#0 // indice
1:
ldrb w3,[x0,x2] // one byte string 1
ldrb w4,[x1,x2] // one byte string 2
cmp w3,w4
blt 2f // less
bgt 3f // greather
cmp w3,#0 // 0 final
beq 4f // equal and end
add x2,x2,#1 //
b 1b // else loop
2:
mov x0,#-1 // less
b 100f
3:
mov x0,#1 // greather
b 100f
4:
mov x0,#0 // equal
b 100f
100:
ldp x3,x4,[sp],16 // restaur 2 registers
ldp x2,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,13 @@
TYPES: tty_int TYPE STANDARD TABLE OF i
WITH NON-UNIQUE DEFAULT KEY.
DATA(itab) = VALUE tty_int( ( 1 )
( 2 )
( 3 ) ).
INSERT 4 INTO TABLE itab.
APPEND 5 TO itab.
DELETE itab INDEX 1.
cl_demo_output=>display( itab ).
cl_demo_output=>display( itab[ 2 ] ).

View file

@ -0,0 +1,15 @@
;; Create an array and store it in array-example
(assign array-example
(compress1 'array-example
(list '(:header :dimensions (10)
:maximum-length 11))))
;; Set a[5] to 22
(assign array-example
(aset1 'array-example
(@ array-example)
5
22))
;; Get a[5]
(aref1 'array-example (@ array-example) 5)

View file

@ -0,0 +1,33 @@
begin
comment arrays - Algol 60;
procedure static;
begin
integer array x[0:4];
x[0]:=10;
x[1]:=11;
x[2]:=12;
x[3]:=13;
x[4]:=x[0];
outstring(1,"static at 4: ");
outinteger(1,x[4]);
outstring(1,"\n")
end static;
procedure dynamic(n); value n; integer n;
begin
integer array x[0:n-1];
x[0]:=10;
x[1]:=11;
x[2]:=12;
x[3]:=13;
x[4]:=x[0];
outstring(1,"dynamic at 4: ");
outinteger(1,x[4]);
outstring(1,"\n")
end dynamic;
static;
dynamic(5)
end arrays

View file

@ -0,0 +1,20 @@
PROC array_test = VOID:
(
[1:20]INT a;
a := others; # assign whole array #
a[1] := -1; # assign individual element #
a[3:5] := (2, 4, -1); # assign a slice #
[1:3]INT slice = a[3:5]; # copy a slice #
REF []INT rslice = a[3:5]; # create a reference to a slice #
print((LWB rslice, UPB slice)); # query the bounds of the slice #
rslice := (2, 4, -1); # assign to the slice, modifying original array #
[1:3, 1:3]INT matrix; # create a two dimensional array #
REF []INT hvector = matrix[2,]; # create a reference to a row #
REF []INT vvector = matrix[,2]; # create a reference to a column #
REF [,]INT block = matrix[1:2, 1:2]; # create a reference to an area of the array #
FLEX []CHAR string := "Hello, world!"; # create an array with variable bounds #
string := "shorter" # flexible arrays automatically resize themselves on assignment #
)

View file

@ -0,0 +1,18 @@
begin
% declare an array %
integer array a ( 1 :: 10 );
% set the values %
for i := 1 until 10 do a( i ) := i;
% change the 3rd element %
a( 3 ) := 27;
% display the 4th element %
write( a( 4 ) ); % would show 4 %
% arrays with sizes not known at compile-time must be created in inner-blocks or procedures %
begin
integer array b ( a( 3 ) - 2 :: a( 3 ) ); % b has bounds 25 :: 27 %
for i := a( 3 ) - 2 until a( 3 ) do b( i ) := i
end
% arrays cannot be part of records and cannot be returned by procecures though they can be passed %
% as parameters to procedures %
% multi-dimension arrays are supported %
end.

View file

@ -0,0 +1,13 @@
/ Create an immutable sequence (array)
arr: <1;2;3>
/ Get the head an tail part
h: head[arr]
t: tail[arr]
/ Get everything except the last element and the last element
nl: first[arr]
l: last[arr]
/ Get the nth element (index origin = 0)
nth:arr[n]

View file

@ -0,0 +1 @@
+/ 1 2 3

View file

@ -0,0 +1 @@
1 + 2 + 3

View file

@ -0,0 +1 @@
+

View file

@ -0,0 +1 @@
1 2 3

View file

@ -0,0 +1,186 @@
/* ARM assembly Raspberry PI */
/* program areaString.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/* Initialized data */
.data
szMessStringsch: .ascii "The string is at item : "
sZoneconv: .fill 12,1,' '
szCarriageReturn: .asciz "\n"
szMessStringNfound: .asciz "The string is not found in this area.\n"
/* areas strings */
szString1: .asciz "Apples"
szString2: .asciz "Oranges"
szString3: .asciz "Pommes"
szString4: .asciz "Raisins"
szString5: .asciz "Abricots"
/* pointer items area 1*/
tablesPoi1:
pt1_1: .int szString1
pt1_2: .int szString2
pt1_3: .int szString3
pt1_4: .int szString4
ptVoid_1: .int 0
ptVoid_2: .int 0
ptVoid_3: .int 0
ptVoid_4: .int 0
ptVoid_5: .int 0
szStringSch: .asciz "Raisins"
szStringSch1: .asciz "Ananas"
/* UnInitialized data */
.bss
/* code section */
.text
.global main
main: /* entry of program */
push {fp,lr} /* saves 2 registers */
@@@@@@@@@@@@@@@@@@@@@@@@
@ add string 5 to area
@@@@@@@@@@@@@@@@@@@@@@@@
ldr r1,iAdrtablesPoi1 @ begin pointer area 1
mov r0,#0 @ counter
1: @ search first void pointer
ldr r2,[r1,r0,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
cmp r2,#0 @ is null ?
addne r0,#1 @ no increment counter
bne 1b @ and loop
@ store pointer string 5 in area at position r0
ldr r2,iAdrszString5 @ address string 5
str r2,[r1,r0,lsl #2] @ store address
@@@@@@@@@@@@@@@@@@@@@@@@
@ display string at item 3
@@@@@@@@@@@@@@@@@@@@@@@@
mov r2,#2 @ pointers begin in position 0
ldr r1,iAdrtablesPoi1 @ begin pointer area 1
ldr r0,[r1,r2,lsl #2]
bl affichageMess
ldr r0,iAdrszCarriageReturn
bl affichageMess
@@@@@@@@@@@@@@@@@@@@@@@@
@ search string in area
@@@@@@@@@@@@@@@@@@@@@@@@
ldr r1,iAdrszStringSch
//ldr r1,iAdrszStringSch1 @ uncomment for other search : not found !!
ldr r2,iAdrtablesPoi1 @ begin pointer area 1
mov r3,#0
2: @ search
ldr r0,[r2,r3,lsl #2] @ read string pointer address item r0 (4 bytes by pointer)
cmp r0,#0 @ is null ?
beq 3f @ end search
bl comparaison
cmp r0,#0 @ string = ?
addne r3,#1 @ no increment counter
bne 2b @ and loop
mov r0,r3 @ position item string
ldr r1,iAdrsZoneconv @ conversion decimal
bl conversion10S
ldr r0,iAdrszMessStringsch
bl affichageMess
b 100f
3: @ end search string not found
ldr r0,iAdrszMessStringNfound
bl affichageMess
100: /* standard end of the program */
mov r0, #0 @ return code
pop {fp,lr} @restaur 2 registers
mov r7, #EXIT @ request to exit program
swi 0 @ perform the system call
iAdrtablesPoi1: .int tablesPoi1
iAdrszMessStringsch: .int szMessStringsch
iAdrszString5: .int szString5
iAdrszStringSch: .int szStringSch
iAdrszStringSch1: .int szStringSch1
iAdrsZoneconv: .int sZoneconv
iAdrszMessStringNfound: .int szMessStringNfound
iAdrszCarriageReturn: .int szCarriageReturn
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {fp,lr} /* save registres */
push {r0,r1,r2,r7} /* save others registers */
mov r2,#0 /* counter length */
1: /* loop length calculation */
ldrb r1,[r0,r2] /* read octet start position + index */
cmp r1,#0 /* if 0 its over */
addne r2,r2,#1 /* else add 1 in the length */
bne 1b /* and loop */
/* so here r2 contains the length of the message */
mov r1,r0 /* address message in r1 */
mov r0,#STDOUT /* code to write to the standard output Linux */
mov r7, #WRITE /* code call system "write" */
swi #0 /* call systeme */
pop {r0,r1,r2,r7} /* restaur others registers */
pop {fp,lr} /* restaur des 2 registres */
bx lr /* return */
/***************************************************/
/* conversion register signed décimal */
/***************************************************/
/* r0 contient le registre */
/* r1 contient l adresse de la zone de conversion */
conversion10S:
push {r0-r5,lr} /* save des registres */
mov r2,r1 /* debut zone stockage */
mov r5,#'+' /* par defaut le signe est + */
cmp r0,#0 /* nombre négatif ? */
movlt r5,#'-' /* oui le signe est - */
mvnlt r0,r0 /* et inversion en valeur positive */
addlt r0,#1
mov r4,#10 /* longueur de la zone */
1: /* debut de boucle de conversion */
bl divisionpar10 /* division */
add r1,#48 /* ajout de 48 au reste pour conversion ascii */
strb r1,[r2,r4] /* stockage du byte en début de zone r5 + la position r4 */
sub r4,r4,#1 /* position précedente */
cmp r0,#0
bne 1b /* boucle si quotient different de zéro */
strb r5,[r2,r4] /* stockage du signe à la position courante */
subs r4,r4,#1 /* position précedente */
blt 100f /* si r4 < 0 fin */
/* sinon il faut completer le debut de la zone avec des blancs */
mov r3,#' ' /* caractere espace */
2:
strb r3,[r2,r4] /* stockage du byte */
subs r4,r4,#1 /* position précedente */
bge 2b /* boucle si r4 plus grand ou egal a zero */
100: /* fin standard de la fonction */
pop {r0-r5,lr} /*restaur desregistres */
bx lr
/***************************************************/
/* division par 10 signé */
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
/* and http://www.hackersdelight.org/ */
/***************************************************/
/* r0 contient le dividende */
/* r0 retourne le quotient */
/* r1 retourne le reste */
divisionpar10:
/* r0 contains the argument to be divided by 10 */
push {r2-r4} /* save registers */
mov r4,r0
ldr r3, .Ls_magic_number_10 /* r1 <- magic_number */
smull r1, r2, r3, r0 /* r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0) */
mov r2, r2, ASR #2 /* r2 <- r2 >> 2 */
mov r1, r0, LSR #31 /* r1 <- r0 >> 31 */
add r0, r2, r1 /* r0 <- r2 + r1 */
add r2,r0,r0, lsl #2 /* r2 <- r0 * 5 */
sub r1,r4,r2, lsl #1 /* r1 <- r4 - (r2 * 2) = r4 - (r0 * 10) */
pop {r2-r4}
bx lr /* leave function */
bx lr /* leave function */
.Ls_magic_number_10: .word 0x66666667

View file

@ -0,0 +1,30 @@
BEGIN {
# to make an array, assign elements to it
array[1] = "first"
array[2] = "second"
array[3] = "third"
alen = 3 # want the length? store in separate variable
# or split a string
plen = split("2 3 5 7 11 13 17 19 23 29", primes)
clen = split("Ottawa;Washington DC;Mexico City", cities, ";")
# retrieve an element
print "The 6th prime number is " primes[6]
# push an element
cities[clen += 1] = "New York"
dump("An array", array, alen)
dump("Some primes", primes, plen)
dump("A list of cities", cities, clen)
}
function dump(what, array, len, i) {
print what;
# iterate an array in order
for (i = 1; i <= len; i++) {
print " " i ": " array[i]
}
}

View file

@ -0,0 +1,60 @@
PROC Main()
BYTE i
;array storing 4 INT items with initialized values
;negative values must be written as 16-bit unsigned numbers
INT ARRAY a=[3 5 71 65535]
;array storing 4 CARD items whithout initialization of values
CARD ARRAY b(3)
;array of BYTE items without allocation,
;it may be used as an pointer for another array
BYTE ARRAY c
;array of 1+7 CHAR items or a string
;the first item stores length of the string
CHAR ARRAY s="abcde"
PrintE("Array with initialized values:")
FOR i=0 TO 3
DO
PrintF("a(%I)=%I ",i,a(i))
OD
PutE() PutE()
PrintE("Array before initialization of items:")
FOR i=0 TO 3
DO
PrintF("b(%I)=%B ",i,b(i))
OD
PutE() PutE()
FOR i=0 TO 3
DO
b(i)=100+i
OD
PrintE("After initialization:")
FOR i=0 TO 3
DO
PrintF("b(%I)=%B ",i,b(i))
OD
PutE() PutE()
PrintE("Array of chars. The first item stores the length of string:")
FOR i=0 TO s(0)
DO
PrintF("s(%B)='%C ",i,s(i))
OD
PutE() PutE()
PrintE("As the string:")
PrintF("s=""%S""%E%E",s)
c=s
PrintE("Unallocated array as a pointer to another array. In this case c=s:")
FOR i=0 TO s(0)
DO
PrintF("c(%B)=%B ",i,c(i))
OD
RETURN

View file

@ -0,0 +1,16 @@
//creates an array of length 10
var array1:Array = new Array(10);
//creates an array with the values 1, 2
var array2:Array = new Array(1,2);
//arrays can also be set using array literals
var array3:Array = ["foo", "bar"];
//to resize an array, modify the length property
array2.length = 3;
//arrays can contain objects of multiple types.
array2[2] = "Hello";
//get a value from an array
trace(array2[2]);
//append a value to an array
array2.push(4);
//get and remove the last element of an array
trace(array2.pop());

View file

@ -0,0 +1,43 @@
procedure Array_Test is
A, B : array (1..20) of Integer;
-- Ada array indices may begin at any value, not just 0 or 1
C : array (-37..20) of integer
-- Ada arrays may be indexed by enumerated types, which are
-- discrete non-numeric types
type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
type Activities is (Work, Fish);
type Daily_Activities is array(Days) of Activities;
This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);
-- Or any numeric type
type Fingers is range 1..4; -- exclude thumb
type Fingers_Extended_Type is array(fingers) of Boolean;
Fingers_Extended : Fingers_Extended_Type;
-- Array types may be unconstrained. The variables of the type
-- must be constrained
type Arr is array (Integer range <>) of Integer;
Uninitialized : Arr (1 .. 10);
Initialized_1 : Arr (1 .. 20) := (others => 1);
Initialized_2 : Arr := (1 .. 30 => 2);
Const : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
Centered : Arr (-50..50) := (0 => 1, Others => 0);
Result : Integer
begin
A := (others => 0); -- Assign whole array
B := (1 => 1, 2 => 1, 3 => 2, others => 0);
-- Assign whole array, different values
A (1) := -1; -- Assign individual element
A (2..4) := B (1..3); -- Assign a slice
A (3..5) := (2, 4, -1); -- Assign a constant slice
A (3..5) := A (4..6); -- It is OK to overlap slices when assigned
Fingers_Extended'First := False; -- Set first element of array
Fingers_Extended'Last := False; -- Set last element of array
end Array_Test;

View file

@ -0,0 +1,15 @@
var arr1 = [1,2,3,4] // initialize with array literal
var arr2 = new [10] // empty array of 10 elements (each element has value none)
var arr3 = new int [40] // array of 40 integers
var arr4 = new Object (1,2) [10] // array of 10 instances of Object
arr1.append (5) // add to array
var b = 4 in arr1 // check for inclusion
arr1 <<= 2 // remove first 2 elements from array
var arrx = arr1[1:3] // get slice of array
var s = arr1.size() // or sizeof(arr1)
delete arr4[2] // remove an element from an array
var arr5 = arr1 + arr2 // append arrays
var arr6 = arr1 | arr2 // union
var arr7 = arr1 & arr2 // intersection

View file

@ -0,0 +1 @@
list l;

View file

@ -0,0 +1,3 @@
l_append(l, 3);
l_append(l, "arrays");
l_append(l, pow);

View file

@ -0,0 +1,2 @@
l_push(l, 3, .5);
l_push(l, 4, __type(l));

View file

@ -0,0 +1,2 @@
l_p_integer(l, 5, -1024);
l_p_real(l, 6, 88);

View file

@ -0,0 +1 @@
l_query(l, 5);

View file

@ -0,0 +1,2 @@
l_q_real(l, 6);
l_q_text(l, 1);

View file

@ -0,0 +1,17 @@
DEF ai[100] : ARRAY OF CHAR, -> static
da: PTR TO CHAR,
la: PTR TO CHAR
PROC main()
da := New(100)
-> or
NEW la[100]
IF da <> NIL
ai[0] := da[0] -> first is 0
ai[99] := da[99] -> last is "size"-1
Dispose(da)
ENDIF
-> using NEW, we must specify the size even when
-> "deallocating" the array
IF la <> NIL THEN END la[100]
ENDPROC

View file

@ -0,0 +1,3 @@
Integer[] array = new Integer[10]; // optionally, append a braced list of Integers like "{1, 2, 3}"
array[0] = 42;
System.debug(array[0]); // Prints 42

View file

@ -0,0 +1,4 @@
List <Integer> aList = new List <Integer>(); // optionally add an initial size as an argument
aList.add(5);// appends to the end of the list
aList.add(1, 6);// assigns the element at index 1
System.debug(list[0]); // Prints 5, alternatively you can use list.get(0)

View file

@ -0,0 +1,2 @@
set empty to {}
set ints to {1, 2, 3}

View file

@ -0,0 +1,7 @@
use AppleScript version "2.4" -- Mac OS 10.10 (Yosemite) or later.
use framework "Foundation" -- Allows access to NSArrays and other Foundation classes.
set myList to {1, "foo", 2.57, missing value, {1, 2, 3}} -- AppleScript list.
set myNSArray to current application's NSArray's arrayWithArray:myList -- Bridge the list to an NSArray.
set arrayLength to myNSArray's |count|() -- Get the array's length using its 'count' property.
--> 5

View file

@ -0,0 +1 @@
set any to {1, "foo", 2.57, missing value, ints}

View file

@ -0,0 +1,5 @@
set any to {1, "foo", 2.57, missing value, {1, 2, 3}}
set beginning of any to false
set end of any to Wednesday
return any
--> {false, 1, "foo", 2.57, missing value, {1, 2, 3}, Wednesday}

View file

@ -0,0 +1,3 @@
set any to {1, "foo", 2.57, missing value, {1, 2, 3}}
set any to false & any & Wednesday
--> {false, 1, "foo", 2.57, missing value, {1, 2, 3}, Wednesday}

View file

@ -0,0 +1,3 @@
set any to {1, "foo", 2.57, missing value, {1, 2, 3}}
item -1 of any --> {1, 2, 3}
items 1 thru 3 of any --> {1, "foo", 2.57}

View file

@ -0,0 +1,2 @@
set any to {false, 1, "foo", 2.57, missing value, {1, 2, 3}, Wednesday}
number 2 of any -- 2.57 (ie. the second number in the list)

View file

@ -0,0 +1,2 @@
set any to {false, 1, "foo", 2.57, missing value, 5, 4, 12.0, 38, {1, 2, 3}, 7, Wednesday}
integers from text 1 to list 1 of any --> {5, 4, 38}

View file

@ -0,0 +1,3 @@
count any -- Command.
length of any -- Property.
number of any -- Property.

View file

@ -0,0 +1,2 @@
count any's reals
length of any's integers

View file

@ -0,0 +1,4 @@
10 DIM A%(11): REM ARRAY OF TWELVE INTEGER ELEMENTS
20 LET A%(0) = -1
30 LET A%(11) = 1
40 PRINT A%(0), A%(11)

View file

@ -0,0 +1,31 @@
use std, array
(:::::::::::::::::
: Static arrays :
:::::::::::::::::)
let the array of 2 text aabbArray be Cdata{"aa";"bb"}
let raw array of real :my array: = Cdata {1.0 ; 2.0 ; 3.0} (: auto sized :)
let another_array be an array of 256 byte (: not initialised :)
let (raw array of (array of 3 real)) foobar = Cdata {
{1.0; 2.0; 0.0}
{5.0; 1.0; 3.0}
}
(: macro to get size of static arrays :)
=: <array>.length := -> nat {size of array / (size of array[0])}
printf "%lu, %lu\n" foobar.length (another_array.length) (: 2, 256 :)
(: access :)
another_array[255] = '&'
printf "`%c'\n" another_array[255]
(::::::::::::::::::
: Dynamic arrays :
::::::::::::::::::)
let DynArray = new array of 5 int
DynArray[0] = -42
DynArray = (realloc DynArray (6 * size of DynArray[0])) as (type of DynArray)
DynArray[5] = 243
prints DynArray[0] DynArray[5]
del DynArray

View file

@ -0,0 +1,4 @@
use std, array
let x = @["foo" "bar" "123"]
print x[2]
x[2] = "abc"

View file

@ -0,0 +1,16 @@
; empty array
arrA: []
; array with initial values
arrB: ["one" "two" "three"]
; adding an element to an existing array
arrB: arrB ++ "four"
print arrB
; another way to add an element
append 'arrB "five"
print arrB
; retrieve an element at some index
print arrB\1

View file

@ -0,0 +1,7 @@
myArray := Object() ; could use JSON-syntax sugar like {key: value}
myArray[1] := "foo"
myArray[2] := "bar"
MsgBox % myArray[2]
; Push a value onto the array
myArray.Insert("baz")

View file

@ -0,0 +1,11 @@
arrayX0 = 4 ; length
arrayX1 = first
arrayX2 = second
arrayX3 = foo
arrayX4 = bar
Loop, %arrayX0%
Msgbox % arrayX%A_Index%
source = apple bear cat dog egg fish
StringSplit arrayX, source, %A_Space%
Loop, %arrayX0%
Msgbox % arrayX%A_Index%

View file

@ -0,0 +1,14 @@
#include <Array.au3> ;Include extended Array functions (_ArrayDisplay)
Local $aInputs[1] ;Create the Array with just 1 element
While True ;Endless loop
$aInputs[UBound($aInputs) - 1] = InputBox("Array", "Add one value") ;Save user input to the last element of the Array
If $aInputs[UBound($aInputs) - 1] = "" Then ;If an empty string is entered, then...
ReDim $aInputs[UBound($aInputs) - 1] ;...remove them from the Array and...
ExitLoop ;... exit the loop!
EndIf
ReDim $aInputs[UBound($aInputs) + 1] ;Add an empty element to the Array
WEnd
_ArrayDisplay($aInputs) ;Display the Array

View file

@ -0,0 +1 @@
tup ::= <"aardvark", "cat", "dog">;

View file

@ -0,0 +1,2 @@
<"pinch", "tsp", "tbsp", "cup">[4] \\ "cup"
<3, 2, 1>[100] else [0]

View file

@ -0,0 +1 @@
<"sheep", "wheat", "wood", "brick", "stone">[5] → "ore"

View file

@ -0,0 +1,8 @@
1→{L₁}
2→{L₁+1}
3→{L₁+2}
4→{L₁+3}
Disp {L₁}►Dec,i
Disp {L₁+1}►Dec,i
Disp {L₁+2}►Dec,i
Disp {L₁+3}►Dec,i

View file

@ -0,0 +1,2 @@
OPTION BASE 1
DIM myArray(100) AS INTEGER

View file

@ -0,0 +1 @@
DIM myArray(-10 TO 10) AS INTEGER

View file

@ -0,0 +1,6 @@
'Specify that the array is dynamic and not static:
'$DYNAMIC
DIM SHARED myArray(-10 TO 10, 10 TO 30) AS STRING
REDIM SHARED myArray(20, 20) AS STRING
myArray(1,1) = "Item1"
myArray(1,2) = "Item2"

View file

@ -0,0 +1,6 @@
DIM month$(12)
DATA January, February, March, April, May, June, July
DATA August, September, October, November, December
FOR m=1 TO 12
READ month$(m)
NEXT m

View file

@ -0,0 +1 @@
Dim myArray(1 To 2, 1 To 5) As Integer => {{1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}}

View file

@ -0,0 +1,7 @@
10 REM TRANSLATION OF QBASIC STATIC VERSION
20 REM ELEMENT NUMBERS TRADITIONALLY START AT ONE
30 DIM A%(11): REM ARRAY OF ELEVEN INTEGER ELEMENTS
40 LET A%(1) = -1
50 LET A%(11) = 1
60 PRINT A%(1), A%(11)
70 END

View file

@ -0,0 +1,6 @@
DIM staticArray(10) AS INTEGER
staticArray(0) = -1
staticArray(10) = 1
PRINT staticArray(0), staticArray(10)

View file

@ -0,0 +1,9 @@
REDIM dynamicArray(10) AS INTEGER
dynamicArray(0) = -1
PRINT dynamicArray(0)
REDIM dynamicArray(20)
dynamicArray(20) = 1
PRINT dynamicArray(0), dynamicArray(20)

View file

@ -0,0 +1,29 @@
# numeric array
dim numbers(10)
for t = 0 to 9
numbers[t] = t + 1
next t
# string array
dim words$(10)
# assigning an array with a list
words$ = {"one","two","three","four","five","six","seven","eight","nine","ten"}
gosub display
# resize arrays (always preserves values if larger)
redim numbers(11)
redim words$(11)
numbers[10] = 11
words$[10] = "eleven"
gosub display
end
display:
# display arrays
# using ? to get size of array
for t = 0 to numbers[?]-1
print numbers[t] + "=" + words$[t]
next t
return

View file

@ -0,0 +1,17 @@
REM Declare arrays, dimension is maximum index:
DIM array(6), array%(6), array$(6)
REM Entire arrays may be assigned in one statement:
array() = 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7
array%() = 0, 1, 2, 3, 4, 5, 6
array$() = "Zero", "One", "Two", "Three", "Four", "Five", "Six"
REM Or individual elements may be assigned:
array(2) = PI
array%(3) = RND
array$(4) = "Hello world!"
REM Print out sample array elements:
PRINT array(2) TAB(16) array(3) TAB(32) array(4)
PRINT array%(2) TAB(16) array%(3) TAB(32) array%(4)
PRINT array$(2) TAB(16) array$(3) TAB(32) array$(4)

View file

@ -0,0 +1,11 @@
% Define an array(containing the numbers 1-3) named arr in the group $
in $ let arr hold 1 2 3
% Replace the value at index 0 in array to "Index 0"
set $arr index 0 to "Index 0"
% Will display "Index 0"
display $arr index 0
% There is no automatic garbage collection
delete $arr

View file

@ -0,0 +1,13 @@
# Stranding:
arr 12'a'+5
# General List Syntax:
arr1 1,2,'a',+,5
•Show arr arr1 # both arrays are the same.
•Show arr
•Show arr1
# Taking nth element(⊑):
•Show 3arr
# Modifying the array(↩):
arr "hello"(4) arr

View file

@ -0,0 +1,5 @@
1
1 2 'a' + 5
1 2 'a' + 5
+
1 2 'a' + "hello"

View file

@ -0,0 +1,8 @@
DATA "January", "February", "March", "April", "May", "June", "July"
DATA "August", "September", "October", "November", "December"
LOCAL dat$[11]
FOR i = 0 TO 11
READ dat$[i]
PRINT dat$[i]
NEXT

View file

@ -0,0 +1,9 @@
DECLARE A$[11] = {"January", "February", "March", "April", "May", \
"June", "July", "August", "September", "October", "November", "December"} TYPE STRING
i = 0
'---dynamic index the end of an array is always null terminated
WHILE (A$[i] ISNOT NULL)
PRINT A$[i]
INCR i
WEND

View file

@ -0,0 +1,5 @@
SPLIT ARGUMENT$ BY " " TO TOK$ SIZE len_array
FOR i = 1 TO len_array - 1
PRINT TOK$[i]
NEXT i

View file

@ -0,0 +1 @@
./split January February March April May June July August September October November December

View file

@ -0,0 +1 @@
[1 2 3]

View file

@ -0,0 +1 @@
(1 2 3) ls2lf ;

View file

@ -0,0 +1 @@
[ptr 'foo' 'bar' 'baz'] ar2ls lsstr !

View file

@ -0,0 +1 @@
(1 2 3) bons ;

View file

@ -0,0 +1 @@
[ptr 1 2 3]

View file

@ -0,0 +1 @@
[1 2 3] 1 th ;

View file

@ -0,0 +1 @@
[1 2 3] dup 1 7 set ;

View file

@ -0,0 +1 @@
[ptr 1 2 3] dup 1 [ptr 7] set ;

View file

@ -0,0 +1 @@
[ptr 1 2 3 4 5 6] 1 3 slice ;

Some files were not shown because too many files have changed in this diff Show more