Skip to content

Instantly share code, notes, and snippets.

@pncnmnp
Created November 6, 2019 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pncnmnp/65dfc6bfd8240a8f2737866783ee0640 to your computer and use it in GitHub Desktop.
Save pncnmnp/65dfc6bfd8240a8f2737866783ee0640 to your computer and use it in GitHub Desktop.
.model small
.data
res1 db 10,13,"Enter the bcd value: $"
iresult db 10,13,"Hex value is: $"
result db 10,13,"Ascii value is: $"
.code
mov ax,@data
mov ds,ax
lea dx,res1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
and bl,0f0h
mov cl,04h
ror bl,cl
add bl,30h
cmp bl,39h
jle next
sub bl,07h
next: sub bl,30h
ror bl,cl
mov bh,al
and bh,0fh
add bh,30h
cmp bh,39h
jle next1
sub bh,07h
next1: sub bh,30h
mov dl,00h
add bl,bh
s10: cmp bl,10
jl done
sub bl,10
add dl,10h
jmp s10
done: add dl,bl
mov al,dl
mov bl,dl
and bl,0f0h
ror bl,cl
add bl,30h
and al,0fh
add al,30h
mov bh,al
lea dx,result
mov ah,09h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov dl,bh
mov ah,02h
int 21h
mov ah,4ch
int 21h
end
.model small
.data
str1 db 07h,09h,08h,01h,06h
result db 10,13,"The result is: $"
.code
mov ax,@data
mov ds,ax
mov cl,04h
lea si,str1
mov al,[si]
inc si
up: mov bl,[si]
cmp bl,al ;is bl > al
jg next ;if bl is greater move to next
mov al,bl
next: inc si
dec cl
jnz up
add al,30h
lea dx,result
mov ah,09h
int 21h
mov dl,al
mov ah,02h
int 21h
mov ah,4ch
int 21h
end
.model small
.data
num1 db 10,13,"Enter the first number: $"
num2 db 10,13,"Enter the second number: $"
result db 10,13,"Result is: $"
.code
mov ax,@data
mov ds,ax
lea dx,num1
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,30h
mov cl,04h
ror al,cl
mov bl,al
mov ah,01h
int 21h
sub al,30h
add bl,al ;first digit stored in bl
lea dx,num2
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,30h
ror al,cl
mov bh,al
mov ah,01h
int 21h
sub al,30h
add bh,al ;second digit stored in bh
add bl,bh ;result is stored in bl
daa
mov ch,00h
adc ch,00h
add ch,30h
mov al,bl
and al,0f0h
ror al,cl
add al,30h
mov bh,al ;first digit
and bl,0fh
add bl,30h ;second digit
lea dx,result
mov ah,09h
int 21h
mov dl,ch
mov ah,02h
int 21h
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
end
.model small
.data
.code
mov cx,0607h
mov ah,01h
int 10h
mov ah,4ch
int 21h
end
.model small
.data
num1 db 10,13,"Enter a number: $"
result db 10,13,"Factorial of a number is: $"
.code
mov ax,@data
mov ds,ax
lea dx,num1
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,39h
jle ne1
sub al,07h
ne1: sub al,30h
mov cl,al
mov ax,0001h
mov ch,01h
up1: mul ch
inc ch
dec cl
jnz up1
mov bl,al
mov bh,al
and bh,0f0h
mov cl,04h
ror bh,cl
cmp bh,09h
jle next1
add bh,07h
next1: add bh,30h ;third digit in bh
and bl,0fh
cmp bl,09h
jle next2
add bl,07h
next2: add bl,30h ;fourth digit in bl
mov ch,ah
and ch,0f0h
ror ch,cl
cmp ch,09h
jle next3
add ch,07h
next3: add ch,30h ;second digit in ch
mov cl,ah
and cl,0fh
cmp cl,09h
jle next4
add cl,07h
next4: add cl,30h ;first digit in cl
lea dx,result
mov ah,09h
int 21h
mov dl,ch
mov ah,02h
int 21h
mov dl,cl
mov ah,02h
int 21h
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
end
.model small
.data
num1 db 10,13,"Enter hex digit number: $"
num2 db 10,13,"Enter another hex digit number: $"
result db 10,13,"Result: $"
.code
mov ax,@data
mov ds,ax
lea dx,num1
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,39h
jle next1
sub al,07h
next1: sub al,30h
mov cl,04h
ror al,cl
mov bh,al
mov ah,01h
int 21h
cmp al,39h
jle next2
sub al,07h
next2: sub al,30h
add bh,al ;store digit 1 in bh
lea dx,num2
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,39h
jle next3
sub al,07h
next3: sub al,30h
mov cl,04h
ror al,cl
mov bl,al
mov ah,01h
int 21h
cmp al,39h
jle next4
sub al,07h
next4: sub al,30h
add bl,al ; store digit 2 in bl
add bl,bh ;store result in bl
mov al,bl
mov bh,al
mov ch,00h
adc ch,00h
add ch,30h
and al,0f0h
ror al,cl
mov bl,al
cmp bl,09h
jle next5
add bl,07h
next5: add bl,30h ;first digit in bl
mov al,bh;
and al,0fh
cmp al,09h
jle next6
add al,07h
next6: add al,30h
mov bh,al ;second digit in bh
lea dx,result
mov ah,09h
int 21h
mov dl,ch
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov dl,bh
mov ah,02h
int 21h
mov ah,4ch
int 21h
end
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.model small
.data
omenu db 10,13,"Menu:$"
oadd db 10,13,"1. Addition$"
osub db 10,13,"2. Subtract$"
omul db 10,13,"3. Multiply$"
odiv db 10,13,"4. Divide$"
ochoice db 10,13,"Choose a value: $"
result db 10,13,"Result is: $"
errr db 10,13,"Wrong choice!"
num1 equ 04h
num2 equ 02h
.code
mov ax,@data
mov ds,ax
disp omenu
disp oadd
disp osub
disp omul
disp odiv
disp ochoice
mov ah,01h
int 21h
cmp al,31h
je addi
cmp al,32h
je subs
cmp al,33h
je mult
cmp al,34h
je divi
jmp wrong
wrong: disp errr
jmp go
addi: mov al,num1
add al,num2
call ans
jmp go
subs: mov al,num1
sub al,num2
call ans
jmp go
mult: mov ah,00h
mov al,num1
mov bl,num2
mul bl
call ans
jmp go
divi: mov ah,00h
mov al,num1
mov bl,num2
div bl
call ans
jmp go
ans proc near
mov bl,al
and al,0f0h
mov cl,04h
ror al,cl
cmp al,09h
jle next
add al,07h
next: add al,30h
and bl,0fh
cmp bl,09h
jle next2
add bl,07h
next2: add bl,30h
mov bh,al
disp result
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
go: mov ah,4ch
int 21h
end
.model small
.data
str1 db 10h,07h,08h,55h,23h
.code
mov ax,@data
mov ds,ax
mov ch,04h
up2: mov cl,04h
lea si,str1
up1: mov al,[si]
mov bl,[si+1]
cmp al,bl
jg next
mov bh,[si+1]
xchg [si],bh
mov [si+1],bh
next: inc si
dec cl
jnz up1
dec ch
jnz up2
mov ah,4ch
int 21h
end
.model small
.data
str1 db 9 dup('$')
str2 db 9 dup('$')
str3 equ 'c'
ent db 10,13,"Enter the string: $"
displ db 10,13,"The length of the string is: $"
match db 10,13,"Matched!$"
nmatch db 10,13,"Not matched!$"
.code
mov ax,@data
mov ds,ax
mov es,ax
lea si,str1+2
lea di,str2+2
lea dx,ent
mov ah,09h
int 21h
lea dx,str1
mov ah,0ah ;to take input string
int 21h
lea dx,displ
mov ah,09h
int 21h
mov dl,str1+1
mov cx,dx
mov bx,dx
add dl,30h
mov ah,02h
int 21h
cld
rep movsb
lea di,str2+2
mov al,str3
mov cx,bx
cld
repnz scasb
jz nma
jnz ma
nma: lea dx,match
mov ah,09h
int 21h
jmp go
ma: lea dx,nmatch
mov ah,09h
int 21h
jmp go
go: mov ah,4ch
int 21h
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment