-1

So I have a program that displays text ("Work was done to") and after that counts to 100% and display process, but the thing is that I don't want to print always the text before I display the new percent. So how can I insert text on specified position on the screen to overwrite other text?

How it looks now

Work was done to 1%
2%
3%
...

How I want to be

Work was done to 1% (and this percent just overwrites with the new one)

cpu 386
bits 16
org 0h

start:
    ...

;=====================================================================================================================    

    mov ah, 0x07               ;function to call with interrupt
    mov al, 0x00               ;scroll whole window
    mov bh, 0x07               ;background color
    mov cx, 0x0000             ;row 0,col 0
    mov dx, 0x184f
    int 0x10

    mov si, msg1
    call print_str
    mov eax, [PERCENT]

next:
    inc eax
    mov di, strbuf             ;ES:DI points to string buffer to store to
    call uint32_to_str         ;Convert 32-bit unsigned value in EAX to ASCII string

    mov si, di                 ;DS:SI points to string buffer to print
    call print_str

    mov si, msg2
    call print_str

    cmp eax, 100               ;End loop at 100
    jl next                    ;Continue until we reach limit

done:
    hlt
    jmp done

;=====================================================================================================================    

print_str:
    ...

;=====================================================================================================================    

uint32_to_str:
    ...

;=====================================================================================================================

MBR_Signature:
    msg1 db 13,10,'   Work was done to ',0
    msg2 db '%',0
    PERCENT dd 0
    strbuf times 11 db 0
    times 510-($-$$) db 0
    db 55h,0aah
    times 4096-($-$$) db 0
Temporaly
  • 11
  • 4
  • 1
    Do you understand what the `13,10` means? 13 is carriage return, 10 is line feed. If you don't wish to proceed to the next line, I'd try omitting the line feed. – David Wohlferd Jun 07 '19 at 03:17
  • Maybe not exactly a duplicate of [Why do multiple strings overlap/overwrite in my output in assembly?](//stackoverflow.com/q/45443080) where the behaviour you want is an accident from using a `0x0d` CR character without a newline. – Peter Cordes Jun 07 '19 at 03:26
  • There are some existing duplicates about writing text at *arbitrary* positions, not just going back to the start of the current line. Look up a BIOS interrupt list and use one of the cursor-movement functions if you want that. – Peter Cordes Jun 07 '19 at 03:29
  • 1
    If you don't want to use a BIOS cursor positioning call, if your string output processes ASCII control codes, you might be able to replace the `13,10` of your msg with enough backspace characters (ASCII 8)to back up to the start of the number you want to overwrite (or output them right before you output the new number, so the blinking cursor stays at the end of the percentage). – 1201ProgramAlarm Jun 07 '19 at 21:19

1 Answers1

0

Sorry, forgot the answer, I found an answer. Here is the code that I used, thanks to Peter Cordes, and of course, I modified dh and dl in my source code, and removed 10,13 from msg2 ->

mov dh, 0           ;Cursor position line
mov dl, 0           ;Cursor position column
mov ah, 02h         ;Set cursor position function
mov bh, 0           ;Page number
int 10h             ;Interrupt call
Temporaly
  • 11
  • 4
  • That would suggest you are rewriting the entire line over and over again (and always on the first line). Seems odd given that your question asked something different. If that was all you wanted then you could have stuck with removing the line feed character (10) in your string. Change `msg2 db '%',13,10,0` to `msg2 db '%',13,0` . Then you just rewrite the entire line each time. Removing the `10` will not advance the cursor to the next line but the `13` (Carriage return) will move the cursor to the beginning of the current line. – Michael Petch Jun 08 '19 at 00:15
  • No, that only example, of course, I modified `dh` and `dl` in my source code, and removed `10,13` from msg2 – Temporaly Jun 08 '19 at 00:40
  • 1
    You really should put that in your answer. – Michael Petch Jun 08 '19 at 00:42