233 lines
10 KiB
Plaintext
233 lines
10 KiB
Plaintext
'file constant include'
|
|
/************************************/
|
|
/* Constantes */
|
|
/************************************/
|
|
.equ STDOUT, 1 @ Linux output console
|
|
.equ EXIT, 1 @ Linux syscall
|
|
.equ WRITE, 4 @ Linux syscall
|
|
|
|
'file source include '
|
|
/* file affichage.inc */
|
|
.data
|
|
/*************************************************/
|
|
szMessErr: .ascii "Error code hexa : "
|
|
sHexa: .space 9,' '
|
|
.ascii " decimal : "
|
|
sDeci: .space 15,' '
|
|
.asciz "\n"
|
|
.text
|
|
/******************************************************************/
|
|
/* display text with size calculation */
|
|
/******************************************************************/
|
|
/* r0 contains the address of the message */
|
|
affichageMess:
|
|
push {r0,r1,r2,r7,lr} @ save registres
|
|
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"
|
|
svc #0 @ call systeme
|
|
pop {r0,r1,r2,r7,lr} @ restaur des 2 registres */
|
|
bx lr @ return
|
|
/******************************************************************/
|
|
/* Converting a register to a decimal unsigned */
|
|
/******************************************************************/
|
|
/* r0 contains value and r1 address area */
|
|
/* r0 return size of result (no zero final in area) */
|
|
/* area size => 11 bytes */
|
|
.equ LGZONECAL, 10
|
|
conversion10:
|
|
push {r1-r4,lr} @ save registers
|
|
mov r3,r1
|
|
mov r2,#LGZONECAL
|
|
1: @ start loop
|
|
bl divisionpar10U @ unsigned r0 <- dividende. quotient ->r0 reste -> r1
|
|
add r1,#48 @ digit
|
|
strb r1,[r3,r2] @ store digit on area
|
|
cmp r0,#0 @ stop if quotient = 0
|
|
subne r2,#1 @ else previous position
|
|
bne 1b @ and loop
|
|
@ and move digit from left of area
|
|
mov r4,#0
|
|
2:
|
|
ldrb r1,[r3,r2]
|
|
strb r1,[r3,r4]
|
|
add r2,#1
|
|
add r4,#1
|
|
cmp r2,#LGZONECAL
|
|
ble 2b
|
|
@ and move spaces in end on area
|
|
mov r0,r4 @ result length
|
|
mov r1,#' ' @ space
|
|
3:
|
|
strb r1,[r3,r4] @ store space in area
|
|
add r4,#1 @ next position
|
|
cmp r4,#LGZONECAL
|
|
ble 3b @ loop if r4 <= area size
|
|
|
|
100:
|
|
pop {r1-r4,lr} @ restaur registres
|
|
bx lr
|
|
/***************************************************/
|
|
/* Converting a register to a signed decimal */
|
|
/***************************************************/
|
|
/* r0 contains value and r1 area address */
|
|
conversion10S:
|
|
push {r0-r4,lr} @ save registers
|
|
mov r2,r1 @ debut zone stockage
|
|
mov r3,#'+' @ par defaut le signe est +
|
|
cmp r0,#0 @ negative number ?
|
|
movlt r3,#'-' @ yes
|
|
mvnlt r0,r0 @ number inversion
|
|
addlt r0,#1
|
|
mov r4,#10 @ length area
|
|
1: @ start loop
|
|
bl divisionpar10U
|
|
add r1,#48 @ digit
|
|
strb r1,[r2,r4] @ store digit on area
|
|
sub r4,r4,#1 @ previous position
|
|
cmp r0,#0 @ stop if quotient = 0
|
|
bne 1b
|
|
|
|
strb r3,[r2,r4] @ store signe
|
|
subs r4,r4,#1 @ previous position
|
|
blt 100f @ if r4 < 0 -> end
|
|
|
|
mov r1,#' ' @ space
|
|
2:
|
|
strb r1,[r2,r4] @store byte space
|
|
subs r4,r4,#1 @ previous position
|
|
bge 2b @ loop if r4 > 0
|
|
100:
|
|
pop {r0-r4,lr} @ restaur registers
|
|
bx lr
|
|
|
|
/***************************************************/
|
|
/* division par 10 unsigned */
|
|
/***************************************************/
|
|
/* r0 dividende */
|
|
/* r0 quotient */
|
|
/* r1 remainder */
|
|
divisionpar10U:
|
|
push {r2,r3,r4, lr}
|
|
mov r4,r0 @ save value
|
|
//mov r3,#0xCCCD @ r3 <- magic_number lower raspberry 3
|
|
//movt r3,#0xCCCC @ r3 <- magic_number higter raspberry 3
|
|
ldr r3,iMagicNumber @ r3 <- magic_number raspberry 1 2
|
|
umull r1, r2, r3, r0 @ r1<- Lower32Bits(r1*r0) r2<- Upper32Bits(r1*r0)
|
|
mov r0, r2, LSR #3 @ r2 <- r2 >> shift 3
|
|
add r2,r0,r0, lsl #2 @ r2 <- r0 * 5
|
|
sub r1,r4,r2, lsl #1 @ r1 <- r4 - (r2 * 2) = r4 - (r0 * 10)
|
|
pop {r2,r3,r4,lr}
|
|
bx lr @ leave function
|
|
iMagicNumber: .int 0xCCCCCCCD
|
|
/***************************************************/
|
|
/* display error message */
|
|
/***************************************************/
|
|
/* r0 contains error code r1 : message address */
|
|
displayError:
|
|
push {r0-r2,lr} @ save registers
|
|
mov r2,r0 @ save error code
|
|
mov r0,r1
|
|
bl affichageMess
|
|
mov r0,r2 @ error code
|
|
ldr r1,iAdrsHexa
|
|
bl conversion16 @ conversion hexa
|
|
mov r0,r2 @ error code
|
|
ldr r1,iAdrsDeci @ result address
|
|
bl conversion10S @ conversion decimale
|
|
ldr r0,iAdrszMessErr @ display error message
|
|
bl affichageMess
|
|
100:
|
|
pop {r0-r2,lr} @ restaur registers
|
|
bx lr @ return
|
|
iAdrszMessErr: .int szMessErr
|
|
iAdrsHexa: .int sHexa
|
|
iAdrsDeci: .int sDeci
|
|
/******************************************************************/
|
|
/* Converting a register to hexadecimal */
|
|
/******************************************************************/
|
|
/* r0 contains value and r1 address area */
|
|
conversion16:
|
|
push {r1-r4,lr} @ save registers
|
|
mov r2,#28 @ start bit position
|
|
mov r4,#0xF0000000 @ mask
|
|
mov r3,r0 @ save entry value
|
|
1: @ start loop
|
|
and r0,r3,r4 @value register and mask
|
|
lsr r0,r2 @ move right
|
|
cmp r0,#10 @ compare value
|
|
addlt r0,#48 @ <10 ->digit
|
|
addge r0,#55 @ >10 ->letter A-F
|
|
strb r0,[r1],#1 @ store digit on area and + 1 in area address
|
|
lsr r4,#4 @ shift mask 4 positions
|
|
subs r2,#4 @ counter bits - 4 <= zero ?
|
|
bge 1b @ no -> loop
|
|
|
|
100:
|
|
pop {r1-r4,lr} @ restaur registers
|
|
bx lr @return
|
|
/***************************************************/
|
|
/* integer division unsigned */
|
|
/***************************************************/
|
|
division:
|
|
/* r0 contains dividend */
|
|
/* r1 contains divisor */
|
|
/* r2 returns quotient */
|
|
/* r3 returns remainder */
|
|
push {r4, lr}
|
|
mov r2, #0 @ init quotient
|
|
mov r3, #0 @ init remainder
|
|
mov r4, #32 @ init counter bits
|
|
b 2f
|
|
1: @ loop
|
|
movs r0, r0, LSL #1 @ r0 <- r0 << 1 updating cpsr (sets C if 31st bit of r0 was 1)
|
|
adc r3, r3, r3 @ r3 <- r3 + r3 + C. This is equivalent to r3 ? (r3 << 1) + C
|
|
cmp r3, r1 @ compute r3 - r1 and update cpsr
|
|
subhs r3, r3, r1 @ if r3 >= r1 (C=1) then r3 <- r3 - r1
|
|
adc r2, r2, r2 @ r2 <- r2 + r2 + C. This is equivalent to r2 <- (r2 << 1) + C
|
|
2:
|
|
subs r4, r4, #1 @ r4 <- r4 - 1
|
|
bpl 1b @ if r4 >= 0 (N=0) then loop
|
|
pop {r4, lr}
|
|
bx lr
|
|
|
|
'File Main program'
|
|
|
|
/* ARM assembly Raspberry PI */
|
|
/* program include.s */
|
|
|
|
/* Constantes */
|
|
.include "./constantes.inc"
|
|
/* Initialized data */
|
|
.data
|
|
szMessageOK: .asciz "Hello \n"
|
|
|
|
/* code section */
|
|
.text
|
|
.global main
|
|
main: @ entry of program
|
|
push {fp,lr} @ saves registers
|
|
ldr r0,iAdrszMessageOK
|
|
bl affichageMess
|
|
|
|
|
|
100: @ standard end of the program
|
|
mov r0, #0 @ return code
|
|
pop {fp,lr} @restaur registers
|
|
mov r7, #EXIT @ request to exit program
|
|
swi 0 @ perform the system call
|
|
|
|
iAdrszMessageOK: .int szMessageOK
|
|
|
|
/*********************************/
|
|
/* include source display */
|
|
/*********************************/
|
|
.include "./affichage.inc"
|