Task

Demonstrate how to achieve movement of the terminal cursor:

 how to move the cursor one position to the left
 how to move the cursor one position to the right
 how to move the cursor up one line (without affecting its horizontal position)
 how to move the cursor down one line (without affecting its horizontal position)
 how to move the cursor to the beginning of the line
 how to move the cursor to the end of the line
 how to move the cursor to the top left corner of the screen
 how to move the cursor to the bottom right corner of the screen


For the purpose of this task, it is not permitted to overwrite any characters or attributes on any part of the screen (so outputting a space is not a suitable solution to achieve a movement to the right).



Handling of out of bounds locomotion
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.




 
 
/* ARM assembly Raspberry PI  */
/*  program cursorMove.s   */
 
/* Constantes    */
.equ STDOUT, 1                           @ Linux output console
.equ EXIT,   1                           @ Linux syscall
.equ WRITE,  4                           @ Linux syscall
 
/* 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."
szMessMoveDown:            .asciz "\033[31m\033[BRed text location down"
szMessTopLeft:             .asciz "\033[;HTOP LEFT"
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,iAdrszMessMoveDown                   @ move pointer down
    bl affichageMess
    ldr r0,iAdrszMessTopLeft
    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
iAdrszMessMoveDown:        .int szMessMoveDown
iAdrszMessTopLeft:         .int szMessTopLeft
 
/******************************************************************/
/*     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
 
 