Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Move cursor in Assembly Language

How to move the cursor in Assembly Language?

Solution:


Example Code:

TITLE READ WHOLE SCREEN AND COPY CONTENT INTO SAVEBUFF
.model small
.stack
.data
hi db "Hi",'$'


.code
print macro string
mov ax,0900h
mov dx,0
mov dx,offset string
int 21h
endm
;-------------------------------------------------------------------------------------------------
start:
main proc
mov ax,@data
mov ds,ax

;move cursor from where copy data will start from screen into saveBuff
mov ax,0200h
mov dx,0200h; move cursor to 3rd row of 0th column
mov bx,0; video page = 0
int 10h

print hi

mov ax,4c00h
int 21h
main endp
end start
end

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

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

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