Assembly: Using the Data Segment Register (DS)

前端 未结 1 2079
执笔经年
执笔经年 2021-02-03 11:42

Currently I am in the midst of learning x86 assembly for fun, I\'m love microcontroller programming, so I\'m familiar with assembly.

Currently I\'ve been searching high

1条回答
  •  伪装坚强ぢ
    2021-02-03 12:08

    When the computer is under real mode (the mode the CPU is at when the BIOS executes the bootloader), the method the CPU uses to calculate the address is very simple: Multiply segment register value by 16 (shift bits 4 positions to left), then add the offset.

    For instance in an instruction like "mov ax, [0x1234]" the CPU would use "DS * 0x10 + 0x1234" as the effective address (the first term resolves to zero in your case.) When you have one like "mov ax, [BP+0x32]" then the CPU will use "SS * 0x10 + BP + 0x32". Note that now the CPU used a different segment register (the Stack Segment), and that is because when the BP register is used, the CPU assumes you wan't to access the stack by default (but you can override this by using [DS:BP + 0x32]).

    More o less what I've explained and more can be found at http://wiki.osdev.org/Real_Mode and http://www.internals.com/articles/protmode/realmode.htm and lots of more places.

    BTW, "msg" should be located more or less at 0x7C11 address.

    0 讨论(0)
提交回复
热议问题