Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
264
Task/Visualize-a-tree/AArch64-Assembly/visualize-a-tree.aarch64
Normal file
264
Task/Visualize-a-tree/AArch64-Assembly/visualize-a-tree.aarch64
Normal file
|
|
@ -0,0 +1,264 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program displaytree64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
.equ HEAPSIZE, 50000
|
||||
.equ NBVAL, 9
|
||||
|
||||
/************************************/
|
||||
/* Macros */
|
||||
/************************************/
|
||||
//.include "../../ficmacros64.inc" // use for developper debugging
|
||||
|
||||
/*******************************************/
|
||||
/* Structures */
|
||||
/********************************************/
|
||||
/* structure tree */
|
||||
.struct 0
|
||||
tree_root: // root pointer
|
||||
.struct tree_root + 8
|
||||
tree_size: // number of element of tree
|
||||
.struct tree_size + 8
|
||||
tree_fin:
|
||||
/* structure node tree */
|
||||
.struct 0
|
||||
node_left: // left pointer
|
||||
.struct node_left + 8
|
||||
node_right: // right pointer
|
||||
.struct node_right + 8
|
||||
node_value: // element value
|
||||
.struct node_value + 8
|
||||
node_fin:
|
||||
/* structure queue*/
|
||||
|
||||
/*******************************************/
|
||||
/* Initialized data */
|
||||
/*******************************************/
|
||||
.data // INFO: data
|
||||
szMessDebutPgm: .asciz "Program 64 bits start. \n"
|
||||
szMessFinOK: .asciz "Program normal end. \n"
|
||||
szMessDisplayTree: .asciz "Tree display :\n"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
/* datas error display */
|
||||
szMessErreur: .asciz "Error detected.\n"
|
||||
/* datas message display */
|
||||
szMessResult: .ascii "Element value : @ \n"
|
||||
szIndent: .asciz "|-->"
|
||||
szIndent1: .asciz "| "
|
||||
.align 4
|
||||
ptHeapReserve: .quad heapReserve
|
||||
/*******************************************/
|
||||
/* UnInitialized data */
|
||||
/*******************************************/
|
||||
.bss // INFO: bss
|
||||
.align 4
|
||||
sConvArea: .skip 24
|
||||
stTree: .skip tree_fin // place to structure tree
|
||||
heapReserve: .skip HEAPSIZE
|
||||
/*******************************************/
|
||||
/* code section */
|
||||
/*******************************************/
|
||||
.text
|
||||
.global main
|
||||
main: // INFO: main
|
||||
ldr x0,qAdrszMessDebutPgm
|
||||
bl affichageMess
|
||||
mov x1,1 // node tree value
|
||||
1:
|
||||
ldr x0,qAdrstTree // structure tree address
|
||||
bl insertElement // add element value x1
|
||||
cmp x0,-1
|
||||
beq 99f
|
||||
add x1,x1,1 // increment value
|
||||
cmp x1,NBVAL // end ?
|
||||
ble 1b // no -> loop
|
||||
|
||||
ldr x0,qAdrszMessDisplayTree
|
||||
bl affichageMess
|
||||
ldr x3,qAdrstTree // tree root address (begin structure)
|
||||
ldr x0,[x3,#tree_root]
|
||||
mov x1,0 // level
|
||||
bl displayTree
|
||||
|
||||
ldr x0,qAdrszMessFinOK
|
||||
bl affichageMess
|
||||
b 100f
|
||||
99: // display error
|
||||
ldr x0,qAdrszMessErreur
|
||||
bl affichageMess
|
||||
100: // standard end of the program
|
||||
mov x8,EXIT // request to exit program
|
||||
svc 0 // perform system call
|
||||
qAdrszMessDebutPgm: .quad szMessDebutPgm
|
||||
qAdrszMessFinOK: .quad szMessFinOK
|
||||
qAdrszMessDisplayTree: .quad szMessDisplayTree
|
||||
qAdrszMessErreur: .quad szMessErreur
|
||||
qAdrszCarriageReturn: .quad szCarriageReturn
|
||||
qAdrstTree: .quad stTree
|
||||
qAdrdisplayElement: .quad displayElement
|
||||
/******************************************************************/
|
||||
/* insert element in the tree */
|
||||
/******************************************************************/
|
||||
/* x0 contains the address of the tree structure */
|
||||
/* x1 contains the value of element */
|
||||
/* x0 returns address of element or - 1 if error */
|
||||
insertElement: // INFO: insertElement
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
mov x4,x0
|
||||
mov x0,node_fin // reservation place one element
|
||||
bl allocHeap
|
||||
cmp x0,-1 // allocation error
|
||||
beq 100f
|
||||
mov x5,x0
|
||||
str x1,[x5,node_value] // store value in address heap
|
||||
mov x1,0
|
||||
str x1,[x5,node_left] // init left pointer with zero
|
||||
str x1,[x5,node_right] // init right pointer with zero
|
||||
ldr x2,[x4,tree_size] // load tree size
|
||||
cbnz x2,1f // 0 element ?
|
||||
str x5,[x4,tree_root] // yes -> store in root
|
||||
b 6f
|
||||
1: // else search free address in tree
|
||||
ldr x3,[x4,tree_root] // start with address root
|
||||
add x6,x2,1 // increment tree size
|
||||
clz x7,x6 // compute zeroes left bits
|
||||
add x7,x7,1 // for sustract the first left bit
|
||||
lsl x6,x6,x7 // shift number in left
|
||||
2:
|
||||
tst x6,1<<63 // test left bit
|
||||
lsl x6,x6,1 // shift left bit
|
||||
bne 3f // bit at one
|
||||
ldr x1,[x3,node_left] // no store node address in left pointer
|
||||
cbz x1,4f // if equal zero
|
||||
mov x3,x1 // else loop with next node
|
||||
b 2b
|
||||
3: // yes
|
||||
ldr x1,[x3,node_right] // store node address in right pointer
|
||||
cbz x1,5f // if equal zero
|
||||
mov x3,x1 // else loop with next node
|
||||
b 2b
|
||||
4:
|
||||
str x5,[x3,node_left]
|
||||
b 6f
|
||||
5:
|
||||
str x5,[x3,node_right]
|
||||
6:
|
||||
add x2,x2,1 // increment tree size
|
||||
str x2,[x4,tree_size]
|
||||
100:
|
||||
ldp x1,lr,[sp],16 // restaur 2 registers
|
||||
ret // return to address lr x30
|
||||
/******************************************************************/
|
||||
/* display tree */
|
||||
/******************************************************************/
|
||||
/* x0 contains the address of the tree */
|
||||
/* x1 level */
|
||||
displayTree:
|
||||
stp x2,lr,[sp,-16]! // save registers
|
||||
stp x3,x4,[sp,-16]! // save registers
|
||||
stp x5,x6,[sp,-16]!
|
||||
cmp x0,#-1
|
||||
beq 100f
|
||||
mov x4,x0
|
||||
mov x5,x1
|
||||
mov x2,#0
|
||||
ldr x3,qAdrszIndent1
|
||||
1:
|
||||
cmp x2,x1
|
||||
bge 2f
|
||||
mov x0,x3
|
||||
bl affichageMess
|
||||
add x2,x2,#1
|
||||
b 1b
|
||||
2:
|
||||
ldr x0,qAdrszIndent
|
||||
bl affichageMess
|
||||
ldr x0,[x4,#node_value]
|
||||
ldr x1,qAdrsConvArea
|
||||
bl conversion10S
|
||||
// ldr x0,qAdrsConvArea
|
||||
// bl shiftResult
|
||||
ldr x0,qAdrsConvArea
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszCarriageReturn
|
||||
bl affichageMess
|
||||
ldr x0,[x4,#node_left]
|
||||
cmp x0,#0
|
||||
beq 3f
|
||||
add x1,x5,#1 // increment level
|
||||
bl displayTree
|
||||
3:
|
||||
ldr x0,[x4,#node_right]
|
||||
cmp x0,#0
|
||||
beq 4f
|
||||
add x1,x5,#1 // increment level
|
||||
bl displayTree
|
||||
b 100f
|
||||
4:
|
||||
mov x0,#-1
|
||||
100:
|
||||
ldp x5,x6,[sp],16
|
||||
ldp x3,x4,[sp],16 // restaur 2 registers
|
||||
ldp x2,lr,[sp],16 // restaur 2 registers
|
||||
ret // return to address lr x30
|
||||
qAdrszIndent: .quad szIndent
|
||||
qAdrszIndent1: .quad szIndent1
|
||||
qAdrsConvArea: .quad sConvArea
|
||||
/******************************************************************/
|
||||
/* display node */
|
||||
/******************************************************************/
|
||||
/* x0 contains node address */
|
||||
displayElement:
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
ldr x0,[x0,#node_value]
|
||||
ldr x1,qAdrsConvArea
|
||||
bl conversion10S
|
||||
ldr x0,qAdrszMessResult
|
||||
ldr x1,qAdrsConvArea
|
||||
bl strInsertAtCharInc // insert result at @ character
|
||||
bl affichageMess
|
||||
100:
|
||||
ldp x1,lr,[sp],16 // restaur 2 registers
|
||||
ret // return to address lr x30
|
||||
qAdrszMessResult: .quad szMessResult
|
||||
|
||||
/******************************************************************/
|
||||
/* memory allocation on the heap */
|
||||
/******************************************************************/
|
||||
/* x0 contains the size to allocate */
|
||||
/* x0 returns address of memory heap or - 1 if error */
|
||||
/* CAUTION : The size of the allowance must be a multiple of 4 */
|
||||
allocHeap: // INFO: allocHeap
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
stp x2,x3,[sp,-16]!
|
||||
stp x4,x5,[sp,-16]!
|
||||
// allocation
|
||||
ldr x1,qAdrptHeapReserve
|
||||
ldr x2,[x1] // free heap address
|
||||
add x3,x2,x0 // reserve area on heap
|
||||
ldr x4,qAdrheapReserve
|
||||
mov x0,#HEAPSIZE
|
||||
add x4,x4,x0 // compute heap end
|
||||
cmp x3,x4
|
||||
blt 1f // allocation address < heap end ?
|
||||
mov x0,#-1 // allocation error
|
||||
b 100f
|
||||
1:
|
||||
str x3,[x1] // store new start free address heap
|
||||
mov x0,x2 // return address
|
||||
100:
|
||||
ldp x4,x5,[sp],16
|
||||
ldp x2,x3,[sp],16
|
||||
ldp x1,lr,[sp],16 // restaur 2 registers
|
||||
ret // return to address lr x30
|
||||
qAdrptHeapReserve: .quad ptHeapReserve
|
||||
qAdrheapReserve: .quad heapReserve
|
||||
/***********************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
283
Task/Visualize-a-tree/ARM-Assembly/visualize-a-tree.arm
Normal file
283
Task/Visualize-a-tree/ARM-Assembly/visualize-a-tree.arm
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program displaytree.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 */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes */
|
||||
/*******************************************/
|
||||
.include "../constantes.inc"
|
||||
.equ HEAPSIZE, 50000
|
||||
.equ NBVAL, 9
|
||||
/*******************************************/
|
||||
/* Macros */
|
||||
/*******************************************/
|
||||
//.include "../../ficmacros32.inc" @ for developer debugging
|
||||
|
||||
/*******************************************/
|
||||
/* Structures */
|
||||
/********************************************/
|
||||
/* structure tree */
|
||||
.struct 0
|
||||
tree_root: @ root pointer
|
||||
.struct tree_root + 4
|
||||
tree_size: @ number of element of tree
|
||||
.struct tree_size + 4
|
||||
tree_fin:
|
||||
/* structure node tree */
|
||||
.struct 0
|
||||
node_left: @ left pointer
|
||||
.struct node_left + 4
|
||||
node_right: @ right pointer
|
||||
.struct node_right + 4
|
||||
node_value: @ element value
|
||||
.struct node_value + 4
|
||||
node_fin:
|
||||
|
||||
/*******************************************/
|
||||
/* Initialized data */
|
||||
/*******************************************/
|
||||
.data
|
||||
szMessDebutPgm: .asciz "Program 32 bits start. \n"
|
||||
szMessFinOK: .asciz "Program normal end. \n"
|
||||
szMessDisplayTree: .asciz "Tree display :\n"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
/* datas error display */
|
||||
szMessErreur: .asciz "Error detected.\n"
|
||||
/* datas message display */
|
||||
szMessResult: .ascii "Element value :"
|
||||
sValue: .space 12,' '
|
||||
.asciz "\n"
|
||||
szIndent: .asciz "|-->"
|
||||
szIndent1: .asciz "| "
|
||||
.align 2
|
||||
ptHeapReserve: .int heapReserve
|
||||
/*******************************************/
|
||||
/* UnInitialized data */
|
||||
/*******************************************/
|
||||
.bss
|
||||
sConvArea: .skip 24
|
||||
stTree: .skip tree_fin @ place to structure tree
|
||||
heapReserve: .skip HEAPSIZE
|
||||
/*******************************************/
|
||||
/* code section */
|
||||
/*******************************************/
|
||||
.text
|
||||
.global main
|
||||
main:
|
||||
ldr r0,iAdrszMessDebutPgm
|
||||
bl affichageMess
|
||||
mov r1,#1 @ node tree value
|
||||
1:
|
||||
ldr r0,iAdrstTree @ structure tree address
|
||||
bl insertElement @ add element value r1
|
||||
cmp r0,#-1
|
||||
beq 99f
|
||||
add r1,#1 @ increment value
|
||||
cmp r1,#NBVAL @ end ?
|
||||
ble 1b @ no -> loop
|
||||
|
||||
ldr r0,iAdrszMessDisplayTree
|
||||
bl affichageMess
|
||||
ldr r3,iAdrstTree @ tree root address (begin structure)
|
||||
ldr r0,[r3,#tree_root]
|
||||
mov r1,#0
|
||||
bl displayTree
|
||||
|
||||
ldr r0,iAdrszMessFinOK
|
||||
bl affichageMess
|
||||
b 100f
|
||||
99: @ display error
|
||||
ldr r0,iAdrszMessErreur
|
||||
bl affichageMess
|
||||
100: @ standard end of the program
|
||||
mov r7, #EXIT @ request to exit program
|
||||
svc 0 @ perform system call
|
||||
iAdrszMessDebutPgm: .int szMessDebutPgm
|
||||
iAdrszMessFinOK: .int szMessFinOK
|
||||
iAdrszMessDisplayTree: .int szMessDisplayTree
|
||||
iAdrszMessErreur: .int szMessErreur
|
||||
iAdrszCarriageReturn: .int szCarriageReturn
|
||||
iAdrstTree: .int stTree
|
||||
iAdrdisplayElement: .int displayElement
|
||||
/******************************************************************/
|
||||
/* insert element in the tree */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the tree structure */
|
||||
/* r1 contains the value of element */
|
||||
/* r0 returns address of element or - 1 if error */
|
||||
insertElement:
|
||||
push {r1-r7,lr} @ save registers
|
||||
mov r4,r0
|
||||
mov r0,#node_fin @ reservation place one element
|
||||
bl allocHeap
|
||||
cmp r0,#-1 @ allocation error
|
||||
beq 100f
|
||||
mov r5,r0
|
||||
str r1,[r5,#node_value] @ store value in address heap
|
||||
mov r1,#0
|
||||
str r1,[r5,#node_left] @ init left pointer with zero
|
||||
str r1,[r5,#node_right] @ init right pointer with zero
|
||||
ldr r2,[r4,#tree_size] @ load tree size
|
||||
cmp r2,#0 @ 0 element ?
|
||||
bne 1f
|
||||
str r5,[r4,#tree_root] @ yes -> store in root
|
||||
b 4f
|
||||
1: @ else search free address in tree
|
||||
ldr r3,[r4,#tree_root] @ start with address root
|
||||
add r6,r2,#1 @ increment tree size
|
||||
clz r7,r6 @ compute zeroes left bits
|
||||
add r7,#1 @ for sustract the first left bit
|
||||
lsl r6,r7 @ shift number in left
|
||||
2:
|
||||
lsls r6,#1 @ read left bit
|
||||
bcs 3f @ is 1 ?
|
||||
ldr r1,[r3,#node_left] @ no store node address in left pointer
|
||||
cmp r1,#0 @ if equal zero
|
||||
streq r5,[r3,#node_left]
|
||||
beq 4f
|
||||
mov r3,r1 @ else loop with next node
|
||||
b 2b
|
||||
3: @ yes
|
||||
ldr r1,[r3,#node_right] @ store node address in right pointer
|
||||
cmp r1,#0 @ if equal zero
|
||||
streq r5,[r3,#node_right]
|
||||
beq 4f
|
||||
mov r3,r1 @ else loop with next node
|
||||
b 2b
|
||||
4:
|
||||
add r2,#1 @ increment tree size
|
||||
str r2,[r4,#tree_size]
|
||||
100:
|
||||
pop {r1-r7,pc} @ restaur registers
|
||||
|
||||
/******************************************************************/
|
||||
/* display node */
|
||||
/******************************************************************/
|
||||
/* r0 contains node address */
|
||||
displayElement:
|
||||
push {r1,lr} @ save registers
|
||||
ldr r0,[r0,#node_value]
|
||||
ldr r1,iAdrsValue
|
||||
bl conversion10S
|
||||
ldr r0,iAdrszMessResult
|
||||
bl affichageMess
|
||||
100:
|
||||
pop {r1,pc} @ restaur registers
|
||||
iAdrszMessResult: .int szMessResult
|
||||
iAdrsValue: .int sValue
|
||||
/******************************************************************/
|
||||
/* shift result to left */
|
||||
/******************************************************************/
|
||||
/* r0 contains conversion area */
|
||||
shiftResult: @ INFO: shiftResult
|
||||
push {r1-r3,lr} @ save registers
|
||||
mov r2,#0
|
||||
1:
|
||||
ldrb r1,[r0,r2] @ load one char
|
||||
cmp r1,#0 @ zero -> end
|
||||
beq 100f
|
||||
cmp r1,#' ' @ not space ?
|
||||
bne 2f
|
||||
add r2,r2,#1 @ else loop
|
||||
b 1b
|
||||
2:
|
||||
mov r3,#0 @ store indice
|
||||
3:
|
||||
strb r1,[r0,r3] @ store char in area begin
|
||||
cmp r1,#0 @ zero -> end
|
||||
beq 100f
|
||||
add r2,r2,#1 @ increment indices
|
||||
add r3,r3,#1
|
||||
ldrb r1,[r0,r2] @ load char
|
||||
b 3b @ and loop
|
||||
|
||||
100:
|
||||
pop {r1-r3,pc} @ restaur registers
|
||||
/******************************************************************/
|
||||
/* display tree */
|
||||
/******************************************************************/
|
||||
/* r0 contains node address */
|
||||
/* r1 contains level */
|
||||
|
||||
displayTree:
|
||||
push {r2-r5,lr} @ save registers
|
||||
cmp r0,#-1
|
||||
beq 100f
|
||||
mov r4,r0
|
||||
mov r5,r1
|
||||
mov r2,#0
|
||||
ldr r3,iAdrszIndent1
|
||||
1:
|
||||
cmp r2,r1
|
||||
bge 2f
|
||||
mov r0,r3
|
||||
bl affichageMess
|
||||
add r2,r2,#1
|
||||
b 1b
|
||||
2:
|
||||
ldr r0,iAdrszIndent
|
||||
bl affichageMess
|
||||
ldr r0,[r4,#node_value]
|
||||
ldr r1,iAdrsConvArea
|
||||
bl conversion10S
|
||||
ldr r0,iAdrsConvArea
|
||||
bl shiftResult
|
||||
ldr r0,iAdrsConvArea
|
||||
bl affichageMess
|
||||
ldr r0,iAdrszCarriageReturn
|
||||
bl affichageMess
|
||||
ldr r0,[r4,#node_left]
|
||||
cmp r0,#0
|
||||
beq 3f
|
||||
add r1,r5,#1 @ increment level
|
||||
bl displayTree
|
||||
3:
|
||||
ldr r0,[r4,#node_right]
|
||||
cmp r0,#0
|
||||
beq 4f
|
||||
add r1,r5,#1 @ increment level
|
||||
bl displayTree
|
||||
b 100f
|
||||
4:
|
||||
mov r0,#-1
|
||||
|
||||
100:
|
||||
pop {r2-r5,pc} @ restaur registers
|
||||
iAdrszIndent: .int szIndent
|
||||
iAdrszIndent1: .int szIndent1
|
||||
iAdrsConvArea: .int sConvArea
|
||||
/******************************************************************/
|
||||
/* memory allocation on the heap */
|
||||
/******************************************************************/
|
||||
/* r0 contains the size to allocate */
|
||||
/* r0 returns address of memory heap or - 1 if error */
|
||||
/* CAUTION : The size of the allowance must be a multiple of 4 */
|
||||
allocHeap:
|
||||
push {r1-r4,lr} @ save registers
|
||||
@ allocation
|
||||
ldr r1,iAdrptHeapReserve
|
||||
ldr r2,[r1] @ free heap address
|
||||
add r3,r2,r0 @ reserve area on heap
|
||||
ldr r4,iAdrheapReserve
|
||||
mov r0,#HEAPSIZE
|
||||
add r4,r4,r0 @ compute heap end
|
||||
cmp r3,r4
|
||||
blt 1f @ allocation address < heap end ?
|
||||
mov r0,#-1 @ allocation error
|
||||
b 100f
|
||||
1:
|
||||
str r3,[r1] @ store new start free address heap
|
||||
mov r0,r2 @ return address
|
||||
100:
|
||||
pop {r1-r4,pc} @ restaur registers
|
||||
.align 2
|
||||
iAdrptHeapReserve: .int ptHeapReserve
|
||||
iAdrheapReserve: .int heapReserve
|
||||
|
||||
/***************************************************/
|
||||
/* ROUTINES INCLUDE */
|
||||
/***************************************************/
|
||||
.include "../affichage.inc"
|
||||
36
Task/Visualize-a-tree/Ada/visualize-a-tree.adb
Normal file
36
Task/Visualize-a-tree/Ada/visualize-a-tree.adb
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
with Ada.Text_IO, Ada.Directories;
|
||||
|
||||
procedure Directory_Tree is
|
||||
|
||||
procedure Print_Tree(Current: String; Indention: Natural := 0) is
|
||||
|
||||
function Spaces(N: Natural) return String is
|
||||
(if N= 0 then "" else " " & Spaces(N-1));
|
||||
|
||||
use Ada.Directories;
|
||||
Search: Search_Type;
|
||||
Found: Directory_Entry_Type;
|
||||
|
||||
begin
|
||||
Start_Search(Search, Current, "");
|
||||
while More_Entries(Search) loop
|
||||
Get_Next_Entry(Search, Found);
|
||||
declare
|
||||
Name: String := Simple_Name(Found);
|
||||
Dir: Boolean := Kind(Found) = Directory;
|
||||
begin
|
||||
if Name(Name'First) /= '.' then
|
||||
-- skip all files who's names start with ".", namely "." and ".."
|
||||
Ada.Text_IO.Put_Line(Spaces(2*Indention) & Simple_Name(Found)
|
||||
& (if Dir then " (dir)" else ""));
|
||||
if Dir then
|
||||
Print_Tree(Full_Name(Found), Indention + 1);
|
||||
end if;
|
||||
end if;
|
||||
end;
|
||||
end loop;
|
||||
end Print_Tree;
|
||||
|
||||
begin
|
||||
Print_Tree(Ada.Directories.Current_Directory);
|
||||
end Directory_Tree;
|
||||
270
Task/Visualize-a-tree/RISC-V-Assembly/visualize-a-tree.asm
Normal file
270
Task/Visualize-a-tree/RISC-V-Assembly/visualize-a-tree.asm
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
# riscv assembly raspberry pico2 rp2350
|
||||
# program displaytree.s
|
||||
# connexion putty com3
|
||||
/*********************************************/
|
||||
/* CONSTANTES */
|
||||
/********************************************/
|
||||
/* for this file see risc-v task include a file */
|
||||
.include "../../constantesRiscv.inc"
|
||||
.equ HEAPSIZE, 50000
|
||||
.equ NBVAL, 9
|
||||
|
||||
/****************************************************/
|
||||
/* MACROS */
|
||||
/****************************************************/
|
||||
#.include "../ficmacrosriscv.inc" # for debugging only
|
||||
|
||||
/*******************************************/
|
||||
/* Structures */
|
||||
/********************************************/
|
||||
/* structure tree */
|
||||
.struct 0
|
||||
tree_root: # root pointer
|
||||
.struct tree_root + 4
|
||||
tree_size: # number of element of tree
|
||||
.struct tree_size + 4
|
||||
tree_fin:
|
||||
/* structure node tree */
|
||||
.struct 0
|
||||
node_left: # left pointer
|
||||
.struct node_left + 4
|
||||
node_right: # right pointer
|
||||
.struct node_right + 4
|
||||
node_value: # element value
|
||||
.struct node_value + 4
|
||||
node_fin:
|
||||
|
||||
|
||||
/*******************************************/
|
||||
/* INITIALED DATAS */
|
||||
/*******************************************/
|
||||
.data
|
||||
szMessStart: .asciz "Program riscv start.\r\n"
|
||||
szMessEnd: .asciz "\nProgram end OK.\r\n"
|
||||
szCariageReturn: .asciz "\r\n"
|
||||
szIndent: .asciz "|-->"
|
||||
szIndent1: .asciz "| "
|
||||
|
||||
szMessDisplayTree: .asciz "Tree display :\n"
|
||||
|
||||
szMessResult: .asciz "Element value : "
|
||||
.align 2
|
||||
ptHeapReserve: .int heapReserve
|
||||
|
||||
|
||||
.align 2
|
||||
/*******************************************/
|
||||
/* UNINITIALED DATA */
|
||||
/*******************************************/
|
||||
.bss
|
||||
.align 2
|
||||
sConvArea: .skip 24
|
||||
stTree: .skip tree_fin # place to structure tree
|
||||
heapReserve: .skip HEAPSIZE
|
||||
/********************************...-..--*****/
|
||||
/* SECTION CODE */
|
||||
/**********************************************/
|
||||
.text
|
||||
.global main
|
||||
|
||||
main: # INFO: main
|
||||
call stdio_init_all # général init
|
||||
1: # start loop connexion
|
||||
li a0,0 # raz argument register
|
||||
call tud_cdc_n_connected # waiting for USB connection
|
||||
beqz a0,1b # return code = zero ?
|
||||
|
||||
la a0,szMessStart # message address
|
||||
call writeString # display message
|
||||
li s0,1
|
||||
1:
|
||||
la a0,stTree
|
||||
mv a1,s0 # value
|
||||
call insertElement
|
||||
li t0,-1
|
||||
beq a0,t0,100f
|
||||
addi s0,s0,1
|
||||
li t0,NBVAL
|
||||
ble s0,t0,1b
|
||||
|
||||
la a0,szMessDisplayTree
|
||||
call writeString
|
||||
|
||||
la a0,stTree
|
||||
lw a0,tree_root(a0)
|
||||
li a1,0
|
||||
call displayTree
|
||||
|
||||
la a0,szMessEnd
|
||||
call writeString
|
||||
call getchar
|
||||
100: # final loop
|
||||
j 100b
|
||||
/******************************************************************/
|
||||
/* insert element in the tree */
|
||||
/******************************************************************/
|
||||
/* a0 contains the address of the tree structure */
|
||||
/* a1 contains the value of element */
|
||||
/* a0 returns address of element or - 1 if error */
|
||||
insertElement: # INFO: insertElement
|
||||
addi sp, sp, -8 # save registres
|
||||
sw ra, 0(sp)
|
||||
sw s0,4(sp)
|
||||
mv s0,a0
|
||||
li a0,node_fin # reservation place one element
|
||||
call allocHeap
|
||||
li t0,-1
|
||||
beq a0,t0,100f # allocation error
|
||||
mv t0,a0 # save address
|
||||
sw a1,node_value(t0) # store value in address heap
|
||||
sw x0,node_left(t0) # init left pointer with zero
|
||||
sw x0,node_right(t0) # init right pointer with zero
|
||||
lw t1,tree_size(s0) # load tree size
|
||||
bnez t1,1f # 0 element
|
||||
sw t0,tree_root(s0) # yes -> store in root
|
||||
j 4f
|
||||
1: # else search free address in tree
|
||||
lw t2,tree_root(s0) # start with address root
|
||||
mv t5,a1 # value node
|
||||
clz t3,t5 # compute zeroes left bits
|
||||
addi t3,t3,1 # for sustract the first left bit
|
||||
sll t5,t5,t3 # shift number in left
|
||||
2:
|
||||
slt t4,t5,x0 # is bit31 = 1
|
||||
slli t5,t5,1
|
||||
bnez t4,3f # is bit31 = 1
|
||||
lw t4,node_left(t2) # no store node address in left pointer
|
||||
bnez t4,21f # equal zero ?
|
||||
sw t0,node_left(t2)
|
||||
j 4f
|
||||
21:
|
||||
mv t2,t4 # else loop with next node
|
||||
j 2b
|
||||
3:
|
||||
lw t4,node_right(t2) # no store node address in right pointer
|
||||
bnez t4,31f # equal zero ?
|
||||
sw t0,node_right(t2)
|
||||
j 4f
|
||||
31:
|
||||
mv t2,t4 # else loop with next node
|
||||
j 2b # and loop
|
||||
4:
|
||||
addi t1,t1,1
|
||||
sw t1,tree_size(s0)
|
||||
mv a0,t0
|
||||
|
||||
100:
|
||||
lw ra, 0(sp)
|
||||
lw s0,4(sp)
|
||||
addi sp, sp, 8
|
||||
ret
|
||||
/******************************************************************/
|
||||
/* display node */
|
||||
/******************************************************************/
|
||||
/* a0 contains node address */
|
||||
displayElement: # INFO: displayElement
|
||||
addi sp, sp, -8 # reserve stack
|
||||
sw ra, 0(sp)
|
||||
sw s0,4(sp)
|
||||
lw a0,node_value(a0)
|
||||
la a1,sConvArea
|
||||
call conversion10S
|
||||
la a0,szMessResult
|
||||
call writeString
|
||||
la a0,sConvArea
|
||||
call writeString
|
||||
la a0,szCariageReturn
|
||||
call writeString
|
||||
100:
|
||||
lw ra, 0(sp)
|
||||
lw s0, 4(sp)
|
||||
addi sp, sp, 8
|
||||
ret
|
||||
/******************************************************************/
|
||||
/* Display tree */
|
||||
/******************************************************************/
|
||||
/* a0 contains tree address */
|
||||
/* a1 level */
|
||||
/* a0 returns 0 if empty else 1 */
|
||||
displayTree: # INFO: displayTree
|
||||
addi sp, sp, -20 # reserve stack
|
||||
sw ra, 0(sp)
|
||||
sw s0, 4(sp)
|
||||
sw s1, 8(sp)
|
||||
sw s2, 12(sp)
|
||||
sw s3, 16(sp)
|
||||
li t0,-1
|
||||
beq a0,t0,100f
|
||||
mv s0,a0
|
||||
mv s1,a1
|
||||
li s2,0
|
||||
la s3,szIndent1
|
||||
1: # display indentation loop
|
||||
bge s2,s1,2f
|
||||
mv a0,s3
|
||||
call writeString
|
||||
addi s2,s2,1
|
||||
j 1b
|
||||
2:
|
||||
la a0,szIndent
|
||||
call writeString
|
||||
# affregtit debut1
|
||||
lw a0,node_value(s0)
|
||||
la a1,sConvArea
|
||||
call conversion10S
|
||||
la a0,sConvArea
|
||||
call writeString
|
||||
la a0,szCariageReturn
|
||||
call writeString
|
||||
|
||||
lw a0,node_left(s0)
|
||||
beqz a0,3f
|
||||
addi a1,s1,1
|
||||
call displayTree
|
||||
3:
|
||||
lw a0,node_right(s0)
|
||||
beqz a0,4f
|
||||
addi a1,s1,1
|
||||
call displayTree
|
||||
j 100f
|
||||
4:
|
||||
li a0,-1
|
||||
|
||||
100:
|
||||
lw ra, 0(sp)
|
||||
lw s0, 4(sp)
|
||||
lw s1, 8(sp)
|
||||
lw s2, 12(sp)
|
||||
lw s3, 16(sp)
|
||||
addi sp, sp, 20
|
||||
/******************************************************************/
|
||||
/* memory allocation on the heap */
|
||||
/******************************************************************/
|
||||
/* a0 contains the size to allocate */
|
||||
/* a0 returns address of memory heap or - 1 if error */
|
||||
/* CAUTION : The size of the allowance must be a multiple of 4 */
|
||||
allocHeap: # INFO: allocHeap
|
||||
addi sp, sp, -8 # reserve stack
|
||||
sw ra, 0(sp)
|
||||
la t0,ptHeapReserve
|
||||
lw t1,(t0) # free heap address
|
||||
add t2,t1,a0 # reserve area on heap
|
||||
la t3,heapReserve
|
||||
li t4,HEAPSIZE
|
||||
add t3,t3,t4 # compute heap end
|
||||
blt t2,t3,1f # allocation address < heap end ?
|
||||
li a0,-1 # allocation error
|
||||
j 100f
|
||||
1:
|
||||
sw t2,(t0) # store new start free address heap
|
||||
mv a0,t1 # return address
|
||||
100:
|
||||
lw ra, 0(sp)
|
||||
addi sp, sp, 8
|
||||
ret
|
||||
|
||||
/************************************/
|
||||
/* file include Fonctions */
|
||||
/***********************************/
|
||||
/* for this file see risc-v task include a file */
|
||||
.include "../../includeFunctions.s"
|
||||
Loading…
Add table
Add a link
Reference in a new issue