DEV Community

Lucas M. Ríos
Lucas M. Ríos

Posted on

Introduction with examples to Emu8086

☢️ Introduction with examples to Emu8086


🔗Related content

You can find repo related in:

🐱‍🏍GitHub

You can connect with me in:

🧬LinkedIn


Resume 🧾

Here we will have a brief introduction with many examples of scripts to Emu8086.

[WARNING ⚠️] This is a low level of programming, so I recommend you be so inspired. 😁

What is Emu8086?

EMU8086 is an emulator that allows you to run and test programs written in assembly language on a Windows computer. It is a software tool that can emulate the hardware and software of a microprocessor, specifically the Intel 8086 microprocessor, which was used in the original IBM PC.

The emulator can be used to write, debug and test programs for the 8086 architecture. It provides an environment that is similar to the actual hardware on which the program would run, allowing programmers to develop code that is optimized for the specific hardware platform.

EMU8086 is popular among students and hobbyists who are interested in learning assembly language programming, as well as in reverse engineering and debugging software. It also includes a built-in assembler, which allows users to write and assemble programs directly within the emulator.

What is assembly?

Assembly language is a low-level programming language that is used to write programs that are executed by a computer's microprocessor. It is a symbolic representation of the machine language code that can be executed by the CPU (Central Processing Unit) of a computer.

Assembly language programs are typically used to control hardware directly, as they can be used to manipulate the individual bits and bytes of a computer's memory and CPU registers. Unlike high-level programming languages such as Java or Python, which are easier to read and write but require an interpreter or compiler to run, assembly language programs are written using mnemonic codes that correspond to specific CPU instructions.

Writing programs in assembly language can be challenging, as programmers must have a good understanding of the underlying hardware and be able to write code that is both efficient and concise. However, assembly language can be useful in situations where high performance or low-level control of hardware is required, such as in embedded systems, operating systems, or device drivers.


Examples

Okay, now we will see some examples. If you want prove this programs you can download Emu8086 remember this is only for Windows systems.

1️⃣Simple example of move data

; Perform a program that exchanges the contents
; of two decimal values defined in data1 and data2

.data
data1 db 11
data2 db 22

.code

EXCHANGE:
    MOV AL, data1
    MOV AH, data2
    MOV data1, AH
    MOV data2, AL

END:
    HLT

Enter fullscreen mode Exit fullscreen mode

2️⃣Simple(no really) example of multiply two numbers interactively

; Make the multiplication of two numbers entered by keyboard,
; to store the result in the result variable
; print the result on the screen

INCLUDE 'EMU8086.INC'

org 100h

.data

Result db ?

.code
    INIT_VAR:
        MOV Result, 0
    GET_VALUES:
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "SET A MULTIPLIER: ",0
        CALL SCAN_NUM
        MOV BL, CL 
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "SET A MULTIPLICATOR: ",0   
        CALL SCAN_NUM
        MOV AL, CL

    MULTIPLY:
        ADD Result, BL
        DEC AL        
        JZ SHW_RESULT
        JMP MULTIPLY 

    SHW_RESULT: 
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "RESULT IS: ", 0       
        MOV AL, Result
        CALL PRINT_NUM

END:
    DEFINE_PTHIS
    DEFINE_SCAN_NUM
    DEFINE_PRINT_NUM 
    DEFINE_PRINT_NUM_UNS  
    DEFINE_CLEAR_SCREEN
    HLT

Enter fullscreen mode Exit fullscreen mode

3️⃣Super simple(defintively no really) example of a calculator

; Perform a program that works as a calculator of 2 whole numbers,
; and allow the 4 basic operations. The keyboard must be entered by the
; numbers and the operation to be performed. Then print the result obtained.
INCLUDE "EMU8086.INC"

ORG 0x100h

.DATA
OPTION DB 0
VALUE1 DB 0
VALUE2 DB 0
RESULT DB 0

.CODE
START:
    GET_OPERATION:
        CALL PTHIS
        DB "SET A OPTION. 1-SUM, 2-SUBSTRACTION, 3-MULT, 4-DIVISION: ",0
        MOV CX, 0
        CALL SCAN_NUM
        MOV OPTION, CL

    GET_NUMS:
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "SET VALUE 1: ",0
        MOV CX, 0
        CALL SCAN_NUM
        MOV VALUE1, CL

        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "SET VALUE 2: ",0 
        MOV CX, 0
        CALL SCAN_NUM
        MOV VALUE2, CL        

    SELECT_OPT:
        MOV AL, OPTION
        SUB AX, 1
        JZ SUM

        MOV AL, OPTION
        SUB AX, 2
        JZ RESTA

        MOV AL, OPTION
        SUB AX, 3
        JZ MULT

        MOV AL, OPTION
        SUB AX, 4
        JZ DIVISION

        JMP NO_VALID

    NO_VALID:
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "OPTION NO VALID",0
        JMP END

    SUM:
        MOV AX, 0
        MOV AL, VALUE1
        ADD AL, VALUE2
        MOV RESULT, AL
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "RESULT DE SUM: ",0
        MOV AX, 0
        MOV AL, RESULT
        CALL PRINT_NUM
        JMP END         

    RESTA:
        MOV AX, 0
        MOV AL, VALUE1
        SUB AL, VALUE2
        MOV RESULT, AL
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "RESULT DE RESTA: ",0 
        MOV AX, 0
        MOV AL, RESULT
        CALL PRINT_NUM
        JMP END

    MULT:
        MOV AX, 0
        MOV BX, 0
        MOV AL, VALUE1
        MOV BL, VALUE2
        IMUL BL
        MOV RESULT, AL
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "RESULT DE MULT: ",0 
        MOV AX, 0
        MOV AL, RESULT
        CALL PRINT_NUM
        JMP END

    DIVISION:
        MOV AX, 0
        MOV AL, VALUE1
        MOV BL, VALUE2
        IDIV BL
        MOV RESULT, AL
        CALL CLEAR_SCREEN
        CALL PTHIS
        DB "RESULT DE DIVISION: ",0
        MOV AX, 0
        MOV AL, RESULT
        CALL PRINT_NUM
        JMP END

END:
    HLT
    DEENDE_PTHIS
    DEENDE_PRINT_NUM
    DEENDE_PRINT_NUM_UNS
    DEENDE_SCAN_NUM  
    DEENDE_CLEAR_SCREEN

Enter fullscreen mode Exit fullscreen mode

You can get more exercises in repo


Say thanks, give like and share if this has been of help/interest 😁🖖


Top comments (0)