Category:8086 Assembly: Difference between revisions

m
 
(2 intermediate revisions by the same user not shown)
Line 39:
 
===Other Registers===
When writing to or reading from consecutive sections of memory, it is helpful to apply an offset from a base value. The Base Pointer register <code>BP</code>, Source Index <code>SI</code>, and Destination Index <code>DI</code> can point to various regions of memory. Many commands that work with these registers can auto-increment or decrement them after each load or store. In addition, they can be optionally offset by a constant, the value stored in <code>BX</code>, or both at the same time. (<code>BX</code> cannot be added to <code>BP</code> in this manner, but it can be added to <code>DI</code>, and <code>SI</code>.) Unlike the data registers, <code>BP</code>,<code>DI</code>, and <code>SI</code> cannot be split in half and worked on separately. Only data registers allow you to work in 8-bit.
 
The syntax for offsetting an index register will vary depending on your assembler. Many assemblers will often accept multiple different ways of writing it, and it comes down to personal preference.
Line 102:
 
While both the 8086 and the 8087 can read the same code, data, and memory, they cannot read the contents of each other's registers. So for example, if you wanted to use the 8087 to perform a calculation and then output the result to the screen, you'd need to give the 8087 the command to do the math and store the result into RAM. Then, the 8086 would read that RAM and output the result to the screen. The 8087 also doesn't have the robust indexed addressing modes of the 8086 - so the 8086 will often do the job of looking up a value from a table, then dumping that value into a temporary "loading zone" at a known location where the 8087 can more easily read from. In order to make sure that the 8086 and 8087 stay in sync, the 8086 can <code>WAIT</code> for the 8087 to finish its current instruction before executing more instructions. This is incredibly useful in the event that the 8086 needs to use a calculation that the 8087 did - it might end up reading from the "loading zone" before the 8087 actually has put the result of the calculation in it! (Most assemblers will handle this for you.)
 
One other caveat to mention: On early IBM PCs and compatibles, the 8087 was not built into the CPU like it is now. Back then, it was sold separately. So if you're programming on original hardware and the floating point commands don't work, it might be because you don't have the coprocessor installed!
 
===Looping Constructs===
Line 119 ⟶ 121:
loop foobar</lang>
 
It may not be obvious at first but the above loop will never end. <code>CX</code> decrements to 0x09990x0FFF with the <code>LOOP</code> instruction but the <code>mov cx,1000h</code> was mistakenly placed ''inside'' the loop, resetting the loop counter back to 0x1000, which means no progress is really being made. The correct way to do this is to set the starting loop counter '''outside''' the loop, like so:
 
<lang asm>mov cx,1000h
1,489

edits