News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

No COORD structure

Started by felipe, July 03, 2017, 03:17:16 AM

Previous topic - Next topic

felipe

Here is a simple illustration of the beauty of the assembly language.   :biggrin:
You may use the COORD struct for windows functions like SetConsoleCursorPosition or FillConsoleOutputAttribute (i have done this in other relative posts). But you also can skip this by just pushing a register value or an inmediate value. Here is an example for the FillConsoleOutputCharacter windows function.


.386
.model  flat,stdcall
option  casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\kernel32.lib

.data?
hconout     dd  ?
hconin      dd  ?
numactu     dd  ?
buffer      db  256 dup(?)                         


.data
contitle    db  "My new program",0
text        db  "This is my text",0


.code
main    proc
        call    AllocConsole                                ; Initial basic code.
        push    STD_OUTPUT_HANDLE
        call    GetStdHandle
        mov     hconout,eax
        push    STD_INPUT_HANDLE
        call    GetStdHandle
        mov     hconin,eax


        lea     eax,contitle                                ; We set a title for the console.
        push    eax
        call    SetConsoleTitle


        lea     esi,text                                    ; Address of the text.                       
        mov     ebx,15                                      ; 15 chars to be displayed.
        xor     edi,edi                                     ; Column and row (0,0). Not using the COORD struct.

nextchar:
        lea     eax,numactu                 
        push    eax                                         ; Actual chars written.
        push    edi                                         ; The coordinates for the char in the console.
        push    1                                           ; 1 char at a time.
        push    [esi]                                       ; The char in the string text.
        push    hconout                                     ; Console output handle.
        call    FillConsoleOutputCharacter                  ; A char, n times.
        inc     esi                                         ; Next char.
        inc     edi                                         ; Increment column, but keep row the same.
        dec     ebx                                         ; Until we write the 15 chars.
        jnz     nextchar 


        lea     eax,numactu                                 ; Actual chars written.
        push    eax
        ;mov     edi,0005000ah                              ; Not even necessary.
        ;push    edi
        push    0005000ah                                   ; Column 10, row 5.
        push    10                                          ; Repeat the char 10 times.
        lea     eax,text                                   
        push    [eax]                                       ; What char?: this one.
        push    hconout                                     ; The handle.
        call    FillConsoleOutputCharacter                  ; Same windows function as before.

       
        push    NULL                                        ; This is just for do the pause
        lea     eax,numactu                                 ;   and see the result of the operations.
        push    eax
        push    1
        lea     eax,buffer
        push    eax 
        push    hconin
        call    ReadConsole


        call    FreeConsole                                 ; Terminating the program.
        push    NULL
        call    ExitProcess
main    endp

        end     main