16 bit Assembly
Home Feedback Site Map Instruction Index
All registers are 16 bit however, AX, BX, CX and DX can be split into their 8bit halves.
If you change one of the 8bit halves it effects the total of the main register.
Hence if AH=32 and you make AL=2 then AX=34.
There are also 4 pairs of registers that have special uses.
There is one more register BP the Base Pointer. This can used to point to the start of your program.
When set to address zero it enables code to use direct access addressing, rather than offsets.
When your program first starts it may point to the end of your code, in which case it will help protect
your code from being overwritten by stack data, if the stack overflows.
If you have a small program you should never need to change to ES, DS or SS registers. These Segment addresses can be used to access data outside your 64K code segment. You should never attempt to change the CS and IP registers, they are used to keep track of the current position within your program.
If you need to move the stack, you should only change SS once at start up, to move the stack away from your code segment. Moving the stack later can result in data corruption.
Registers DI, SI and BP can be used in you routines, but it is advisable to reset them to their former values if the values are to be retained when you leave the routine.
When you need to change a segment register SS, DS and ES.
FS and GS are also available. In 16bit assembly they serve no specific purpose, and can be used to store 16bit values.
You can only assign SS to segments 0 to 3 once. Repeated attempts causes an exeption and your program will crash.
It is important to remember that you cannot perform tasks outside the segment you are pointing to. When changing ES you cannot write to segments outside of the current segment until you change it back again.
You can however move data from one segment to another using the MOVSB and MOVSW instructions.
The easiest way to assign a segment is to use the stack as shown in the code sample below.
You can examine the registers at any time by calling a routine like the one below.
It is assential that you save the registers on the stack first before attempting to display them, otherwise their values will be changed by the current operation.
The \\0 in the data string represents a NULL (zero) end of string. The data string will need to be modified for use with your own compiler.
Routines SubDisplayTTYString, SubDisplayTTYNumber, SubDisplayTTYNewLine, SubDisplayTTYPressAnyKey are shown on the Teletype page.
Register can also be used as addresses to access memory addresses.