This blog was last modified 428 days before.
Recommend Tutorial
Check this open-sourced guide book of 8086 CPU and assembly: https://github.com/gurugio/book_assembly_8086?tab=readme-ov-file
Complete 8086 CPU Instruction Set: https://www.eng.auburn.edu/~sylee/ee2220/8086_instruction_set.html
Here I recommend that you start with the Github book of the first link. This series is more serve as a note for myself while reading that book, and it is, at least in my point of view, a really good place to start your low level program and ASM tour with. And the chapter of these several notes is correspond to that book, so you can just read these notes at the same pace as you read that book as a additional reference and as an extend of that book.
Other References
CPU Structure Diagram
8086 Software Interrput Manual
For what is Software Interruption , see ASM Learning Note 9 - Go Further.
General-Proposed Register
- AX: called as accumulation register or called as arithmetic register. It is mainly used for calculations.
- BX: This is called as base address register. It is mainly used when calculating memory addresses.
- CX: This is called as counter register. It is mainly used to remember how many times you are repeating in the loop.
- DX: Data register. The result of the calculation is stored or the data read from memory is saved.
- SI: This is called as source index register. Used to store the address of the original data in memory copying.
- DI: This is called the destination index register. It is used to store the address of destination in memory copy etc.
- BP: Base Pointer Register. Used to preserve stack addresses when calling function.
- SP: Stack Pointer Register. The current stack address is saved.
Segment Register
- CS: The address of the segment where the current program is saved is saved.
- DS: The address of the segment where the current data is stored is saved.
- ES: It has no purpose and stores the segment address of the desired memory location whenever necessary.
- SS: The address of the segment with the stack is saved.
Sepcial Purpose Register
- IP: Instruction Pointer register. Indicates the address of the next instruction to be executed.
- Flag register: indicates the status of the processor.
These two register couldn't be modified by programmers, and would automatically changes while the program running.
Flag Register
Flag register is a 16-bit register contains the arithmetic and control info of the CPU.
-
ZF
Zero Flag. If any calculation get a zero result, set to1
. -
CF
Carry Flag. If any calculation of n-bit unsigned number get a result out of the range of n-bit, set to1
. -
AC
Auxiliary Carry. Only used when processing BCD (Binary Coded Decimal) numbers. Could NOT be directly accessed by programmer. -
PF
Parity Flag. If any calculation got an even result, set to1
.
For signed-number calculation:
-
SF
Sign Flag. If any calculation got an negative result, set to1
. -
OF
Overflow Flag. If any signed calculation got an answer out of the range, set to1
.
CPU control-related flags:
-
DF
Directional Flag. When dealing string using little-endian convention, set to1
. -
IF
Interrupt Flag. When CPU could response the external interrupt instruction, set to1
. -
TF
Trap Flag. If1
, generate an interal interrupt after each instruction. This behaviour will be convenient for devs to debug their programs.
For more info about these flags, check:
Memory Addressing
To address a 20-bit address, we should use 2 registers. DS
(Data Segment Register) and SI
(Segment Index Register).
If we set DS = 1230H
, SI = 0045H
(notice that here "H" means "Hexademical"), then the memory address that been accessed would be:
1230H << 4 + 0045H (Or you can say 1230H * 16 + 0045H)
= 12300H + 45H
= 12345H
About SIM8086 Debug Tools
As you can see in the picture, the 4 column from left to right is:
- Instruction Address
- Instruction Data (in
Hexadecimal
) - Instruction Data (in
Decimal
) - Instruction Data Description
No comment