Program to add numbers using register addressing in Assembly Language using emu 8086

Assembly Language Programming Tutorial

Problem:

Write a program  to add two decimal, binary & hexadecimal numbers using register addressing in Assembly Language.

Solution:

.model
.stack 100h
.data
;data here
.code
main PROC
  
    mov AX,1234
    mov BX,5678
    add AX,BX
  
    MOV BX, 1256h
    MOV CX, 3478h
    ADD BX,CX
  
    MOV CX, 1100b
    MOV DX, 1010b
    ADD CX,DX
  
    int 21h
    mov AX,04ch
    int 21h
  
main ENDP
end main

.model

The .MODEL directive defines the attributes that affect the entire module: memory model, default calling and naming conventions, operating system & stack type.

.stack 100h 

The stack segment holds procedure parameters, local variables, and return addresses.The .STACK directive identifies the area of a program holding the run-time stack, setting its size.

.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.

.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. 

Immediate to Register

mov AX,1234
mov BX,5678
 
MOV BX, 1256h
MOV CX, 3478h 
 
MOV CX, 1100b
MOV DX, 1010b

ADD 

ADD instruction is used to add destination and source and save it in the destination. It has two operands, destination is written on the left and source is written on the right. Value of destination is updated to the sum of both source and destination after the execution of this statement. ADD instruction has different formats, we can add a register to another register.
add AX,BX
ADD BX,CX
ADD CX,DX

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 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 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:
Program to add numbers using immediate addressing using emu 8086