Category:8086 Assembly: Difference between revisions

m
Line 3:
==Architecture Overview==
===Segmented Memory===
The 8086 uses a segmented memory model, similar to the Super Nintendo Entertainment System. Unlike banked memory models used in the Commodore 64 and late NES games, segment addresses are held in <i>segment registers</i>. These segment registers are 16 bit and get left-shifted by 4 and added to the pointer register of interest to determine the memory address to look up. The 8086 has four in total, but only the Data Segment<code>DS</code> and Extra<code>ES</code> Segmentregisters can be used by the programmer. (The other two arework reserved forwith the stack pointer and instruction pointer, and are loaded for you.) On the 8086, you can only load segment registers with the value in a data register, or with the <code>POP</code> command. So first you must load a segment into a data register, THEN into a segment register.
 
<lang asm>;This is NOT valid code!
Line 12:
mov ax, @data ;I chose AX but I could have used BX, CX, or DX.
mov ds, ax ;load DS with the data segment.</lang>
 
It's important to remember the subtle distinction between a ''segment'' and a ''segment register.'' Your program might have labeled ''segments'' such as <code>.data</code> and <code>.code</code>, but in order to properly read from/write to these sections you'll need to load their memory locations into ''segment registers.''
 
===Data Registers===
1,489

edits