167 lines
5.3 KiB
Plaintext
167 lines
5.3 KiB
Plaintext
/* ARM assembly Raspberry PI */
|
|
/* program commandLine.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
|
|
|
|
/***********************/
|
|
/* Initialized data */
|
|
/***********************/
|
|
.data
|
|
szMessDebutPgm: .asciz "Program 32 bits start. \n"
|
|
szMessFinOK: .asciz "Program normal end. \n"
|
|
szCarriageReturn: .asciz "\n"
|
|
szmessresUser: .asciz "result for USER :"
|
|
szmessresHome: .asciz "result for HOME :"
|
|
szmessresPath: .asciz "result for PATH :"
|
|
szVarRech: .asciz "USER="
|
|
.equ LGVARRECH, . - szVarRech - 1 @ car zero final
|
|
szVarRech1: .asciz "HOME="
|
|
.equ LGVARRECH1, . - szVarRech1 - 1 @ car zero final
|
|
szVarRech2: .asciz "PATH="
|
|
.equ LGVARRECH2, . - szVarRech2 - 1 @ car zero final
|
|
/***********************/
|
|
/* UnInitialized data */
|
|
/***********************/
|
|
.bss
|
|
.align 4
|
|
/***********************/
|
|
/* code section */
|
|
/***********************/
|
|
.text
|
|
.global main
|
|
main: @ entry of program
|
|
ldr r0,iAdrszMessDebutPgm
|
|
bl affichageMess
|
|
mov fp,sp @ fp <- start address
|
|
mov r0,fp
|
|
|
|
@ variable search USER
|
|
ldr r2,[fp] @ number param
|
|
add r2,r2,#2
|
|
ldr r1,iAdrszVarRech
|
|
1:
|
|
ldr r0,[fp,r2,lsl #2] @ load variable address
|
|
cmp r0,#0 @ end ?
|
|
beq 2f
|
|
mov r4,r0
|
|
bl searchSubBeginString @ search variable name
|
|
cmp r0,#-1 @ no find ?
|
|
addeq r2,#1
|
|
beq 1b
|
|
ldr r0,iAdrszmessresUser
|
|
bl affichageMess
|
|
add r0,r4,#LGVARRECH
|
|
bl affichageMess @ display result
|
|
ldr r0,iAdrszCarriageReturn
|
|
bl affichageMess
|
|
|
|
2:
|
|
ldr r2,[fp] @ search variable HOME
|
|
add r2,r2,#2
|
|
ldr r1,iAdrszVarRech1
|
|
3:
|
|
ldr r0,[fp,r2,lsl #2]
|
|
cmp r0,#0
|
|
beq 4f
|
|
mov r4,r0
|
|
bl searchSubBeginString
|
|
cmp r0,#-1
|
|
addeq r2,#1
|
|
beq 3b
|
|
ldr r0,iAdrszmessresHome
|
|
bl affichageMess
|
|
add r0,r4,#LGVARRECH
|
|
bl affichageMess
|
|
ldr r0,iAdrszCarriageReturn
|
|
bl affichageMess
|
|
|
|
4:
|
|
ldr r2,[fp] @ search variable PATH
|
|
add r2,r2,#2
|
|
ldr r1,iAdrszVarRech2
|
|
5:
|
|
ldr r0,[fp,r2,lsl #2]
|
|
cmp r0,#0
|
|
beq 6f
|
|
mov r4,r0
|
|
bl searchSubBeginString
|
|
cmp r0,#-1
|
|
addeq r2,#1
|
|
beq 5b
|
|
ldr r0,iAdrszmessresPath
|
|
bl affichageMess
|
|
add r0,r4,#LGVARRECH
|
|
bl affichageMess @ affichage message dans console
|
|
ldr r0,iAdrszCarriageReturn
|
|
bl affichageMess
|
|
|
|
6:
|
|
ldr r0,iAdrszMessFinOK
|
|
bl affichageMess
|
|
100: @ standard end of the program
|
|
mov r0, #0 @ return code
|
|
mov r7, #EXIT @ request to exit program
|
|
swi 0 @ perform the system call
|
|
|
|
iAdrszMessDebutPgm: .int szMessDebutPgm
|
|
iAdrszMessFinOK: .int szMessFinOK
|
|
iAdrszCarriageReturn: .int szCarriageReturn
|
|
iAdrszVarRech: .int szVarRech
|
|
iAdrszVarRech1: .int szVarRech1
|
|
iAdrszVarRech2: .int szVarRech2
|
|
iAdrszmessresUser: .int szmessresUser
|
|
iAdrszmessresPath: .int szmessresPath
|
|
iAdrszmessresHome: .int szmessresHome
|
|
/******************************************************************/
|
|
/* search a substring at the string beguining */
|
|
/******************************************************************/
|
|
/* r0 contains the address of the input string */
|
|
/* r1 contains the address of substring */
|
|
/* r0 returns index of substring in string or -1 if not found */
|
|
searchSubBeginString:
|
|
push {r1-r5,lr} @ save registers
|
|
mov r2,#0 @ counter byte input string
|
|
mov r3,#0 @ counter byte string
|
|
1:
|
|
ldrb r4,[r1,r3]
|
|
ldrb r5,[r0,r2] @ load byte string
|
|
cmp r5,#0
|
|
beq 3f
|
|
cmp r4,#0 @ zero final ?
|
|
moveq r0,#0 @ yes string find in position 0
|
|
beq 100f
|
|
cmp r5,r4 @ compare character
|
|
beq 2f
|
|
mov r0,#-1 @ no return no find
|
|
b 100f
|
|
2:
|
|
add r2,r2,#1 @ and increment counter byte
|
|
add r3,r3,#1 @ and increment
|
|
b 1b @ and loop
|
|
3: @
|
|
cmp r4,#0
|
|
movne r0,#-1 @ yes returns no find
|
|
bne 100f
|
|
mov r0,#0 @ string find in position 0
|
|
100:
|
|
pop {r1-r5,lr} @ restaur registers
|
|
bx lr
|
|
|
|
/***************************************************/
|
|
/* ROUTINES INCLUDE */
|
|
/***************************************************/
|
|
.include "../affichage.inc"
|