简体   繁体   English

如何在装配体8086中使用基本指针来遍历堆栈?

[英]how to use Base Pointer in Assembly 8086 to go through the stack?

I have an assigment in which I have to insert two digit integers into the stack. 我有一个要求,我必须在堆栈中插入两位整数。 Search a number in the stack and return in which position this number is, print all the numbers in the stack and delete a number from the stack. 在堆栈中搜索一个号码,然后返回该号码所在的位置,打印堆栈中的所有号码,然后从堆栈中删除一个号码。

Right now I'm trying to print all the numbers in the stack by going through the stack using the base pointer, but my code doesn't work. 现在,我试图通过使用基本指针遍历堆栈来打印堆栈中的所有数字,但是我的代码不起作用。

mov di,offset bp   
mov ax, [di]     ;trying to move de value stored in di direction in stack to Ax
mov digito,ah
mov digito2,al

mov dl,digito
mov ah,02
int 21h

mov dl,digito2
mov ah,02
int 21h

mov ah,01
int 21h

So in this code I'm trying to print the two number digit by getting the bp into di (so later I can decrement it to go through all the stack), and the passing the number stored in that direction in Ax. 因此,在这段代码中,我尝试通过将bp放入di中来打印两个数字(以便以后我可以将其递减以遍历所有堆栈),并将该方向上存储的数字传递到Ax中。 I'm a newby in assembly so I don't know what I'm doing. 我是大会的新生,所以我不知道自己在做什么。

Thank you in advance for your time. 预先感谢您的宝贵时间。 (And sorry for my english) (对不起我的英语)

Sorry for the delayed reply. 抱歉,回复延迟。 First, bp doesn't really have an "offset", so you could remove that. 首先, bp确实没有“偏移”,因此您可以删除它。 Second, bp won't automatically point into the stack unless you have made it so ( mov bp, sp ). 其次,除非您这样做,否则bp不会自动指向堆栈( mov bp, sp )。

You don't mention an OS, but int 21h identifies it as DOS... which is real mode, segmented memory model. 您没有提到OS,但是int 21h将其标识为DOS ...,这是实模式,分段内存模型。 mov ax, [di] defaults to mov ax, ds:[di] . mov ax, [di]默认为mov ax, ds:[di] If you've assembled this into a ".com" file, cs , ds , es , and ss are all the same. 如果已将其组装到“ .com”文件中,则csdsesss都是相同的。 If you've assembled it into an ".exe" file, this is not so! 如果已将其组装为“ .exe”文件,则并非如此! You may want to write it as mov ax, ss:[di] to be sure. 您可能需要将其写为mov ax, ss:[di] In contrast, mov ax, [bp] defaults to mov ax, ss:[bp] , so you may want to use bp instead of di here. 相反, mov ax, [bp]默认为mov ax, ss:[bp] ,因此您可能要在此处使用bp而不是di I suspect that's how you're "supposed" to do it. 我怀疑这就是您“应该”这样做的方式。 If you've got a ".com" file, you can forget about this part (in 32-bit code you can forget about it too, but that doesn't apply to you). 如果您有一个“ .com”文件,则可以忽略此部分(在32位代码中,您也可以忽略它,但这不适用于您)。

Then... your attempt to print a number isn't really going to work properly. 然后...您尝试打印数字实际上无法正常工作。 Look for "How do I print a number?" 寻找“我如何打印号码?” examples for more information on that - too much to get into here... 有关更多信息的示例-太多内容无法进入这里...

This is too hard an assignment for a beginner, IMO (but "the instructor is always right" :) ). 对于IMO初学者来说,这是一项艰巨的任务(但是“教师永远是对的” :))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM