Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ADD 8bit:
- .model small
- .data
- a db 05h
- b db 03h
- .code
- mov bx, @data
- mov ds, bx
- mov al, a
- mov bl, b
- add al, bl
- int 21h
- end
- ADD 16bit:
- .model small
- .data
- a dw 04h
- b dw 03h
- c dw 00h
- .code
- mov bx, @data
- mov ds, bx
- mov ax, a
- mov bx, b
- add ax, bx
- mov c, ax
- int 21h
- end
- MUL 8bit:
- .model small
- .data
- a db 05h
- b db 03h
- c db 00h
- .code
- mov bx, @data
- mov ds, bx
- mov al, a
- mov bl, b
- mul bl
- mov c, al
- int 21h
- end
- MUL 16bit:
- .model small
- .data
- a dw 04h
- b dw 03h
- c dw 00h
- .code
- mov bx, @data
- mov ds, bx
- mov ax, a
- mov bx, b
- mul bx
- mov c, ax
- int 21h
- end
- Sub 8bit:
- .model small
- .data
- a db 05h
- b db 03h
- c db 00h
- .code
- mov bx, @data
- mov ds, bx
- mov al, a
- mov bl, b
- sub al, bl
- mov c, al
- int 21h
- end
- Sub 16bit:
- .model small
- .data
- a dw 0Fh
- b dw 03h
- c dw 00h
- .code
- mov bx, @data
- mov ds, bx
- mov ax, a
- mov bx, b
- sub ax, bx
- mov c, ax
- int 21h
- end
- Div 8bit:
- .model small
- .data
- a dw 09h
- b dw 02h
- c dw 00h
- d dw 00h
- .code
- mov bx, @data
- mov ds, bx
- mov ax, a
- mov cx, b
- mov dx, d
- div cx
- mov c, ax
- mov d, dx
- int 21h
- end
- BCD:
- .model small
- .code
- MOV AL,23H
- MOV BL,AL
- AND AL,0FH
- MOV BH,AL
- AND BL,0F0H
- MOV CL,04H
- ROR BL,CL
- MOV AL,0AH
- MUL BL
- ADD AL,BH
- INT 21h
- end
- Posneg:
- .model small
- .data
- a db -12h
- msg1 db "The given number is Positive $"
- msg2 db "The given number is Negative $"
- .code
- MOV ax, @data
- MOV ds, ax
- MOV al, a
- rol al, 01
- JC next
- lea dx, msg1
- jmp down
- next: lea dx, msg2
- down: MOV ah, 09h
- int 21H
- MOV ah, 4Ch
- int 21h
- end
- Evod:
- .model small
- .data
- msg1 db 'Number is even$'
- msg2 db 'Number is odd$'
- .code
- MOV ax,@data
- MOV ds,ax
- MOV dx,0000h
- MOV ax,0021h
- MOV bx,0002h
- div bx
- cmp dx,0000h
- JZ ev
- lea dx,msg2
- jmp next
- ev: lea dx, msg1
- next: MOV ah, 09h
- int 21h
- MOV ah,4Ch
- int 21h
- end
- count:
- .model small
- .data
- num dw 2345h
- z dw 0000h
- o dw 0000h
- .code
- mov ax, @data
- mov ds, ax
- mov ax, num
- mov bx, 00h
- mov cx, 10h
- mov dx, 00h
- up: rol ax, 01
- JC one
- inc bx
- JMP next
- one: inc dx
- next: dec cx
- JNZ up
- mov z, bx
- mov o, dx
- int 21h
- end
- Sort:
- .model small
- .data
- string1 db 56h,99h,12h
- .code
- mov ax,@data
- mov ds,ax
- mov ch,02h
- up2: mov cl,02h
- lea si, string1
- up1: mov al,[si]
- mov bl,[si+1]
- cmp al,bl
- jc down
- mov dl,[si+1]
- xchg [si],dl
- mov [si+1],dl
- down: inc si
- dec cl
- JNZ up1
- dec ch
- JNZ up2
- int 21h
- end
- Palindro:
- .model small
- .data
- str db 'MOM'
- n dw $-str
- rstr db 10 dup(10)
- msg1 db "Palindrome$"
- msg2 db "Not a Palindrome$"
- .code
- mov ax,@data
- mov ds,ax
- mov es,ax
- lea si,str
- lea di,rstr
- add di,n
- dec di
- mov cx,n
- back: cld
- lodsb
- std
- stosb
- loop back
- mov cx,n
- lea si,str
- lea di,rstr
- cld
- repe cmpsb
- je dmsg1
- lea dx,msg2
- jmp exit
- dmsg1: lea dx,msg1
- exit: mov ah,09h
- int 21h
- mov ah,4ch
- int 21h
- end
- bsearch:
- .model small
- .data
- list db 1h,2h,3h,4h,5h
- len dw ($-list)
- key db 8h
- msg1 db 'key found$'
- msg2 db 'key not found$'
- .code
- mov ax,@data
- mov ds,ax
- mov si,0
- mov di,len
- dec di
- back:cmp si,di
- ja nf
- mov bx,si
- add bx,di
- shr bx,01
- mov al,list[bx]
- cmp al,key
- je yf
- jb nm
- mov di,bx
- sub di,01
- jmp back
- nm:mov si,bx
- add si,01
- jmp back
- nf: lea dx,msg2
- jmp next
- yf: lea dx,msg1
- next:mov ah,09h
- int 21h
- mov ah,4ch
- int 21h
- end
- strcmp:
- .model Large
- .data;reserve memory to store string 1
- str1 DB 150
- DB ? ; string length stored here
- DB 150 dup(?); reserve memory array to store string 2
- str2 DB 150
- DB ?
- DB 150 dup(?);Messages
- msg1 DB 10,10,13,"Strings are Equal $" ;
- msg2 DB 10,10,13,"Strings Not Equal $";
- msg3 DB 10,13, " Enter string1 $ ";
- msg4 DB 10,13, " Enter string2 $ ";
- msg5 DB 10,13, " Length of string1 = $";
- msg6 DB 10,13, " Length of string2 = $"; macro definition to clear screen
- clrscr MACRO
- MOV AL, 2
- MOV AH,0
- INT 10H
- ENDM; macro definition to display string on screen
- dispm MACRO str
- LEA DX, str
- MOV AH, 09h
- INT 21h
- ENDM
- .code
- MOV AX,@data
- MOV DS, AX
- MOV ES, AX ; Extra segment required for CMPSB instruction
- clrscr
- dispm msg3 ; invoke macro to display message
- MOV DX, OFFSET str1 ; read string1 from keyboard
- MOV AH, 0ah ; using DOS interrupt
- INT 21h
- dispm msg4
- MOV DX, OFFSET str2 ; read string2 from keyboard
- MOV AH, 0AH
- INT 21h;To display the string1 length
- dispm msg5 ; invoke macro
- MOV DL, str1[1]
- ADD DL, 30H
- MOV AH, 2
- INT 21H;To display the string2 length
- dispm msg6
- MOV DL, str2[1]
- ADD DL, 30H
- MOV AH, 2
- INT 21H;Compare string lengths
- MOV AL, str1[1]
- CMP AL, str2[1]
- JNE noteq ;If lengths are not equal, display .not equal.
- ;If string lengths are equal, then compare two strings
- MOV CH, 00h
- MOV CL, str1[1] ; get size of string 2 in CL reg
- CLD
- LEA SI, str1+2
- LEA DI, str2+2
- repe CMPSB ;Compare the strings usign CMPSB instruction
- JNZ noteq ;If they are not equal display .not equal.
- dispm msg1 ;If strings are equal, display .Equal.
- JMP stop
- noteq: dispm msg2 ;Display Not Equal
- stop: MOV AH,4CH
- INT 21h
- END
- DecimalUpCounter:
- .model small
- .data
- cnt db 64h
- msg db "BCD upcounter"
- cr db 13,10,'$'
- .code
- start: mov ax,@data
- mov ds,ax
- lea dx,msg
- mov ah,09h
- int 21h
- mov cl,cnt
- mov al,00h
- lp1: call disp
- loop lp1
- mov ah,4ch
- int 21h
- disp proc
- mov al,64h
- sub al,cl
- mov bl,0ah
- mov ah,00h
- div bl
- xchg al,ah
- mov dl,ah
- add dl,'0'
- mov ah,02h
- push ax
- int 21h
- pop ax
- mov dl,al
- add dl,'0'
- int 21h
- mov dl,0dh
- int 21h
- push cx
- mov bx,01aah
- lp: loop lp
- dec bx
- jnz lp
- pop cx
- ret
- disp endp
- end start
Advertisement
Add Comment
Please, Sign In to add comment