Displaying 2 digit number Assembly


TITLE Displaying 2 digit number in Assembly
.model small
.stack
.data

.code
mov ax,2579; 2579 will be displayed
mov cx,0
mov bx,10

loop1:
cmp ax,0
je next1
mov dx,0
div bx
push dx
inc cx
jmp loop1

next1:
mov ah,2h
loop2:
pop dx
add dx,48
int 21h
loop loop2

;exit:
mov ax,0
mov ah,4ch
int 21h
end

NEG in Assembly Language


¢NEG X
X := –X


NEG in Assembly Language


TITLE NEG Command in Assembly Language
.MODEL small
.STACK 1000H

.DATA
V1 DW 7
V2 DW 2

.CODE
;LOAD DATA
MOV AX,@DATA
MOV DS,AX

;V1 = V1 + (-V2)
mov BX,V2
NEG BX
ADD V1,BX

;PRINT V1
MOV DX,V1
ADD DX,48
MOV AH,2H
INT 21H

;RETURN CONTROL
mov ah,4ch
int 21h
END

XCHG in Assembly Language



;Following program takes two numbers from user and stores them in v1 and v2 respectively, then exchanges the values of v1 and v2 using XCHG command in assembly Language on 8086.

TITLE XCHG in Assembly Language
.model small
.stack
.data
v1 db ?
v2 db ?

.code
;input first number
mov ah,1h
int 21h

mov v1,al; v1 = first number
int 21h
mov v2,al; v2 = second number


;print v1(first) number
mov ah,2h
mov dl,v1
int 21h
;print v2(2nd) number
mov dl,v2
int 21h



;Xchange values of v1 and v2
mov al,v1
xchg al,v2
mov v1,al

;print newline
mov dl,10
int 21h

;print v1(first) number
mov ah,2h
mov dl,v1
int 21h
;print v2(2nd) number
mov dl,v2
int 21h

mov ax,0
 mov ah,4ch
 int 21h
end

Print String in Assembly Language


Program to print a string in Assembly Language is given below:

;program to print a string in Assembly Language
.model small
.stack
.data
str db "Hello World!",'$'
.code
mov ax, seg str
mov ds, ax
mov ah,09
lea dx,str
int 21h

EXIT:
mov ah,4ch
int 21h
end

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Carriage Return, (ASCII 13D) is the control character to bring the cursor to the start of a line.



Line-feed (ASCII 10D) is the control character that brings the cursor down to the next line on the screen.

(We use the abbreviations CR and LF to refer to Return and Line-feed in comments.)


;How to come to new line while printing in assembly language.
.model small
.stack
.data
str db "First Line",0AH,"SECOND LINE",0AH,"3RD line",'$'
.code
MOV AX,@DATA
MOV DS,AX
MOV AH,09
MOV DX, OFFSET STR
INT 21H

mov ah,4ch
int 21h
end


Alternate way of printing Hello World in Assembly Language

Hello World Program in Assembly Language


Hello World Program in Assembly Language is given below. This program prints Hello World in Assembly Language.

TITLE Hello World Program in Assembly Language
.model small
.stack
.data
str db "Hello World!",'$'
.code
mov ax,@data
mov ds,ax
mov ah,09h
mov dx,offset str
int 21h

EXIT:
mov ah,4ch
int 21h
end

An alternate approach for printing Hello World in Assembly Language

if in Assembly Language

 Take input from user and implement condition:
 If((var > 5 ) && (var < 9))
 {
 Print 1 according to the value of var
 }
 Else
 0



.model small
.stack

.code
mov ah,1h
int 21h

mov bl,al
cmp bl,'5'
jbe below
cmp bl,'9'
jae below
;print 1 according to the value of bl
mov dl,'1'
SUB BL,48
mov cx,bx
mov ah,2h
loop1:
int 21h
loop loop1
JMP EXIT

below:
MOV DL,'0';PRINT 0
MOV AH,2H
INT 21H

EXIT:
mov ah,4ch
int 21h
end

Loop in Assembly Language


TITLE LOOP IN ASSEMBLY LANGUAGE
.model small
.stack
.data
.code
MOV CX,10
L1:
MOV DL,'A'
MOV AH,2H
INT 21H
LOOP L1

MOV AH,4CH
INT 21H
end

See another way:

Loop in Assembly Language

Loop in Assembly Language


TITLE LOOP IN ASSEMBLY LANGUAGE
.model small
.stack

.code
mov bl,10
L1:
MOV AH,2H;PRINT 'A'
MOV DL,'A'
INT 21H
DEC bL
JNZ L1

MOV AH,4CH
INT 21H
end

See another way for

Loop in Assembly Language

Loop in Assembly Language


Loop in Assembly Language

TITLE for (int i = 10; i!=0; i++)
; print 'A'

.model small
.stack

.code
;initializing
mov al,10;
mov bl,al;

;condition
wapis:
cmp bl,0;
;if (bl == 0)
je false
; else
; if (bl != 0)
; print 'A'
mov dl,'A'
mov ah,02h
;decrement
sub bl,1
int 21h
jmp wapis

false:
;Give control back to OS
mov ah,4ch
int 21h

end

Upper-Case to Lower-Case in Assembly Language Program


Program to convert upper-case to Lower-case in Assembly Language.


TITLE Write Assembly program to Input Upper Case letter from user and display it’s lower case. (ADD 32 from ASCII)

.model small
.stack

.code

;Input character
mov ah,07h;
int 21h;

;Capitalize
ADD al,32

;print character
mov ah,02h;
mov dl,al;
int 21h;

;Give control back to OS
mov ah,4ch
int 21h

end


See Also:

Lower-case to Upper-case in Assembly Language Program

Lower-case to Upper-case in Assembly Language Program

Program to convert lower-case to upper-case in Assembly Language.



TITLE Write Assembly program to Input Lower Case letter from user and display it’s upper case. (Subtract 32 in ASCII)

.model small
.stack

.code

;Input character
mov ah,07h;
int 21h;

;Capitalize
sub al,32

;print character
mov ah,02h;
mov dl,al;
int 21h;

;Give control back to OS
mov ah,4ch
int 21h

end


You might be interested in

Upper-Case to Lower-Case in Assembly Language Program

Print character in assembly language



Program to print a character in assembly language is given below.
Write character to standard output. DL = character to write, after
execution AL = DL.

TITLE Print character in assembly language

.model small
.stack

.code
mov dl,'A';
mov ah,02h;
int 21h;

mov ah,4ch;
int 21h;

end

Input character in Assembly Language


TITLE Program to Input character in Assembly Language
.model small
.stack

.code
mov ah,01h;
int 21h;

mov ah,4ch;
int 21h;
end