Terminal control/Cursor movement: Difference between revisions

Add task to ARM assembly Raspberry pi
m (→‎{{header|REXX}}: added whitespace and highlighting to the REXX section preamble.)
(Add task to ARM assembly Raspberry pi)
Line 19:
This task has no specific requirements to trap or correct cursor movement beyond the terminal boundaries, so the implementer should decide what behavior fits best in terms of the chosen language.   Explanatory notes may be added to clarify how an out of bounds action would behave and the generation of error messages relating to an out of bounds cursor position is permitted.
<br><br>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
/* program cursorMove.s */
 
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
 
.equ BUFFERSIZE, 100
 
/* Initialized data */
.data
szMessStartPgm: .asciz "Program start \n"
szMessEndPgm: .asciz "Program normal end.\n"
szMessColorRed: .asciz "Color red.\n"
szCodeInit: .asciz "\033[0m" @ color reinit
szCodeRed: .asciz "\033[31m" @ color red
szCodeBlue: .asciz "\033[34m" @ color blue
szMessMove: .asciz "\033[A\033[6CBlue Message up and 6 location right.\n"
szMessMovePos: .asciz "\033[31m\033[5;20HRed text location at line 5 columns 20"
szCarriageReturn: .asciz "\n"
 
/* UnInitialized data */
.bss
 
/* code section */
.text
.global main
main:
 
ldr r0,iAdrszMessStartPgm @ display start message
bl affichageMess
ldr r0,iAdrszCodeRed @ color red
bl affichageMess
ldr r0,iAdrszMessColorRed
bl affichageMess
ldr r0,iAdrszCodeBlue
bl affichageMess
ldr r0,iAdrszMessMove
bl affichageMess
ldr r0,iAdrszMessMovePos
bl affichageMess
ldr r0,iAdrszCarriageReturn @ start next line
bl affichageMess
ldr r0,iAdrszCodeInit @ color reinitialize
bl affichageMess
ldr r0,iAdrszMessEndPgm @ display end message
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
iAdrszMessStartPgm: .int szMessStartPgm
iAdrszMessEndPgm: .int szMessEndPgm
iAdrszCodeInit: .int szCodeInit
iAdrszCodeRed: .int szCodeRed
iAdrszCodeBlue: .int szCodeBlue
iAdrszMessColorRed: .int szMessColorRed
iAdrszMessMove: .int szMessMove
iAdrszCarriageReturn: .int szCarriageReturn
iAdrszMessMovePos: .int szMessMovePos
 
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} @ save registers
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 system
pop {r0,r1,r2,r7,lr} @ restaur registers
bx lr @ return
 
</lang>
=={{header|AutoHotkey}}==