Assembly 8086 Basic Program Execution Registers

wahyu eko hadi saputro
4 min readJan 1, 2023

--

Assembly is categorized as a low level programming language. In general, the process of assembly is to load instructions from memory to be processed by the CPU or push back the result of the CPU process to memory. CPUs, especially processors, need to fetch data / instruction from RAM / memory, and to speed up the process, processors have internal memory storage locations called registers. Registers sometimes act as temp storage for data / instruction from RAM.

Requirement :

Assembly installation on windows : https://www.youtube.com/watch?v=lCjbwLeLNfs

Useful library : https://github.com/Eazybright/Irvine32

irvine library installation
Assembly source code workspace

General Architecture of microprocessor 8086

EU (Execution Unit) and BIU (Bus Interface Unit) work simultaneously. BIU will access memory and EU executes the instruction fetched by BIU. on this section i only focus on EU.

EU (Execution Unit) Register Explanation :

Kind of register in assembly 8086

There are eight general-purpose registers, six segment registers, a processor status flags register (EFLAGS), and an instruction pointer (EIP). The general-purpose registers are primarily used for arithmetic and data movement.

register schema
Break down of EAX memory

The right 16 bit of EAX is AX and AX is divided into 8 bit high (AH) and 8 bit low (AL).

Breakdown of general some general purpose register
Breakdown of general some general purpose register

AX = Extended accumulator
BX = Extended Base
CX = Extended Counter
DX = Extended Data

Explanation General purpose register:

- EAX (extended accumulator register) is automatically used by multiplication and division instructions. For example, in multiplication operation, one operand is stored in EAX or AX or AL register according to the size of the operand.
- ECX (Extended Counter): The CPU uses ECX or CX as a loop counter.
- EBX (Extended Base Counter) : EBX is used for addressing, particularly when dealing with arrays and strings and EBX can be used as a data register when not used for addressing.
- EDX (Extended data register) : EDX is used for In and Out instructions (input, output), also used to store partial results of Mul and Div operations and in other cases, can be used as a data register
- ESP (Extended stack pointer) : addresses data on the stack (a system memory structure). It is rarely used for ordinary arithmetic or data transfer.
- ESI (extended source index) and EDI (extended destination index registers) are used by high-speed memory transfer instructions.
- EBP (extended frame pointer register) is used by high-level languages to reference function parameters and local variables on the stack. It should not be used for ordinary arithmetic or data transfer except at an advanced level of programming.

Example of assembly code to add 2 integer :

.386
.model flat,stdcall

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib C:\assembly\lib\Irvine32-master\Irvine32.lib
include C:\assembly\lib\Irvine32-master\Irvine32.inc
.data
result DWORD ? ; variable declaration
.code
main:
MOV result, 40
MOV eax, result ;Sets EAX
ADD eax, 10 ; add 10 to EAX
call WriteDec
call CrLf
exit
END main
PS C:\assembly> C:\masm32\bin\ml /c /Zd /coff .\add.asm       
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: .\add.asm
C:\assembly\lib\Irvine32-master\SmallWin.inc(11) : warning A4011: multiple .MODEL directives found : .MODEL ignored
PS C:\assembly> \masm32\bin\Link /SUBSYSTEM:CONSOLE .\add.obj
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

PS C:\assembly> .\add.exe
50

Use command : C:\masm32\bin\ml /c /Zd /coff .\add.asm to compile the .asm code
Use command : \masm32\bin\Link /SUBSYSTEM:CONSOLE .\add.obj to compile the .obj code
Use command : .\add.exe to execute te .exe code.

Source :
Assembly Language for x86 Processors KIP R. IRVINE
80X86 IBM PC and Compatible Computers_ Assembly Language, Design, and Interfacing Volumes I & II (4th Edition)
https://www.tutorialspoint.com/assembly_programming/assembly_registers.html
https://www.cs.virginia.edu/~evans/cs216/guides/x86.html

--

--

No responses yet