I am trying to make an x86 assembly macro in NASM that uses ANSI escape codes to move the cursor to the specified X Y coordinates in the user's terminal window. The code is:
; MoveCursor X, Y
segment .data
format:
db `\033[%d;%dH` ; First %d is Y coordinate, second %d is X coordinate
; Backticks tell NASM to process these as C-Strings
; Semicolon seperates the Y and X values.
%macro MoveCursor 2
lea rdi, [rel format]
lea rsi, [rel %2]
lea rcx, [rel %1] ; ANSI move cursor code is in Y, X format, hence reversing parameters
; to provide more traditional X,Y format.
call _printf ; Print the ANSI code to move the cursor.
; printf should have printed something like "\033[1;5H" at this point
%endmacro
You can probably already see my problem. NASM uses Intel syntax, where ";" marks the beginning of a comment. Because of this, NASM thinks everything after the first semicolon in "format" is a comment. Because of this, the macro will change the Y coordinate but not the X coordinate, since where the x coordinate should go is commented out of the printf format. I tried, but (As far as I know. I am no expert in ANSI codes) the ANSI escape code needs that semicolon seperating the two numbers, I can't use whitespace.
Is there any way at all to get around this problem? How can I get properly get that semicolon in "\033[%d;%dH" without NASM thinking it's a comment? Of course, I could write a C++ program to do this and link it with my assembly program, but I would prefer to do it in assembly.
I'm running Mac OSX, and am programming in x86 assembly language. I am using NASM and GCC to compile my program.
Any help will be much appreciated, I'm new here so please tell me if I did anything wrong when writing this question.