有人可以帮助我进行细分和8086 intel的微处理器吗? [英] Can someone help me with segmentation and 8086 intel's microprocessor?

查看:66
本文介绍了有人可以帮助我进行细分和8086 intel的微处理器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读intel 8086的体系结构,无法了解有关分段的以下内容:我知道分段寄存器分别指向分段,并且包含一个64kb长的分段的基址.但是,谁来计算?在哪一点上设置段寄存器中的物理地址?此外,由于一个物理地址可以由多个segment:offset对和segment重叠,所以如何确定不会覆盖某些内容?在哪里可以了解更多有关此的信息?

I am reading about the architecture of intel's 8086 and can't figure out the following things about segmentation: I know that segment registers point to segments respectively and contain the base address of a 64kb long segment. But who calculates and in which point sets the physical address in the segment registers? Also, because one physical address can be accessed by multiple segment:offset pairs and segments can overlap, how you can be sure that you won't overwrite something? Where I can read more about this?

推荐答案

通常来说,汇编器将仅使用偏移地址来访问逻辑地址.例如,看下面的代码:

Generally speaking the Assembler will only use offset addresses to access a logical address. For example looking at this code:

start   lea si,[hello]          ; Load effective address of string
        mov word [ds:si+10],0   ; Zero-terminate string after 10th letter
        jmp $                    ; Loop endlessly

; Fill rest of the segment with 0s
times 65536-($-$$) db 0x00

hello   db "I'm just outside of the current segment. Hello!",0

汇编程序将尝试计算'hello'与程序原点的偏移量.由于未定义原点,因此将假定为0x0.但是,在这种情况下,"hello"的偏移量将为0x10000,不适合16位.因此,汇编程序会将地址截断为0x0000.它不会更改任何段寄存器.但是,它可能会发出警告,例如test.asm:1: warning: word data exceeds bounds.当您运行该程序时,实际上发生的是jmp $行被零覆盖,因为hello的地址环绕并且CPU将开始执行除零以外的任何操作,这不是您想要的.

The assembler will try to calculate the offset of 'hello' from the origin of the program. Since no origin is defined 0x0 will be assumed. However the offset of 'hello' would be 0x10000 in this case, which does not fit 16-bits. Therefor the Assembler will truncate the address to 0x0000. It will not change any of the Segment registers. However it will likely issue a warning, for example test.asm:1: warning: word data exceeds bounds. What actually happens when you run this program is that the jmp $ line is overwritten with zeroes, because the address of hello wrapped around and the CPU will start executing nothing but Zeroes, which was not what you intended to do.

当然只有在代码段和数据段相同的情况下.现在谁能保证是这种情况?真的没有人.尤其是因为我仍然不知道您要为哪个平台编写代码.设置段寄存器正确的值完全是您的责任.最简单的方法是:

That is of course only if the code-segment and data-segment are the same. Now who guarantees that is the case? Nobody really. Especially since I still don't know what platform you are coding for. It is entirely your resposibility to set up the segment registers with correct values. The easiest way to do so is:

push cs   ; Push address of code segment to stack
pop ds    ; Pop address back into data segment
push cs   ; Same for extra data segment
pop es    ;

这样,您可以确定自己正在访问正确数据段中的偏移量.

This way you can be certain your you are accessing the offset in the correct-data segment.

现在关于如何确保代码段不与数据段重叠",为什么不呢?当您的程序中的数据小于64KB时,如果代码和数据段相同,则实际上这是访问数据的最简单方法.

Now regarding 'How do you make sure the code segment doesnt overlap the data segment', why shouldn't it? When your program with data is smaller than 64KB it is actually the easiest way to access data if your code and data segment are identical.

如何确定不覆盖任何重要内容?汇编程序无法帮助您,您必须检查自己是否要写入的segment:offset地址已包含数据.

And how can you be sure that you don't overwrite anything important? Assembler can't help you with that, you have to check yourself if the segment:offset address you are writing to already contains data.

这篇关于有人可以帮助我进行细分和8086 intel的微处理器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆