144 lines
4.9 KiB
Text
144 lines
4.9 KiB
Text
/* ARM assembly Raspberry PI */
|
|
/* program arrayHash.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"
|
|
|
|
/*******************************************/
|
|
/* Macros */
|
|
/*******************************************/
|
|
//.include "../../ficmacros32.inc" @ for developer debugging
|
|
|
|
/************************************/
|
|
/* structure */
|
|
/************************************/
|
|
.struct 0 @ hash structure
|
|
hash_index:
|
|
.struct hash_index + 4
|
|
hash_value:
|
|
.struct hash_value + 4
|
|
hash_end:
|
|
|
|
/*******************************************/
|
|
/* Initialized data */
|
|
/*******************************************/
|
|
.data
|
|
szMessDebutPgm: .asciz "Program 32 bits start. \n"
|
|
szCarriageReturn: .asciz "\n"
|
|
szMessFinOK: .asciz "Program normal end. \n"
|
|
szMessIndex: .asciz "Index : "
|
|
szMessValue: .asciz " Value : "
|
|
|
|
szIndex1: .asciz "1"
|
|
szIndex2: .asciz "2"
|
|
szIndex3: .asciz "3"
|
|
szIndex4: .asciz "4"
|
|
|
|
szValue1: .asciz "One"
|
|
szValue2: .asciz "Two"
|
|
szValue3: .asciz "Three"
|
|
szValue4: .asciz "For"
|
|
|
|
listIndex: .int szIndex1
|
|
.int szIndex2
|
|
.int szIndex3
|
|
.int szIndex4
|
|
.equ NBINDEX, (. - listIndex ) / 4
|
|
|
|
listValue: .int szValue1
|
|
.int szValue2
|
|
.int szValue3
|
|
.int szValue4
|
|
.equ NBVALUE, (. - listValue ) / 4
|
|
/*******************************************/
|
|
/* UnInitialized data */
|
|
/*******************************************/
|
|
.bss
|
|
.align 4
|
|
hashExemple: .skip hash_end * NBINDEX
|
|
|
|
/*******************************************/
|
|
/* code section */
|
|
/*******************************************/
|
|
.text
|
|
.global main
|
|
main:
|
|
ldr r0,iAdrszMessDebutPgm
|
|
bl affichageMess
|
|
|
|
ldr r4,iAdrlistIndex @ index list address
|
|
ldr r5,iAdrlistValue @ value list address
|
|
ldr r6,iAdrhashExemple
|
|
mov r1,#hash_end @ size one record
|
|
mov r3,#0 @ indice
|
|
1:
|
|
ldr r2,[r4,r3,lsl #2] @ load one index address
|
|
mul r7,r3,r1 @ compute offset oh hah index address
|
|
str r2,[r6,r7] @ store index address in hah index address
|
|
ldr r2,[r5,r3,lsl #2] @ load one value address
|
|
add r7,#hash_value @ compute offset hash value address
|
|
str r2,[r6,r7] @ store value address in hash value address
|
|
|
|
add r3,r3,#1 @ increment indice
|
|
cmp r3,#NBINDEX @ end ?
|
|
blt 1b
|
|
|
|
ldr r0,iAdrhashExemple @ hash address
|
|
mov r1,#NBINDEX @ record umber
|
|
bl displayHash @ display
|
|
|
|
ldr r0,iAdrszMessFinOK
|
|
bl affichageMess
|
|
|
|
100: @ standard end of the program
|
|
mov r0, #0 @ return code
|
|
mov r7, #EXIT @ request to exit program
|
|
svc 0 @ perform system call
|
|
iAdrszMessDebutPgm: .int szMessDebutPgm
|
|
iAdrszMessFinOK: .int szMessFinOK
|
|
iAdrszCarriageReturn: .int szCarriageReturn
|
|
iAdrlistValue: .int listValue
|
|
iAdrlistIndex: .int listIndex
|
|
iAdrhashExemple: .int hashExemple
|
|
/******************************************************************/
|
|
/* display hash array */
|
|
/******************************************************************/
|
|
/* r0 contains hash list address */
|
|
/* r1 contains number lines */
|
|
displayHash:
|
|
push {r1-r5,lr} @ save registers
|
|
mov r4,r0 @ save hash address
|
|
mov r2,#0 @ indice
|
|
mov r3,#hash_end @ size record hash
|
|
1:
|
|
ldr r0,iAdrszMessIndex @ display index libellé
|
|
bl affichageMess
|
|
mul r5,r2,r3 @ compute hash index offset
|
|
ldr r0,[r4,r5] @ load address index
|
|
bl affichageMess @ and display
|
|
ldr r0,iAdrszMessValue @ display value libellé
|
|
bl affichageMess
|
|
add r5,r5,#hash_value @ compute offset hash value
|
|
ldr r0,[r4,r5] @ load address value
|
|
bl affichageMess @ and display
|
|
ldr r0,iAdrszCarriageReturn
|
|
bl affichageMess
|
|
add r2,r2,#1 @ increment indice
|
|
cmp r2,r1 @ end ?
|
|
blt 1b @ no -> loop
|
|
|
|
100:
|
|
pop {r1-r5,pc} @ restaur registers
|
|
iAdrszMessIndex: .int szMessIndex
|
|
iAdrszMessValue: .int szMessValue
|
|
|
|
/***************************************************/
|
|
/* ROUTINES INCLUDE */
|
|
/***************************************************/
|
|
.include "../affichage.inc"
|