Strange exit with Irvine WriteString

the point of the next program is to print the letter "c" with a combination of each background and foreground color.

In the library I'm using, colors are defined 0-15 and with the following code:

mov eax,FOREGROUND + (BACKGROUND * 16) 
call SetTextColor 

Here is my code:

INCLUDE Irvine32.inc
.data

character BYTE "c"
count DWORD ?
background DWORD 0

.code
main PROC
    call Clrscr

    mov ecx, 15                             ; our main counter 0-15 colors

L1:     
    mov count, ecx                          ; store our outer loop counter
    mov ecx, 15                             ; set out inner loop counter
L2:     
    ; since our color is defined like so... mov eax,FOREGROUND + (BACKGROUND * 16)
    mov eax, count                          ; setup our foreground color
    add eax, background                     ; setup our background color
    call SetTextColor

    ;  instead of multiplying each background color by 16, we are going to 
    ; add 16 each time. 
    add background, 16                      

    ; print the character
    mov edx, OFFSET character
    call WriteString 
    loop L2

    mov ecx, count                          ; reset our outside loop
    loop L1

    call Crlf
    exit
main ENDP

END main

Now I use windows 7, the above code "works", but for some reason it goes to a certain point, the program stops, and the computer starts to sound. In addition, at a certain point in the program, he begins to print random characters with the letter c .. here is my conclusion:

c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c
c
c
c
c
c
c
c
c
c
c
c
c
c
c
c       c       c       c       c       c       c       c       c       c
c       c       c       c       c       cccccccccccccccc♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c
♠c♠c♠c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♥c♥c♥c♥c♥c♥c♥c
♥c♥c♥c♥c♥c♥c♥c♥c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺
Press any key to continue . . .

Can someone tell me why this is happening?

+3
source share
3 answers

Irvine WriteString . CHM (IrvineLibHelp.exe).

"EDX = ". EDX , (: "" ). WriteString , 0. MASM 0, :

character BYTE "c", 0

- WriteChar:

...
; print the character
mov al, character
call WriteChar
loop L2

mov ecx, count                          ; reset our outside loop
loop L1
...
+3
character BYTE "c"

:

character BYTE "c",0dh,0ah,0
+2

What does WriteString do? If a function prints a line, you may need to end the "BYTE character" c "" with $ (if it is a DOS program. 09 function Int21h)

0
source

Source: https://habr.com/ru/post/1766683/


All Articles