Assembly Programs
Assembly Programs
Assembly Programs
Facebook: https://web.facebook.com/AliiHassanSoomro
Gmail: alisoomro666@gmail.com
Youtube: https://www.youtube.com/programology
1. Get an integer from user and display whether the number is even or odd.
mov bl,2
div bl
cmp ah,0
je IsEven
mov dx,10
mov ah,2
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,offset od
mov ah,9
int 21h
mov ah,4ch
int 21h
IsEven:
mov dx,10
mov ah,2
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,offset ev
mov ah,9
int 21h
mov ah,4ch
int 21h
main endp
end main
dosseg
.model small
.stack 100h
.data
.code
main proc
mov ax,@data
mov ds,ax
mov cx,1
mov ax,0
l1:
add ax,cx
add cl,2
cmp cl,100
jl l1
mov dx,0
mov bx,10
mov cx,0
l2:
div bx
push dx
mov dx,0
mov ah,0
inc cx
cmp ax,0
jne l2
mov ah,02h
l3:
pop dx
add dx,48
int 21h
loop l3
mov ah,4ch
int 21h
main endp
end main
dosseg
.model small
.stack 100h
.data
.code
main proc
mov ax,@data
mov ds,ax
mov cx,0
mov ax,0
l1:
add ax,cx
add cl,2
cmp cl,100
jle l1
mov dx,0
mov bx,10
mov cx,0
l2:
div bx
push dx
mov dx,0
mov ah,0
inc cx
cmp ax,0
jne l2
mov ah,02h
l3:
pop dx
add dx,48
int 21h
loop l3
mov ah,4ch
int 21h
main endp
end main
mov cx, 4
mov bl, 0
LEA SI, STRING1
up:
mov al, [SI]
cmp al, bl
jl nxt
mov bl, al
nxt:
inc si
dec cx
jnz up
mov res,bl
mov dl,res
add dl,48
mov ah,2
int 21h
mov ah,4ch
int 21h
main endp
end main
mov cx, 4
mov res,bl
mov dl,res
add dl,48
mov ah,2
int 21h
mov ah,4ch
int 21h
main endp
end main
lea dx,msg
mov ah,9 ;print message
int 21h
mov ah,1
int 21h ;read data from user
cmp al,39h
jnle invalid
lea dx,msg2 ;print message
mov ah,9
int 21h
shr bh,cl
add bh,30h
xor bh,bh
mov bh,bl
add bh,30h
xor bh,bh
mov bh,bl
jmp exit
invalid:
exit:
mov ah,4ch
int 21h
main endp
end main
; Conversion program
; 1) Accept a decimal value (up to 5 digits), and print its hex value
; 3) Quit program.
.MODEL SMALL
.STACK 100h
.DATA
Menu DB 10, 13, 'Enter a choice (1 or 2):'
DB 10, 13, '1) Convert 1 to 5 Decimal values to Hex'
DB 10, 13, '2) Quit Program', 10, 13, '$'
MenuErr DB 10, 13, 'Choice must be a 1, 2, or 3!'
DB 10, 13, 'Try again!', 10, 13, '$'
AskDec DB 10, 13, 'Enter a number with 1 to 5 digits: ', 10, 13, '$'
.CODE
START PROC
MOV AX, @DATA ; Startup code
MOV DS, AX
dispMenu:
MOV DX, OFFSET Menu ; Display menu
MOV AH, 09H
INT 21H
dispErr:
MOV DX, OFFSET MenuErr ; Display menu error.
MOV AH, 09H
INT 21H
JMP dispMenu
goDec:
CALL DEC2HEX ; Call DEC2HEX procedure.
JMP dispMenu
goQuit:
START ENDP
DEC2HEX PROC ; *** Accept a decimal value (up to 5 digits) > print it's hex value.
SDiv1:
mov cx, 0
MOV BX, 16
pop ax
Div1:
END START
.data
counter db 0
curValue db 0
prevValue db 0
octal db 0
msg db "Enter a decimal number and press Enter: $"
octmsg db 13,10,"In octall: $"
.code
main proc
mov ax, @data ;initialize DS
mov ds, ax
accept:
mov ah, 01
int 21h ;read a digit
cmp al, 13 ;compare al with 13
je exit ;jump to label exit if input is 13
inc_ctr:
mov prevValue, al ;move al to prevValue
exit:
mov bl,prevValue ;move prevValue to bl
convertTooctall:
main endp
end main
dosseg
.model small
.stack 100h
.data
ev db 'divisible by 2 and 4$'
od db 'divisible by 3$'
.code
main proc
mov ax,@data
mov ds,ax
mov ah,1
int 21h
mov bl,2
div bl
cmp ah,0
je IsEven
mov dx,10
mov ah,2
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,offset od
mov ah,9
int 21h
mov ah,4ch
int 21h
IsEven:
mov dx,10
mov ah,2
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,offset ev
mov ah,9
int 21h
mov ah,4ch
int 21h
main endp
end main
10. Get 10 number from user and display after placing them in an array .
dosseg
.model small
.stack 100h
.data
msg db 'Please 10 Digits: $'
array db 11 dup('$')
.code
main proc
mov ax,@data
mov ds,ax
lea si,array
l1:
mov ah,1
int 21h
cmp al,13
je Print
mov [si],al ; placing in array
inc si
jmp l1
Print:
mov dx,10
mov ah,2
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,offset array ; displaying array to get confirm numbers are placed
mov ah,9
int 21h
mov ah,4ch
int 21h
main endp
end main
dosseg
.model small
.stack 100h
.data
msg db 'Please 5 Digits in terms of array: $'
array db 11 dup('$')
.code
main proc
mov ax,@data
mov ds,ax
lea si,array
l1:
mov ah,1
int 21h
cmp al,13
je Print
cmp al,bl
je l1
mov [si],al ; placing in array
inc si
jmp l1
Print:
mov dx,10
mov ah,2
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,offset array ; displaying array to get confirm numbers are placed
mov ah,9
int 21h
mov ah,4ch
int 21h
main endp
end main