September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -0,0 +1,52 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program forfunction.s */
|
||||
|
||||
/* Constantes */
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
/* Initialized data */
|
||||
.data
|
||||
szString: .asciz "Hello word\n"
|
||||
|
||||
/* UnInitialized data */
|
||||
.bss
|
||||
|
||||
/* code section */
|
||||
.text
|
||||
.global main
|
||||
main: @ entry of program
|
||||
push {fp,lr} @ saves registers
|
||||
|
||||
ldr r0,iAdrszString @ string address
|
||||
bl strdup @ call function C
|
||||
@ return new pointer
|
||||
bl affichageMess @ display dup string
|
||||
bl free @ free heap
|
||||
|
||||
100: @ standard end of the program */
|
||||
mov r0, #0 @ return code
|
||||
pop {fp,lr} @restaur 2 registers
|
||||
mov r7, #EXIT @ request to exit program
|
||||
swi 0 @ perform the system call
|
||||
iAdrszString: .int szString
|
||||
|
||||
/******************************************************************/
|
||||
/* 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
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
@[Link("c")] # name of library that is passed to linker. Not needed as libc is linked by stdlib.
|
||||
lib LibC
|
||||
fun free(ptr : Void*) : Void
|
||||
fun strdup(ptr : Char*) : Char*
|
||||
end
|
||||
|
||||
s1 = "Hello World!"
|
||||
p = LibC.strdup(s1) # returns Char* allocated by LibC
|
||||
s2 = String.new(p)
|
||||
LibC.free p # pointer can be freed as String.new(Char*) makes a copy of data
|
||||
|
||||
puts s2
|
||||
Loading…
Add table
Add a link
Reference in a new issue