-1

I have a global variable that count's how many times a function has been accessed. Eeverytime I access a specific function, the last line of that function is something like this: add var_count, 1.

Then, I have another function that prints this global variable, the problem is: I can't print it...

Here is the code where I'am printing:

.data

var_count db 0

.code

...piece of code


mov ah,9
lea dx, var_count
int 21h


...piece of code
niarb
  • 136
  • 11
  • This may be of help: http://stackoverflow.com/q/13166064/3258851 – Marc.2377 Apr 03 '15 at 00:48
  • Are you sure 1 byte is enough? – Weather Vane Apr 03 '15 at 12:11
  • function 09h in 21h prints string. It is not possible to directly print numbers. When you want to do, you have to write your own procedure to do it. And how? By dividing value stored in variable by 10, then adding ascii code of character '0' to reminder and then print this value using some function for printing characters e.g. function 02h. For more information and guidance just search a little bit for similar questions here on stackoverflow. – Gondil Apr 04 '15 at 15:11
  • I made this but it prints the numbers in reverse orde: ´mov al, var_number mov ah ,0 mov cx, 10 loopit: mov dx, 0 div cx push ax add dl,'0' mov ah,2 int 21h pop ax cmp ax,0 jnz loopit´ – niarb Apr 04 '15 at 21:31

1 Answers1

1

Here's what your program could become. I used most of the code you wrote in your comment. When creating the text version of our number we start writing at the end and move towards the beginning.

.data

var_count db 0
txt_buffer db '   ','$'  ;3 spaces is enough when converting a byte

.code

...piece of code

 mov di, offset txt_buffer + 3
 mov al, var_count
 mov ah ,0
 mov cx, 10
loopit:
 mov dx, 0
 div cx
 add dl,'0'
 dec di
 mov [di], dl
 cmp ax,0
 jnz loopit
 mov dx, di
 mov ah, 9
 int 21h

...piece of code
Sep Roland
  • 26,423
  • 5
  • 40
  • 66