Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 12

.

model small
.stack 100h
.data
.code

main proc

mov ah,2
mov dl,'#'
mov cx,80

_loop:
int 21h

loop _loop

main endp
****************************************************
.model small
.stack 100h
.data
.code

main proc

mov ah,1
mov cx,8

_input:
int 21h

loop _input

main endp
;take 8 single key input
***********************************************
.model small
.stack 100h
.data
.code

main proc

mov ah,2
mov cx,5
mov dl,30h

_input:
int 21h
inc dl

loop _input

main endp
;print 1st 5 digit
******************************************
.model small
.stack 100h
.data

msg db "Enter a text$"


array db 10 dup(?),'$'
newl db 0ah,0dh,'$'

.code

main proc
mov ax,@data
mov ds,ax

mov ah,1
mov cx,10
lea si,array

_in:
int 21h
mov [si],al
inc si

loop _in

mov ah,9
lea dx,newl ;show new line
int 21h
lea dx,array
int 21h

main endp
************************************************
.model small
.stack 100h
.data
.code

main proc
mov ax,@data
mov ds,ax

mov ah,1
mov cx,10

_input:
int 21h
jmp _input

main endp
***************************************
.model small
.stack 100h
.datas
.code

main proc
mov ax,@data
mov ds,ax

mov ah,1
mov cx,10

_input:
int 21h
dec cx
jnz _input

main endp
*****************************************
Task 1:
Write a program to take 10 single-key inputs. Terminate the program if the number
of user
input keys exceed the given size or user inputs ‘a’.

.model small
.stack 100h
.data
.code

main proc
mov dx,@data
mov ds,dx

mov ah,1
mov cx,10

_block:
int 21h
cmp al,'a'
je _exit

loop _block

_exit:
mov ah,4ch
int 21h

main endp
*********************************************
Task 4:
Take a user input; if the input is character ‘1’ display ‘O’, if it is ‘2’, display
“E”, if it is anything
else, do nothing.

.model small
.stack 100h
.data
.code

main proc
mov dx,@data
mov ds,dx
mov ah,1
int 21h

cmp al,'1'
je _print1
cmp al,'2'
je _print2

jmp exit ;go to exit if input is none of the above

_print1:
mov ah,2
mov dl,'O'
int 21h
hlt

_print2:
mov ah,2
mov dl,'E'
int 21h
hlt

exit:
mov ah,4ch
int 21h

main endp
*******************************************************
******Even Odd*********

.model small
.stack 100h
.data
.code

main proc
mov dx,@data
mov ds,dx

mov ah,1
int 21h

test al,1
jz _print1

jmp _print2

jmp exit ;go to exit if input is none of the above

_print1:
mov ah,2
mov dl,'E'
int 21h
hlt

_print2:
mov ah,2
mov dl,'O'
int 21h
hlt

exit:
mov ah,4ch
int 21h

main endp
*****************************************************
*******print A to Z**********
.model small
.stack 100h
.code

mov ah,2
mov cx,26
mov dl,41h ;set dl value to 'A'

_loop:
int 21h
inc dl
mov bl,dl ;stores updated value of dl to bl
dec cx

mov dl,10
int 21h
mov dl,0dh
int 21h

mov dl,bl ;restores the value of dl after a line is created

jnz _loop

exit:
mov ah,4ch
int 21h
**************************************************
****count string*******
.model small
.stack 100h
.data
msg db "naureen$"

.code
main proc
mov ax,@data
mov ds,ax

mov ah,9
lea dx,msg
int 21h

mov cx,0
lea si,msg

traverse:
cmp [si],'$'
jz exit
inc cx
inc si
jmp traverse
exit:
mov ah,4ch
int 21h

main endp
********************************************
*******add 2 string************
.model small
.stack 100h
.data
str1 db 'Hello world$'
len1 equ $-str1

str2 db 'This is assembly$'


len2 equ $-str2

str3 db len1+len2 dup(?)

.code
main proc
mov ax,@data
mov ds,ax

lea si,str1
lea di,str3

mov cl,0 ; for count

traverse1:
cmp cl,len1
jz newloop

mov al,[si]
mov [di],al
inc si
inc di
inc cl

jmp traverse1

newloop:
lea si,str2
mov cl,0

traverse2:
cmp cl,len2
jz print

mov al,[si]
mov [di],al
inc si
inc di
inc cl
jmp traverse2

print:
;lea dx,str3
mov ah,9
int 21h
exit:
mov ah,4ch
int 21h

main endp
*****************************************************
*********reverse string********************
.model small
.stack 100h
.data
nl EQU 0dh,0ah
msg1 db "Enter char :$"
msg2 db nl,'output :$'

.code
main proc
mov ax,@data
mov ds,ax

lea dx,msg1
mov ah,9
int 21h

mov ah,1

input:
int 21h
mov bl,al
cmp bl,0dh
je newline
push bx
jmp input

newline:
lea dx,msg2
mov ah,9
int 21h

mov ah,2

output:
pop dx
int 21h
cmp sp,0100h
je exit
jmp output

exit:
mov ah,4ch
int 21h
main endp
*************************************************
*********string equality*****************
.model small
.stack 100h
.data
array1 db 'GOOD$'
array2 db 'GOD$'
msg1 db "String are equal$"
msg2 db 'String are unequal$'

.code
main proc
mov ax,@data
mov ds,ax

lea si,array1
lea di,array2

rep cmpsb

jnz l1
lea dx,msg2
jmp l2

l1:
lea dx,msg2
l2:
mov ah,9
int 21h

exit:
mov ah,4ch
int 21h

main endp
********************************************
***********print star***********
.model small
.stack 100h
.data

.code
main proc
mov ax,@data
mov ds,ax

mov cx,15
l1:
mov bx,cx

l2:
mov dl,'*'
mov ah,2
int 21h

loop l2

mov ah,2
mov dl,0ah
int 21h
mov dl,0dh
int 21h

mov cx,bx

loop l1
ret

exit:
mov ah,4ch
int 21h

main endp
***********************************************************
*************convert hexa************
.model small
.stack 100h
.data
nl equ 0ah,0dh
M1 DB nl,'TYPE A CHARACTER :','$'
M2 DB nl,'THE ASCII CODE OF '
C1 DB ?,' IN HEXA IS ','$'
.code
main proc
mov ax,@data
mov ds,ax

BEGIN:
MOV AH,9 ;prompt user
LEA DX,M1
INT 21h
MOV AH,1 ;read char.
INT 21H
CMP AL,0DH ;if CR exit
JE exit
MOV C1,AL ;store char.
MOV BL,AL ;take a copy of char

MOV AH,9 ;display 2nd MSG


LEA DX,M2
int 21h

MOV CL,4
SHR C1,CL ;prapare for display 1st half
;* note below
ADD C1,30H ;convert to char.
MOV DL,C1
JMP EXE1

continue: AND BL,0FH ;convert 2nd half to char.


CMP BL,9 ;if >9 mean A,B,C…..hex ch.
JG ERROR_

ADD BL,30H ;convert to char.


MOV DL,BL
JMP EXE2
EXE1: MOV AH,2 ;1st half displayed
INT 21H
JMP continue
EXE2: MOV AH,2
INT 21H ;2nd half displayed

JMP BEGIN ;ask if you want to do it again


;------------
ERROR_: ADD BL,37H ;convert to A,B,C…. hexa ch.
MOV DL,BL
MOV AH,2 ;display it

INT 21H
exit:
mov ah,4ch
int 21h

main endp
*******************************************
*************convert binary************
.model small
.stack 100h
.data
M1 DB 'TYPE A CHARACTER :','$'
M2 DB 0AH,0DH,'THE ASCII CODE OF '
C1 DB ?,' IN BINARY IS :','$'
M3 DB 0AH,0DH,'THE NUMBER OF 1 BIT IS '
C2 DB ?,'$'
.code
main proc
mov ax,@data
mov ds,ax

MOV AH,9 ;prompt the user


LEA DX,M1
INT 21H
;-------------
MOV AH,1 ;read character
INT 21H
MOV BL,AL
MOV C1,AL ;store character
MOV AH,9 ;display results

LEA DX,M2
INT 21H

MOV BH,0 ;counter for one’s


MOV CX,8
MOV AH,2
L1: SHL BL,1 ;display content of BL
JC L2
MOV DL,'0'
INT 21H
JMP L4
L2: MOV DL,'1'
INT 21H
INC BH ;count number of one’s
L4: LOOP L1
ADD BH,30H ;convert to char.
MOV C2,BH
MOV AH,9 ;display number of one’s
LEA DX,M3
INT 21H

exit:
mov ah,4ch
int 21h

main endp
**************************************
*********counting number********
start:
lea bx, string
mov ax, 0

compare:
cmp [bx], '$'
jz printer
inc ax
inc bx
jmp compare

printer:
mov ah, 02
mov dx, ax
add dl, '0'
int 21h

ret
**************************************
**************Define and intialize a string, “exercise”. Write a program to count
the number of “e” in “exercise”

Link to solution

org 100h

lea si, string


mov cx, 8h
mov ax, 0h

here:

cmp [si],'e'
jnz there
add ax, 1

there:
inc si

loop here

ret

string DB "exercise$"
**********************************************
***********length of string***************
org 100h
lea si,string
mov ax, 0000h

here:
cmp [si],'$' ;check if end of string
jz there ;jump if end
inc si
add ax, 0001h ;count each char
jmp here

there:
LEA DX, ax
add dx, '0'
mov AH, 02H
int 21h

ret

string DB "pewpew$"

You might also like