Program to mov data in Assembly Language using emu 8086

 Assembly Language Programming Tutorial

Problem:

Write a program to MOV data using immediate addressing, register addressing and memory addressing in Assembly Language.

Solution:

.model small

.data
num1 dw 1
num2 dw ?

.code
MAIN PROC
  
    MOV AX, data
    MOV DS, AX
  
    ;reg, mem
    MOV AX, num1
  
    ;mem, imm
    MOV num2, 3
  
    ;reg, imm 
    MOV BX, 2
  
    ;reg, reg
    MOV CX, BX
  
    ;mem, reg
    MOV num1, CX

    MOV AX, 04ch
    int 21h
  
ENDP
END MAIN

.model small

The .MODEL directive defines the attributes that affect the entire module: memory model, default calling and naming conventions, operating system & stack type.
The traditional memory models recognized by many languages are small, medium, compact, large, and huge. Small model supports one data segment and one code segment. All data and code are near by default. 

.data

.data represents the data segment of the program. .data is a directive that is used to represent program area where data used by the program is declared and initialized. 

num1 dw 1

num2 dw ?

To declare data in assembly language we need data types, assembly language provide directives for different data types like db is used to define byte (1 byte or 8 bits) and dw is used to define word (2 bytes or 16 bits).
For leaving data uninitialized we use a question mark (?)

.code

The .CODE directive in your program instructs the assembler to start a code segment. This is used to write source code for your program.

MAIN PROC

It represents the start of the main procedure of our program. It defines the entry point of our program. The end of this procedure is denoted by the following instruction.

 ENDP

 MOV 

MOV instruction is used to move data from a source to a destination. It has two operands, destination is written on the left and source is written on the right. Only value of destination is changed after executing this instruction. MOV instruction operands has following standard formats.

Memory to Register

MOV AX, num1

Immediate to Memory

MOV num2, 3

Immediate to Register

MOV BX, 2

Register to Register

MOV CX, BX

Register to Memory

MOV num1, CX

MOV AX, data

MOV DS, AX

These two instruction are used to set the address of data segment in DS. As memory to memory move is not allowed so address is first placed in AX and then to DS.

MOV AX, 04ch

int 21h

These lines are used to call the interrupt to exit program and return 0 in AL. int 21h represents the DOS interrupt.

END MAIN

The END directive instructs the assembler to stop processing this source file. Every assembly language source module must finish with an END directive on a line by itself. Any lines following the END directive are ignored by the assembler.

Source Code:

Assembly Basics, Assembly Language, Coding for beginners, Coding tutorial, Computer Science, Emu 8086, Learn Coding, Learn programming, Programming for beginners, Programming Tutorial

 Register and memory before execution:

Assembly Basics, Assembly Language, Coding for beginners, Coding tutorial, Computer Science, Emu 8086, Learn Coding, Learn programming, Programming for beginners, Programming Tutorial

 Register and memory after execution:

Assembly Basics, Assembly Language, Coding for beginners, Coding tutorial, Computer Science, Emu 8086, Learn Coding, Learn programming, Programming for beginners, Programming Tutorial

Let me know in the comment section if you have any question.

Previous Post: