assembly - Strange output with Irvine's WriteString -
the point of following program print out letter "c" combination of every background , foreground color.
in library i'm using colors defined 0-15 , following code:
mov eax,foreground + (background * 16) call settextcolor
here 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 defined 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 16, going ; add 16 each time. add background, 16 ; print 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'm using windows 7, above code "works" reason, goes point, program stops, , computer starts beeping. also, @ point in program, starts printing random characters letter c.. here output:
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 key continue . . .
can tell me why happening?
irvine's writestring needs "null-terminated string". can download chm-file here (irvinelibhelp.exe).
it's little bit sloppy "edx = points string". edx points memory address identifiable label (here: "character"). writestring
byte byte location , write character or control directive regardless of real type or intention until comes across byte value 0. masm has no directive define string last 0, has added manually:
character byte "c", 0
an alternative way print character use writechar:
... ; print character mov al, character call writechar loop l2 mov ecx, count ; reset our outside loop loop l1 ...
Comments
Post a Comment