Create a two-dimensional array at runtime: Difference between revisions

add task to arm assembly raspberry pi
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(add task to arm assembly raspberry pi)
Line 374:
 
To correct the last comment in the script above: when a script's run, the values of its properties, globals, and run-handler (''ie.'' top level) variables are saved back to the script file when the execution finishes. So variables containing bulky values like lists ideally ''should'' be set to something smaller before the end in order to prevent file bloat. Or local variables could be used, which would be the better option above as the <code>return</code> statement prevents the last line from being executed anyway.
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program createarray2.s */
 
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes */
/************************************/
.include "../constantes.inc"
.equ STDIN, 0 @ Linux input console
.equ READ, 3 @ Linux syscall
.equ BUFFERSIZE, 64
 
//.include "../../ficmacros32.inc"
 
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessRead1: .asciz "Input size level 1 : "
szMessRead2: .asciz "Input size level 2 : "
szMessIndice1: .asciz "Indice 1 ="
szMessIndice2: .asciz "Indice 2 ="
szMessResult: .asciz "Item = "
szMessStart: .asciz "Program 32 bits start.\n"
szCarriageReturn: .asciz "\n"
 
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip BUFFERSIZE // conversion buffer
sZoneConv1: .skip BUFFERSIZE // conversion buffer
sZoneConv2: .skip BUFFERSIZE // conversion buffer
sBuffer: .skip BUFFERSIZE
 
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
ldr r0,iAdrszMessStart
bl affichageMess
ldr r0,iAdrszMessRead1
bl affichageMess
mov r0,#STDIN @ Linux input console
ldr r1,iAdrsBuffer @ buffer address
mov r2,#BUFFERSIZE @ buffer size
mov r7,#READ @ request to read datas
svc 0 @ call system
ldr r0,iAdrsBuffer @ buffer address
bl conversionAtoD
mov r9,r0
ldr r0,iAdrszMessRead2
bl affichageMess
mov r0,#STDIN @ Linux input console
ldr r1,iAdrsBuffer @ buffer address
mov r2,#BUFFERSIZE @ buffer size
mov r7,#READ @ request to read datas
svc 0 @ call system
ldr r0,iAdrsBuffer @ buffer address
bl conversionAtoD
mov r10,r0
@ create array
lsl r12,r10,#2 @ compute size level 2
mul r8,r12,r9 @ compute size array
sub sp,sp,r8 @ reserve place on stack
mov fp,sp
mov r0,#0 @ init all items array
1: @ begin loop1
mov r1,#0
2: @ begin loop2
mul r2,r0,r12
add r2,r2,r1, lsl #2
str r2,[fp,r2] @ store shift in array item
add r1,r1,#1
cmp r1,r10
blt 2b
add r0,r0,#1
cmp r0,r9
blt 1b
mov r0,fp
mov r1,#1 @ second indice level 1
mov r2,#0 @ first indice level 2
mov r3,r12 @ level 2 size
bl displayItem
mov r0,fp
sub r1,r9,#1 @ last level 1
sub r2,r10,#1 @ last level 2
mov r3,r12 @ level 2 size
bl displayItem
 
add sp,sp,r8
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdrszCarriageReturn: .int szCarriageReturn
iAdrsZoneConv: .int sZoneConv
iAdrsZoneConv1: .int sZoneConv1
iAdrsZoneConv2: .int sZoneConv2
iAdrszMessRead1: .int szMessRead1
iAdrszMessRead2: .int szMessRead2
iAdrsBuffer: .int sBuffer
iAdrszMessResult: .int szMessResult
iAdrszMessStart: .int szMessStart
iAdrszMessIndice1: .int szMessIndice1
iAdrszMessIndice2: .int szMessIndice2
/***************************************************/
/* display array item */
/***************************************************/
/* r0 array address */
/* r1 indice 1 */
/* r2 indice 2 */
/* r3 level 2 size */
displayItem:
push {r1-r6,lr} @ save des registres
mov r5,r0
mov r6,r1
mov r0,r6
ldr r1,iAdrsZoneConv
bl conversion10 @ conversion indice 1
mov r0,r2
ldr r1,iAdrsZoneConv1
bl conversion10 @ conversion indice 2
mul r4,r6,r3 @ multiply indice level 1 by level 2 size
add r4,r4,r2, lsl #2 @ add indice level 2 * 4 (4 bytes)
ldr r0,[r5,r4] @ load array item
ldr r1,iAdrsZoneConv2
bl conversion10
mov r0,#7 @ string number to display
ldr r1,iAdrszMessIndice1
ldr r2,iAdrsZoneConv @ insert conversion in message
ldr r3,iAdrszMessIndice2
ldr r4,iAdrsZoneConv1 @ insert conversion in message
push {r4}
ldr r4,iAdrszMessResult
push {r4}
ldr r4,iAdrsZoneConv2 @ insert conversion in message
push {r4}
ldr r4,iAdrszCarriageReturn
push {r4}
bl displayStrings @ display message
add sp,sp,#16
100:
pop {r1-r6,pc}
/***************************************************/
/* display multi strings */
/***************************************************/
/* r0 contains number strings address */
/* r1 address string1 */
/* r2 address string2 */
/* r3 address string3 */
/* other address on the stack */
/* thinck to add number other address * 4 to add to the stack */
displayStrings: @ INFO: displayStrings
push {r1-r4,fp,lr} @ save des registres
add fp,sp,#24 @ save paraméters address (6 registers saved * 4 bytes)
mov r4,r0 @ save strings number
cmp r4,#0 @ 0 string -> end
ble 100f
mov r0,r1 @ string 1
bl affichageMess
cmp r4,#1 @ number > 1
ble 100f
mov r0,r2
bl affichageMess
cmp r4,#2
ble 100f
mov r0,r3
bl affichageMess
cmp r4,#3
ble 100f
mov r3,#3
sub r2,r4,#4
1: @ loop extract address string on stack
ldr r0,[fp,r2,lsl #2]
bl affichageMess
subs r2,#1
bge 1b
100:
pop {r1-r4,fp,pc}
 
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
{{Out}}
<pre>
Program 32 bits start.
Input size level 1 : 10
Input size level 2 : 5
Indice 1 =1 Indice 2 =0 Item = 20
Indice 1 =9 Indice 2 =4 Item = 196
</pre>
 
=={{header|Arturo}}==
79

edits