hello all ,
there was a code which would solve hanoi probelm , one of my friends asked me to split the code so that it uses two code segments !
and this is where i am stuck ! and i ask for your help .
here is the code .
thanks in advance
INCLUDE IO.H
;**************************CLS MACRO*******************
CLS MACRO
STARTMSG DB 'ENTER DISK NUMBER : ',"$"
STARTMSG2 DB 'Ok ',"$"
endMSG2 DB 'end ',"$"
NUM DB 2 DUP(0)
MOVEMSG DB 0DH,0AH, ' '
SOURCE DB ?
MSG DB ' ==> '
DEST DB ?
ENDMSG DB "$"
Ok, this looks much better! :) Simple question: Does it work?
Static procedure nesting in Assembly looks a bit like the respective structural feature in Pascal but it's by far not that easy to use. (It can actually be of some use in some situations though I can't give an example of this off-hand either. That probably is the reason why it's not plain illegal.) The assembler translates the instructions exactly as you write them. As a consequence, your original proc _hanoi_ would simply run into the code of MOVE and never have a chance to reach its final three instructions that are intended to return control to the code that called it. (It would probably crash for certain because it would try to return from a far proc, _hanoi_, using the near RET in MOVE. But I'm not 100% sure at the moment that the far property doesn't get inherited by nested procs.)
Aside from that, the main code at the end of the program would run into nirvana after return from _hanoi_ - if it ever had a chance to get there at all.
Oh, wait... I just found something that still keeps the program from running correctly at the very end of the code: the ADD SP,8 before the call to EXIT. It tries to remove the parameters passed to _hanoi_ from the stack after the call, but that was in the previous version, so you are popping something off the stack that isn't there. The program may not even actually crash because of that since you're not attempting to do a RET unsing whatever SP is pointing to now, but that's still asking for trouble.
Well, you accomplished the objective of demonstrating the use of more than one code segments, but that's not a very useful example as the "outer" code in the segment CODESG does close to nothing, i.e. just set up DS and then call the rest in the other segment before exiting. Ok, you can think of it as a really, really tiny runtime environment... :D
Master.
February 18th, 2011, 02:49 AM
Ok, this looks much better! :) Simple question: Does it work?
Static procedure nesting in Assembly looks a bit like the respective structural feature in Pascal but it's by far not that easy to use. (It can actually be of some use in some situations though I can't give an example of this off-hand either. That probably is the reason why it's not plain illegal.) The assembler translates the instructions exactly as you write them. As a consequence, your original proc _hanoi_ would simply run into the code of MOVE and never have a chance to reach its final three instructions that are intended to return control to the code that alled it. (It would probably crash for certain because it would try to return from a far proc, _hanoi_, using the near RET in MOVE. But I'm not 100% sure at the moment that the far property doesn't get inherited by nested procs.)
Aside from that, the main code at the end of the program would run into nirvana after return from _hanoi_ - if it ever had a chance to get there at all.
Oh, wait... I just found something that still keeps the program from running correctly at the very end of the code: the ADD SP,8 before the call to EXIT. It tries to remove the parameters passed to _hanoi_ from the stack after the call, but that was in the previous version, so you are popping something off the stack that isn't there. The program may not even actually crash because of that since you're not attempting to do a RET unsing whatever SP is pointing to now, but that's still asking for trouble.
Well, you accomplished the objective of demonstrating the use of more than one code segments, but that's not a very useful example as the "outer" code in the segment CODESG does close to nothing, i.e. just set up DS and then call the rest in the other segment before exiting. Ok, you can think of it as a really, really tiny runtime environment... :D
silly me :D
i was extremely tired , and if it weren't for your help on the proc , i wouldn't find out that i'd committed such bizarre error in using procs and stuff , you just saved me for real Eri523 (from banging my head to the wall you know ):D
i would like to know more on these stuff .( you said sth about the slick way of sth ? ! what could that mean ? )
thanks eri523 :wave:
Eri523
February 18th, 2011, 06:30 AM
i would like to know more on these stuff .( you said sth about the slick way of sth ? ! what could that mean ? )
As I said, I can imagine fancy things being done that way but I don't have an example ready. If one comes to mind I'll come back and post it. :)
thanks eri523 :wave:
You're welcome. :)
Master.
February 21st, 2011, 10:17 PM
thanks again :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.