flat assembler
Message board for the users of flat assembler.

Index > Linux > How to reset terminal cursor position

Author
Thread Post new topic Reply to topic
burrows



Joined: 13 Jul 2024
Posts: 6
burrows 20 Jul 2024, 21:53
I'm working on a 32 bit assembly program that clears the terminal, and all I need to do is reset the cursor position to the top of the terminal. I'm using the XFCE terminal, if it matters. Yes, I'm using the method of printing a bunch of newlines instead of using ANSI escape codes or libraries to do this. I've looked for an answer on several forums, articles and blogs and I've found nothing.

This is the code so far.
Code:
start:
            mov ecx , 80           ; Amount of newlines to print
clear_loop:
            push ecx               ; Preserve ecx value
            mov eax , 4            ; Print newline
            mov ebx , 1
            mov ecx , newline
            mov edx , 1
            int 0x80
            pop ecx                ; Bring back ecx value
            dec ecx                ; Take away 1 from ecx
            jnz clear_loop         ; Keep printing until ecx in stack is 0

segment readable writable

newline db 0x0A
    
Post 20 Jul 2024, 21:53
View user's profile Send private message Reply with quote
uu



Joined: 20 Jul 2024
Posts: 44
uu 20 Jul 2024, 22:57
I use ANSI escape code:

Code:
format ELF executable 3

segment readable executable

entry $

            mov eax, 4
            mov ebx, 1
            mov ecx, cls
            mov edx, len
            int 0x80
            mov eax, 1
            int 0x80

cls     db      27,'[H',27,'[JI am here!'
len     =       $ - cls             


You can remove "I am here", it is used here to show that the cursor is at top-left corner.
Post 20 Jul 2024, 22:57
View user's profile Send private message Reply with quote
burrows



Joined: 13 Jul 2024
Posts: 6
burrows 21 Jul 2024, 00:01
Quote:

I use ANSI escape code:

Thank you for your example, but it's important that the program doesn't depend on things like ANSI escape codes to do it's job. I'm trying to directly target the terminal emulator's cursor and reset its position, like with a specific syscall or BIOS interrupt. Maybe this would be easier to make on DOS.
Post 21 Jul 2024, 00:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 21 Jul 2024, 03:29
In Linux there is no syscall to control a terminal. You will need to talk to the terminal directly with IOCTL calls. This is the hard route, and it is less compatible with the terminals.

It is no doubt vastly easier, and more compatible, to use ANSI code in Linux. It is how it is built.

Also: BIOS interrupt isn't possible in Linux. Linux runs in protected mode.
Post 21 Jul 2024, 03:29
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.