opurag

MP

May 31st, 2023 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. ADD 8bit:
  2.  
  3. .model small
  4. .data
  5. a db 05h
  6. b db 03h
  7. .code
  8. mov bx, @data
  9. mov ds, bx
  10. mov al, a
  11. mov bl, b
  12. add al, bl
  13. int 21h
  14. end
  15.  
  16. ADD 16bit:
  17.  
  18. .model small
  19. .data
  20. a dw 04h
  21. b dw 03h
  22. c dw 00h
  23. .code
  24. mov bx, @data
  25. mov ds, bx
  26. mov ax, a
  27. mov bx, b
  28. add ax, bx
  29. mov c, ax
  30. int 21h
  31. end
  32.  
  33. MUL 8bit:
  34.  
  35. .model small
  36. .data
  37. a db 05h
  38. b db 03h
  39. c db 00h
  40. .code
  41. mov bx, @data
  42. mov ds, bx
  43. mov al, a
  44. mov bl, b
  45. mul bl
  46. mov c, al
  47. int 21h
  48. end
  49.  
  50. MUL 16bit:
  51. .model small
  52. .data
  53. a dw 04h
  54. b dw 03h
  55. c dw 00h
  56. .code
  57. mov bx, @data
  58. mov ds, bx
  59. mov ax, a
  60. mov bx, b
  61. mul bx
  62. mov c, ax
  63. int 21h
  64. end
  65.  
  66. Sub 8bit:
  67. .model small
  68. .data
  69. a db 05h
  70. b db 03h
  71. c db 00h
  72. .code
  73. mov bx, @data
  74. mov ds, bx
  75. mov al, a
  76. mov bl, b
  77. sub al, bl
  78. mov c, al
  79. int 21h
  80. end
  81.  
  82. Sub 16bit:
  83. .model small
  84. .data
  85. a dw 0Fh
  86. b dw 03h
  87. c dw 00h
  88. .code
  89. mov bx, @data
  90. mov ds, bx
  91. mov ax, a
  92. mov bx, b
  93. sub ax, bx
  94. mov c, ax
  95. int 21h
  96. end
  97.  
  98. Div 8bit:
  99. .model small
  100. .data
  101. a dw 09h
  102. b dw 02h
  103. c dw 00h
  104. d dw 00h
  105. .code
  106. mov bx, @data
  107. mov ds, bx
  108. mov ax, a
  109. mov cx, b
  110. mov dx, d
  111. div cx
  112. mov c, ax
  113. mov d, dx
  114. int 21h
  115. end
  116.  
  117. BCD:
  118. .model small
  119. .code
  120. MOV AL,23H
  121. MOV BL,AL
  122. AND AL,0FH
  123. MOV BH,AL
  124. AND BL,0F0H
  125. MOV CL,04H
  126. ROR BL,CL
  127. MOV AL,0AH
  128. MUL BL
  129. ADD AL,BH
  130. INT 21h
  131. end
  132.  
  133. Posneg:
  134. .model small
  135. .data
  136. a db -12h
  137. msg1 db "The given number is Positive $"
  138. msg2 db "The given number is Negative $"
  139. .code
  140. MOV ax, @data
  141. MOV ds, ax
  142. MOV al, a
  143. rol al, 01
  144. JC next
  145. lea dx, msg1
  146. jmp down
  147. next: lea dx, msg2
  148. down: MOV ah, 09h
  149. int 21H
  150. MOV ah, 4Ch
  151. int 21h
  152. end
  153.  
  154. Evod:
  155. .model small
  156. .data
  157. msg1 db 'Number is even$'
  158. msg2 db 'Number is odd$'
  159. .code
  160. MOV ax,@data
  161. MOV ds,ax
  162. MOV dx,0000h
  163. MOV ax,0021h
  164. MOV bx,0002h
  165. div bx
  166. cmp dx,0000h
  167. JZ ev
  168. lea dx,msg2
  169. jmp next
  170. ev: lea dx, msg1
  171. next: MOV ah, 09h
  172. int 21h
  173. MOV ah,4Ch
  174. int 21h
  175. end
  176.  
  177. count:
  178. .model small
  179. .data
  180. num dw 2345h
  181. z dw 0000h
  182. o dw 0000h
  183. .code
  184. mov ax, @data
  185. mov ds, ax
  186. mov ax, num
  187. mov bx, 00h
  188. mov cx, 10h
  189. mov dx, 00h
  190. up: rol ax, 01
  191. JC one
  192. inc bx
  193. JMP next
  194. one: inc dx
  195. next: dec cx
  196. JNZ up
  197. mov z, bx
  198. mov o, dx
  199. int 21h
  200. end
  201.  
  202. Sort:
  203. .model small
  204. .data
  205. string1 db 56h,99h,12h
  206. .code
  207. mov ax,@data
  208. mov ds,ax
  209. mov ch,02h
  210. up2: mov cl,02h
  211. lea si, string1
  212. up1: mov al,[si]
  213. mov bl,[si+1]
  214. cmp al,bl
  215. jc down
  216. mov dl,[si+1]
  217. xchg [si],dl
  218. mov [si+1],dl
  219. down: inc si
  220. dec cl
  221. JNZ up1
  222. dec ch
  223. JNZ up2
  224. int 21h
  225. end
  226.  
  227. Palindro:
  228. .model small
  229. .data
  230. str db 'MOM'
  231. n dw $-str
  232. rstr db 10 dup(10)
  233. msg1 db "Palindrome$"
  234. msg2 db "Not a Palindrome$"
  235. .code
  236. mov ax,@data
  237. mov ds,ax
  238. mov es,ax
  239. lea si,str
  240. lea di,rstr
  241. add di,n
  242. dec di
  243. mov cx,n
  244. back: cld
  245. lodsb
  246. std
  247. stosb
  248. loop back
  249. mov cx,n
  250. lea si,str
  251. lea di,rstr
  252. cld
  253. repe cmpsb
  254. je dmsg1
  255. lea dx,msg2
  256. jmp exit
  257. dmsg1: lea dx,msg1
  258. exit: mov ah,09h
  259. int 21h
  260. mov ah,4ch
  261. int 21h
  262. end
  263.  
  264. bsearch:
  265. .model small
  266. .data
  267. list db 1h,2h,3h,4h,5h
  268. len dw ($-list)
  269. key db 8h
  270. msg1 db 'key found$'
  271. msg2 db 'key not found$'
  272. .code
  273. mov ax,@data
  274. mov ds,ax
  275. mov si,0
  276. mov di,len
  277. dec di
  278. back:cmp si,di
  279. ja nf
  280. mov bx,si
  281. add bx,di
  282. shr bx,01
  283. mov al,list[bx]
  284. cmp al,key
  285. je yf
  286. jb nm
  287. mov di,bx
  288. sub di,01
  289. jmp back
  290. nm:mov si,bx
  291. add si,01
  292. jmp back
  293. nf: lea dx,msg2
  294. jmp next
  295. yf: lea dx,msg1
  296. next:mov ah,09h
  297. int 21h
  298. mov ah,4ch
  299. int 21h
  300. end
  301.  
  302. strcmp:
  303. .model Large
  304. .data;reserve memory to store string 1
  305. str1 DB 150
  306. DB ? ; string length stored here
  307. DB 150 dup(?); reserve memory array to store string 2
  308.  
  309. str2 DB 150
  310. DB ?
  311. DB 150 dup(?);Messages
  312. msg1 DB 10,10,13,"Strings are Equal $" ;
  313. msg2 DB 10,10,13,"Strings Not Equal $";
  314. msg3 DB 10,13, " Enter string1 $ ";
  315. msg4 DB 10,13, " Enter string2 $ ";
  316. msg5 DB 10,13, " Length of string1 = $";
  317. msg6 DB 10,13, " Length of string2 = $"; macro definition to clear screen
  318. clrscr MACRO
  319. MOV AL, 2
  320. MOV AH,0
  321. INT 10H
  322. ENDM; macro definition to display string on screen
  323. dispm MACRO str
  324. LEA DX, str
  325. MOV AH, 09h
  326. INT 21h
  327. ENDM
  328. .code
  329. MOV AX,@data
  330. MOV DS, AX
  331. MOV ES, AX ; Extra segment required for CMPSB instruction
  332. clrscr
  333. dispm msg3 ; invoke macro to display message
  334. MOV DX, OFFSET str1 ; read string1 from keyboard
  335. MOV AH, 0ah ; using DOS interrupt
  336. INT 21h
  337. dispm msg4
  338. MOV DX, OFFSET str2 ; read string2 from keyboard
  339. MOV AH, 0AH
  340. INT 21h;To display the string1 length
  341. dispm msg5 ; invoke macro
  342.  
  343. MOV DL, str1[1]
  344. ADD DL, 30H
  345. MOV AH, 2
  346. INT 21H;To display the string2 length
  347. dispm msg6
  348. MOV DL, str2[1]
  349. ADD DL, 30H
  350. MOV AH, 2
  351. INT 21H;Compare string lengths
  352. MOV AL, str1[1]
  353. CMP AL, str2[1]
  354. JNE noteq ;If lengths are not equal, display .not equal.
  355. ;If string lengths are equal, then compare two strings
  356. MOV CH, 00h
  357. MOV CL, str1[1] ; get size of string 2 in CL reg
  358. CLD
  359. LEA SI, str1+2
  360. LEA DI, str2+2
  361. repe CMPSB ;Compare the strings usign CMPSB instruction
  362. JNZ noteq ;If they are not equal display .not equal.
  363. dispm msg1 ;If strings are equal, display .Equal.
  364. JMP stop
  365. noteq: dispm msg2 ;Display Not Equal
  366. stop: MOV AH,4CH
  367. INT 21h
  368. END
  369.  
  370.  
  371. DecimalUpCounter:
  372.  
  373. .model small
  374. .data
  375. cnt db 64h
  376. msg db "BCD upcounter"
  377. cr db 13,10,'$'
  378. .code
  379. start: mov ax,@data
  380. mov ds,ax
  381. lea dx,msg
  382. mov ah,09h
  383. int 21h
  384. mov cl,cnt
  385. mov al,00h
  386. lp1: call disp
  387. loop lp1
  388. mov ah,4ch
  389. int 21h
  390. disp proc
  391. mov al,64h
  392. sub al,cl
  393. mov bl,0ah
  394. mov ah,00h
  395. div bl
  396. xchg al,ah
  397.  
  398. mov dl,ah
  399. add dl,'0'
  400. mov ah,02h
  401. push ax
  402. int 21h
  403. pop ax
  404. mov dl,al
  405. add dl,'0'
  406. int 21h
  407. mov dl,0dh
  408. int 21h
  409. push cx
  410. mov bx,01aah
  411. lp: loop lp
  412. dec bx
  413. jnz lp
  414. pop cx
  415. ret
  416. disp endp
  417. end start
  418.  
  419.  
  420.  
Advertisement
Add Comment
Please, Sign In to add comment