Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   Calling A Macro Multiple Times With Same Code (http://www.programmingforums.org/showthread.php?t=1338)

lepricaun Nov 29th, 2004 3:58 PM

hi,

i had a problem converting a number to characters to output it to the screen.

i solved this problem by writing a macro, but now when i try to call the macro 3 times within the same code i get the following error while compiling:

Quote:


Turbo Assembler Version 2.01 Copyright © 1988, 1990 Borland International

Assembling file: 1.asm
**Error** 1.asm(20) PRINTVALUE(6) Symbol already defined elsewhere: THOUSAND
**Error** 1.asm(20) PRINTVALUE(8) Relative jump out of range by 000Ah bytes
**Error** 1.asm(20) PRINTVALUE(13) Symbol already defined elsewhere: HUNDRED
**Error** 1.asm(20) PRINTVALUE(15) Relative jump out of range by 0001h bytes
**Error** 1.asm(20) PRINTVALUE(25) Symbol already defined elsewhere: NEXT1
**Error** 1.asm(20) PRINTVALUE(27) Relative jump out of range by 000Bh bytes
**Error** 1.asm(20) PRINTVALUE(32) Symbol already defined elsewhere: TEN
**Error** 1.asm(20) PRINTVALUE(34) Relative jump out of range by 000Dh bytes
**Error** 1.asm(20) PRINTVALUE(36) Relative jump out of range by 0002h bytes
**Error** 1.asm(20) PRINTVALUE(38) Symbol already defined elsewhere: GO_ON
**Error** 1.asm(20) PRINTVALUE(48) Symbol already defined elsewhere: LAST
**Error** 1.asm(20) PRINTVALUE(50) Relative jump out of range by 000Ch bytes
**Error** 1.asm(20) PRINTVALUE(55) Symbol already defined elsewhere: FINAL
**Error** 1.asm(20) PRINTVALUE(57) Relative jump out of range by 000Eh bytes
**Error** 1.asm(20) PRINTVALUE(59) Relative jump out of range by 0008h bytes
**Error** 1.asm(20) PRINTVALUE(61) Symbol already defined elsewhere: NEXT2
**Error** 1.asm(20) PRINTVALUE(69) Symbol already defined elsewhere: FINISH
**Error** 1.asm(23) PRINTVALUE(6) Symbol already defined elsewhere: THOUSAND
**Error** 1.asm(23) PRINTVALUE(8) Relative jump out of range by 009Dh bytes
**Error** 1.asm(23) PRINTVALUE(13) Symbol already defined elsewhere: HUNDRED
**Error** 1.asm(23) PRINTVALUE(15) Relative jump out of range by 0094h bytes
**Error** 1.asm(23) PRINTVALUE(25) Symbol already defined elsewhere: NEXT1
**Error** 1.asm(23) PRINTVALUE(27) Relative jump out of range by 009Eh bytes
**Error** 1.asm(23) PRINTVALUE(32) Symbol already defined elsewhere: TEN
**Error** 1.asm(23) PRINTVALUE(34) Relative jump out of range by 00A0h bytes
**Error** 1.asm(23) PRINTVALUE(36) Relative jump out of range by 0095h bytes
**Error** 1.asm(23) PRINTVALUE(38) Symbol already defined elsewhere: GO_ON
**Error** 1.asm(23) PRINTVALUE(48) Symbol already defined elsewhere: LAST
**Error** 1.asm(23) PRINTVALUE(50) Relative jump out of range by 009Fh bytes
**Error** 1.asm(23) PRINTVALUE(55) Symbol already defined elsewhere: FINAL
**Error** 1.asm(23) PRINTVALUE(57) Relative jump out of range by 00A1h bytes
**Error** 1.asm(23) PRINTVALUE(59) Relative jump out of range by 009Bh bytes
**Error** 1.asm(23) PRINTVALUE(61) Symbol already defined elsewhere: NEXT2
**Error** 1.asm(23) PRINTVALUE(69) Symbol already defined elsewhere: FINISH
Error messages: 34
Warning messages: None
Passes: 1
Remaining memory: 472k


i know what is wrong, but i do not know how to solve it :(

since the code in the macro is put into the place where i put the calling, i get multiple labels with the same name.
how can i make this work without having to create at least 3 different macros with as only difference the label names?

here's the macro i have written:

:

;####################
;printvalue macro
;print value 0234 = 234
;####################
printvalue macro number

push ax bx cx dx

mov ax,number
xor cx,cx
thousand:
cmp ax,1000
jl hundred
sub ax,1000
inc cx
jmp thousand

hundred:
cmp cx,0
je next1
mov bx,1
push ax
mov dl,cl
add dl,48
mov ah,02h
int 21h
pop ax
xor cx,cx

next1:
cmp ax,100
jl ten
sub ax,100
inc cx
jmp next1

ten:
cmp bx,1
je go_on
cmp cx,0
je last

go_on:
mov bx,2
push ax
mov dl,cl
add dl,48
mov ah,02h
int 21h
pop ax
xor cx,cx

last:
cmp ax,10
jl final
sub ax,10
inc cx
jmp last

final:
cmp bx,2
je next2
cmp cx,0
je finish

next2:
push ax
mov dl,cl
add dl,48
mov ah,02h
int 21h
pop ax

finish:
mov dl,al
add dl,48
mov ah,02h
int 21h

pop dx cx bx ax

endm
;##################


i also don't want to create a procedure from this since i would like to use it in multiple programs without having to rewrite the proc everytime i start writing another program.


any ideas?


thanks in advance ;)

liquidsilver Mar 11th, 2005 4:40 PM

This code seems rather long. If you're using it 3 times I strongly consider making into a proc. You can just drag the code to your new project if you wish.

lepricaun Mar 16th, 2005 6:17 AM

thanks,

i'll keep that in mind as soon as i start working with 16-bit assembly again, currently i'm using masm32 a lot, as it is a lot more useful to me at this time.

liquidsilver Mar 16th, 2005 2:36 PM

I found a proper solution. Use the @@: label and jmp @F or jmp @B to jump forwards or backwards to a @@ label.

lepricaun Mar 17th, 2005 4:14 AM

Thanks, i know about the @@ labels now.. but like i said, i'm not really using 16-bits assembly at the moment.. i also know it is possible to use these labels with masm32, so it can indeed be a nice solution :)


All times are GMT -5. The time now is 2:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC