Addtion & Subtraction in ASM

Below coding is the example of addition and subtraction in assembly language.

name "add-sub"
org 100h
mov al,5
mov bl,10
add bl,al
sub bl,1   ;print result in binary
mov cx,8
print: mov ah,2
mov dl,'0'
test bl,10000000b
jz zero
mov dl,'1'
zero: int 21h
shl bl,1
loop print   ;print binary suffix
mov dl,'b'
int 21h  ;wait for any key press
mov ah,0
int 16h

In the above program, “add-sub” is the name of the program.

ORG xxh – The origin directive tells the assembler where to load instructions and data into memory. It changes the program counter to the value specified by the expression in the operand field. If ORG not specified in the program, the program counter set to zero.

In the program, the value 5 is assigned to register a1 and 10 is assigned to b1 and the sum of two register values stored in the register and subtract the value by 1 and print the value in binary values using the loop.

Leave a Reply