Assembly Language Programming Tutorial
Problem:
Write a program to add two decimal, binary & hexadecimal numbers using immediate addressing in Assembly Language.
Solution:
.model
.stack 100h
.data
;data here
.code
main PROC
MOV AX,1234
ADD AX,5678
MOV BX, 1234h
ADD BX, 5678h
MOV CX,1100110011001100b
ADD CX,1010101010101010b
int 21h
mov AX,04ch
int 21h
.stack 100h
.data
;data here
.code
main PROC
MOV AX,1234
ADD AX,5678
MOV BX, 1234h
ADD BX, 5678h
MOV CX,1100110011001100b
ADD CX,1010101010101010b
int 21h
mov AX,04ch
int 21h
.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, 1234h
MOV CX,1100110011001100b
ADD AX,5678
ADD BX, 5678h
ADD CX,1010101010101010b
MOV BX, 1234h
MOV CX,1100110011001100b
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 directly add an immediate value to a register or memory.ADD AX,5678
ADD BX, 5678h
ADD CX,1010101010101010b
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:
Registers before Execution:
Registers after execution:
Let me know in the comment section if you have any question.
Previous Post:
Program to mov data in Assembly Language using emu 8086
Previous Post:
Program to mov data in Assembly Language using emu 8086