-
count loop
Hi,
I can print A - Z fine using the following :
Code:
.model small
.stack 100h
.data
.code
mov ah, 02h ; DOS function call 2, character output
mov dl, 41h ; the character 041h (i.e.'A')
mov cx, 26 ; start the counter at 26 in cx
again: int 21h ; print character
inc dl ; the next character into dl
add dl,1 ;
loop again ; subtract 1 from cx, if not zero jump back to again
finish: mov ax, 4C00h ; Terminate program
int 21h ; correctly
end
What I'd like to do now is print 1 - 100 in the following order
1
2
3
4
5
6
etc etc ...
Any help would be very much appreciated.
thanks in advance
-
Re: count loop
It's exactly the same, only instead of just printing a single character, you need to print a string, and that string must contain the stringized number.
So you need two subroutines, probably. One converts a number to a string. The other prints a string.
-
Re: count loop
Well, I don't know if it is any help to solve the problem for you but you preserve six bytes in data section for your string. Three bytes for the numbers, two for cr and lf and one for string termination.
Code:
msg db 6 dup(0,0,31h,0Dh,0Ah,"$") ;msg = "1"
Then it is a matter of loops. If you have problem show you code and we will help.
-
Re: count loop
i have the same sorta problem as the first guy but i need to display the alphabet on different lines for example
a
b
c
d
e
f
etc,
ive used the same code as he has, but i need to use the newline (0Ah) and carriage return (0Dh) functions in the loop.
if you could help it would help me alot
thanks in advanced
will
-
Re: count loop
a = 61h and z = 7Ah. Write a loop from 61h to 7Ah. There you have the small letters.
1) Reserve data space like msg db 4 dup(00h,0Dh,0Ah,"$") in data section.
2) Use for example cx and put first letter value in cx.
3) Put cl in first byte of msg
4) Write to screen
5) jump back untill cx = 7Ah
-
Re: count loop
i think you should make a table of characters
and use a pointer to this table
for example:
table db 6 dup 'abcdef'
then in your code: if you want to print the alphabet on different lines:
Code:
.model small
.stack 100h
.data
table db 6 dup 'abcdef'
.code
mov ax,@data
mov ds,ax
cld ;clear DF
lea si,table ;si stores the offset of the first char in table
mov cx,6 ;count loop
mov ah,2
again:
lodsb ;[si] -> al
mov dl,al
int 21h
mov dl,0Ah
int 21h
mov dl,0Dh
int 21h
loop again
according to each LODSB instruction :inc si (automatical)