parent
9bc3cd33e6
commit
ee0eefad66
@ -0,0 +1,25 @@
|
|||||||
|
*Concepts you may want to Google beforehand: segmentation*
|
||||||
|
|
||||||
|
**Goal: learn how to address memory with 16-bit real mode segmentation**
|
||||||
|
|
||||||
|
If you are comfortable with segmentation, skip this lesson.
|
||||||
|
|
||||||
|
We did segmentation
|
||||||
|
with `[org]` on lesson 3. Segmentation means that you can specify
|
||||||
|
an offset to all the data you refer to.
|
||||||
|
|
||||||
|
This is done by using special registers: `cs`, `ds`, `ss` and `es`, for
|
||||||
|
Code, Data, Stack and Extra (i.e. user-defined)
|
||||||
|
|
||||||
|
Beware: they are *implicitly* used by the CPU, so once you set some
|
||||||
|
value for, say, `ds`, then all your memory access will be offset by `ds`.
|
||||||
|
[Read more here](http://wiki.osdev.org/Segmentation)
|
||||||
|
|
||||||
|
Furthermore, to compute the real address we don't just join the two
|
||||||
|
addresses, but we *overlap* them: `segment << 4 + address`. For example,
|
||||||
|
if `ds` is `0x4d`, then `[0x20]` actually refers to `0x4d0 + 0x20 = 0x4f0`
|
||||||
|
|
||||||
|
Enough theory. Have a look at the code and play with it a bit.
|
||||||
|
|
||||||
|
Hint: We cannot `mov` literals to those registers, we have to
|
||||||
|
use a general purpose register before.
|
@ -0,0 +1,27 @@
|
|||||||
|
mov ah, 0x0e ; tty
|
||||||
|
|
||||||
|
mov al, [the_secret]
|
||||||
|
int 0x10 ; we already saw this doesn't work, right?
|
||||||
|
|
||||||
|
mov bx, 0x7c0 ; remember, the segment is automatically <<4 for you
|
||||||
|
mov ds, bx
|
||||||
|
; WARNING: from now on all memory references will be offset by 'ds' implicitly
|
||||||
|
mov al, [the_secret]
|
||||||
|
int 0x10
|
||||||
|
|
||||||
|
mov al, [es:the_secret]
|
||||||
|
int 0x10 ; doesn't look right... isn't 'es' currently 0x000?
|
||||||
|
|
||||||
|
mov bx, 0x7c0
|
||||||
|
mov es, bx
|
||||||
|
mov al, [es:the_secret]
|
||||||
|
int 0x10
|
||||||
|
|
||||||
|
|
||||||
|
jmp $
|
||||||
|
|
||||||
|
the_secret:
|
||||||
|
db "X"
|
||||||
|
|
||||||
|
times 510 - ($-$$) db 0
|
||||||
|
dw 0xaa55
|
Loading…
Reference in new issue