Example 1.1

001

002

003

004

005

006

007

008

009

010

; a program to add three numbers using registers

[org 0x0100]

              mov  ax, 5              ; load first number in ax

              mov  bx, 10             ; load second number in bx

              add  ax, bx             ; accumulate sum in ax

              mov  bx, 15             ; load third number in bx

              add  ax, bx             ; accumulate sum in ax

 

              mov  ax, 0x4c00         ; terminate program

              int  0x21

001

To start a comment a semicolon is used and the assembler ignores everything else on the same line. Comments must be extensively used in assembly language programs to make them readable.

002

Leave the org directive for now as it will be discussed later.

003

The constant 5 is loaded in one register AX.

004

The constant 10 is loaded in another register BX.

005

Register BX is added to register AX and the result is stored in register AX. Register AX should contain 15 by now.

006

The constant 15 is loaded in the register BX.

007

Register BX is again added to register AX now producing 15+15=30 in the AX register. So the program has computed 5+10+15=30.

008

Vertical spacing must also be used extensively in assembly language programs to separate logical blocks of code.

009-010

The ending lines are related more to the operating system than to assembly language programming. It is a way to inform DOS that our program has terminated so it can display its command prompt again. The computer may reboot or behave improperly if this termination is not present.

 

 

 

Previous

 

 

TOC

 

 

Next