Monday, April 27, 2009

Example

Example 1.1

001 ; a program to add three numbers using registers
002 [org 0x0100]
003 mov ax, 5 ; load first number in ax
004 mov bx, 10 ; load second number in bx
005 add ax, bx ; accumulate sum in ax
006 mov bx, 15 ; load third number in bx
007 add ax, bx ; accumulate sum in ax
008
009 mov ax, 0x4c00 ; terminate program
010 int 0x21

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

The constant 10 is loaded in another register BX.
004


5 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

006 The constant 15 is loade d in the register BX.


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

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

0 comments: