Advertisement
Guest User

micro

a guest
Apr 5th, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.23 KB | None | 0 0
  1. Important programs of 8086 (Exam point of view)
  2. 1. Write an ALP to find factorial of number for 8086. MOV AX, 05H
  3. MOV CX, AX
  4. Back: DEC CX
  5. MUL CX
  6. LOOP back
  7. ; results stored in AX
  8. ; to store the result at D000H
  9. MOV [D000], AX
  10. HLT
  11.  
  12.  
  13.  
  14. 2. The 8 data bytes are stored from memory location E000H to E007H. Write 8086 ALP to
  15. transfer the block of data to new location B001H to B008H. MOV BL, 08H
  16. MOV CX, E000H
  17. MOV EX, B001H
  18. Loop: MOV DL, [CX]
  19. MOV [EX], DL
  20. DEC BL
  21. JNZ loop
  22. HLT
  23.  
  24.  
  25.  
  26.  
  27. 3. Write a program to display string ëElectrical and Electronics Engineeringí for 8086. Title display the string
  28. Dosseg
  29. Written by CHANDRA THAPA (October 2012) 2
  30. .model small
  31. .stack 100h
  32. .data
  33. String1 db ëElectrical and Electronics Engineeringí, $
  34. .code
  35. Main proc
  36. MOV AX, @data
  37. MOV DS, AX
  38. MOV AH, 09H
  39. MOV DX, offset String1
  40. INT 21H
  41. MOV AH, 4CH
  42. INT 21H
  43. Main endp
  44. End Main
  45.  
  46.  
  47.  
  48.  
  49. 4. Write a program to reverse the given string for 8086. Title reverse the given string
  50. Dosseg
  51. .model small
  52. .stack 100h
  53. .data
  54. String1 db ëassembly language programí, $
  55. Length dw $-String1-1
  56. .code
  57. Written by CHANDRA THAPA (October 2012) 3
  58. Main proc
  59. MOV AX, @data
  60. MOV DS, AX
  61. MOV SI, offset String1
  62. MOV CX, Length
  63. ADD SI, CX
  64. Back: MOV DL, [SI]
  65. MOV AH, 02H
  66. INT 21H
  67. DEC SI
  68. LOOP Back
  69. MOV AH, 4CH
  70. INT 21H
  71. Main endp
  72. End Main
  73.  
  74.  
  75.  
  76.  
  77. 5. Write a program to multiply 2 numbers (16-bit data) for 8086. Title multiply two numbers
  78. Written by CHANDRA THAPA (October 2012) 4
  79. .code
  80. MULT proc
  81. MOV AX, @data
  82. MOV DS, AX
  83. MOV AX, Multiplicant
  84. MUL Multiplier
  85. MOV Product, AX
  86. MOV Product+2, DX
  87. MOV AH, 4CH
  88. INT 21H
  89. MULT endp
  90. End MULT
  91.  
  92.  
  93.  
  94.  
  95. 6. Sum of series of 10 numbers and store result in memory location total. Title Sum of series
  96. Dosseg
  97. .model small
  98. .stack 100h
  99. .data
  100. List db 12,34,56,78,98,01,13,78,18,36
  101. Total dw ?
  102. .code
  103. Main proc
  104. MOV AX, @data
  105. MOV DS, AX
  106. MOV AX, 0000H
  107. Written by CHANDRA THAPA (October 2012) 5
  108. MOV CX, 0AH ; counter
  109. MOV BL, 00H ; to count carry
  110. MOV SI, offset List
  111. Back: ADD AL, [SI]
  112. JC Label
  113. Back1: INC SI
  114. LOOP Back
  115. MOV Total, AX
  116. MOV Total+2, BL
  117. MOV AH, 4CH
  118. INT 21H
  119. Label: INC BL
  120. JMP Back1
  121. Main endp
  122. End Main
  123.  
  124.  
  125.  
  126.  
  127. 7. Write a program to find Largest No. in a block of data. Length of block is 0A. Store the
  128. maximum in location result. Title maximum in given series
  129. Dosseg
  130. .model small
  131. .stack 100h
  132. .data
  133. List db 80, 81, 78, 65, 23, 45, 89, 90, 10, 99
  134. Result db ?
  135. Written by CHANDRA THAPA (October 2012) 6
  136. .code
  137. Main proc
  138. MOV AX, @data
  139. MOV DS, AX
  140. MOV SI, offset List
  141. MOV AL, 00H
  142. MOV CX, 0AH
  143. Back: CMP AL, [SI]
  144. JNC Ahead
  145. MOV AL, [SI]
  146. Ahead: INC SI
  147. LOOP Back
  148. MOV Result, AL
  149. MOV AH, 4CH
  150. INT 21H
  151. Main endp
  152. End Main
  153.  
  154.  
  155.  
  156.  
  157. 8. Find number of times letter ëeí exist in the string ëexerciseí, Store the count at memory
  158. ans. Title string operation
  159. Dosseg
  160. .model small
  161. .stack 100h
  162. .data
  163. Written by CHANDRA THAPA (October 2012) 7
  164. String db ëexerciseí, $
  165. Ans db ?
  166. Length db $-String
  167. .code
  168. Main proc
  169. MOV AX, @data
  170. MOV DS, AX
  171. MOV AL,00H
  172. MOV SI, offset String
  173. MOV CX, Length
  174. Back: MOV BH, [SI]
  175. CMP BH, ëeí JNZ Label
  176. INC AL
  177. Label: INC SI
  178. LOOP Back
  179. MOV Ans, AL
  180. MOV AH, 4CH
  181. INT 21H
  182. Main endp
  183. End Main
  184.  
  185.  
  186.  
  187.  
  188. 9. Write an ALP to generate square wave with period of 200µs and address of output
  189. device is 55H for 8086 microprocessor. START: MOV AX, 01H
  190. OUT 30H, AX
  191. Written by CHANDRA THAPA (October 2012) 8
  192. ; to generate loop for 200 µs using system frequency 5MHz
  193. MOV BX, Count ;7T
  194. Label: DEC BX ;4T
  195. JNZ Label ;10T/7T
  196. MOV AX, 00H
  197. OUT 30H, AX
  198. MOV BX, Count
  199. Label1: DEC BX
  200. JNZ Label1
  201. JMP START
  202. Note: Find the value of Count using technique used in 8085 so that delay will be of 200 µs.
  203.  
  204.  
  205.  
  206. 10. Write an assembly language program to count number of vowels in a given string. Title to count number of vowels in given line of a text
  207. Dosseg
  208. .model small
  209. .stack 100h
  210. .code
  211. Main proc
  212. MOV AX, @data
  213. MOV DS, AX
  214. MOV SI, offset String ;initialize p
  215. MOV CX, Len ;length in CX register
  216. MOV BL, 00 ;vowel count=0
  217. Written by CHANDRA THAPA (October 2012) 9
  218. Back: MOV AL, [SI]
  219. CMP AL, ëaí JB VOW
  220. CMP AL, ëzí ;Convert the character to upper case
  221. JA VOW
  222. SUB AL, 20H
  223. VOW: CMP AL, ëAí JNZ a3
  224. INC BL
  225. JMP a2
  226. a3: CMP AL, ëEí JNZ a4
  227. INC BL
  228. JMP a2
  229. a4: CMP AL, ëIí JNZ a5
  230. INC BL
  231. JMP a2
  232. a5: CMP AL, ëOí JNZ a6
  233. INC BL
  234. JMP a2
  235. a6: CMP AL, ëUí JNZ a2
  236. INC BL
  237. Written by CHANDRA THAPA (October 2012) 10
  238. a2: INC SI
  239. LOOP Back
  240. MOV Vowel, BL
  241. MOV AX, 4C00H
  242. INT 21H
  243. Main endp
  244. .data
  245. String db ëThe quick brown fox jumped over lazy sleeping dogí, $
  246. Len dw $-string
  247. Vowel db ?
  248. End Main
  249.  
  250.  
  251.  
  252.  
  253. 11. Write an 8086 ALP which will input the user name from the keyboard. If the user is
  254. ëPokharaí it will output ëThe username is validí else it will output ëInvalid user nameí. Note: This program is not verified in MASM so, please verify this program. This program can be
  255. done in the same approach as question 10, which is done above by comparing each character
  256. input.
  257. title input name and comparision
  258. dosseg
  259. .model small
  260. .stack 100h
  261. .data
  262. input db 7 dup(?)
  263. comparestring db 'Pokhara','$' outputstring1 db 'The username is valid','$' outputstring2 db 'The username is invalid','$'
  264. .code
  265. main proc
  266. mov ax, @data
  267. mov ds, ax
  268. ; read string
  269. mov dx, offset input
  270. Written by CHANDRA THAPA (October 2012) 11
  271. mov ah,0ah
  272. int 21h
  273. ;string comparision
  274. mov si, offset input
  275. mov di, offset comparestring
  276. mov cx,07h ;length of string in cx
  277. CLD ; DF-> direction flag clear i.e. autoincrement mode
  278. repe cmpsw ;compare words of two string if equal then ZF will be set
  279. JZ label1
  280. mov dx, offset outputstring2
  281. jmp label2
  282. label1: mov dx, offset outputstring1
  283. label2: mov ah, 0ah
  284. int 21h
  285. mov ah,4ch
  286. int 21h
  287. main endp
  288. end main
  289.  
  290.  
  291. Q: Convert binary to hexadecimal
  292. JMP HERE
  293. num db 1,0,0,1,0,0,1,1
  294. res db ?
  295. HERE:
  296. LEA SI, num
  297. MOV CL, 08H ; COUNT
  298. MOV AL, 00H ; RESULT
  299.  
  300. AGAIN: MOV BL, [SI] ; FIRST ARRAY ITEM
  301. CMP BL, 01H
  302. JNE NEXT
  303. OR AL, 01H
  304. NEXT:
  305. cmp CL,01h
  306. JE end
  307. SHL AL, 01H
  308. INC SI
  309. LOOP AGAIN
  310. MOV res, AL
  311. end: HLT
  312.  
  313. 1: To perform basic arithmetic operations using 8 bit and 16 bit number (Add, SUB, MUL, and DIV).
  314.  
  315. Sol:
  316. Add:
  317.  
  318. MOV AX,3000h
  319. MOV DS,AX
  320. MOV AX,[0200h]
  321. MOV BX,[0202h]
  322. ADD AX,BX
  323. HLT
  324.  
  325. Sub:
  326.  
  327. MOV AX,3000h
  328. MOV DS,AX
  329. MOV AX,[0200h]
  330. MOV BX,[0202h]
  331. SUB AX,BX
  332. HLT
  333. Multiply:
  334.  
  335. MOV AX,3000h
  336. MOV DS,AX
  337. MOV AX,[0200h]
  338. MOV BX,[0202h]
  339. MUL BX
  340. HLT
  341.  
  342. Division:
  343.  
  344. MOV AX,3000h
  345. MOV DS,AX
  346. MOV AX,[0200h]
  347. MOV BX,[0202h]
  348. DIV BX
  349. HLT
  350.  
  351.  
  352. 2: Write an ALP to perform the sum and average of 5 numbers stored in the address location 2000h onwards and put the result in memory locations starting from 5000h onwards.
  353.  
  354. Sol:
  355.  
  356. mov bx,2000h
  357. mov al,[bx]
  358. incbx
  359. add al,[bx]
  360. incbx
  361. add al,[bx]
  362. incbx
  363. add al,[bx]
  364. incbx
  365. add al,[bx]
  366. mov bx,5000h
  367. mov [bx],al
  368. incbx
  369. mov cl,0005h
  370. div cl
  371. mov [bx],ax
  372. hlt
  373.  
  374.  
  375. 3: Write a program to count the number of 1’s in a given byte located in AL register..( Hint Use Rotate instruction : Eg : Input(AL) : 0A7 h Output : 5))
  376.  
  377. Sol:
  378.  
  379.  
  380. Algorithm:
  381. 1. Move any number to al regiter.
  382. 2. Move 8 to dl register.
  383. 3. Rotate left al register 1 bit.
  384. 4. If carry bit =1 increment bl register.
  385. 5. Decrement dl register.
  386. 6. If dl register is not equal to zero goto Step No. 3,
  387. Else Stop.
  388.  
  389. Code:
  390. mov al,0A7h
  391. mov dl,08h
  392. again: rol al,1
  393. jnc next
  394. incbl
  395. next:dec dl
  396. jnz again
  397. hlt
  398.  
  399.  
  400. Aim: To print the multiplication table for number 07.
  401. Algorithm:
  402.  
  403. 1. Mov the number whose table is to be calculated to al – 07
  404.  
  405. 2. Mov al to bl
  406.  
  407. 3. Start counter cl = 01
  408.  
  409. 4. Define the storing location in DI – 2000
  410.  
  411. 5. Run a loop to print table.
  412.  
  413. 6. Mul al by cl.
  414.  
  415. 7. Store in DI
  416.  
  417. 8. Inc cl and DI
  418.  
  419. 9. Check if cl = 0A.
  420.  
  421. 10. If yes hlt
  422.  
  423. 11. Else loop to 6.
  424.  
  425.  
  426.  
  427. Code:
  428.  
  429. MOV AL,07H
  430.  
  431. MOV BL, AL
  432.  
  433. MOV CL, 01H
  434.  
  435. MOV DI, 2000H
  436.  
  437. BACK: MUL CL
  438.  
  439. MOV [DI], AL
  440.  
  441. INC DI
  442.  
  443. MOV AL, BL
  444.  
  445. INC CL
  446.  
  447. CMP CL, 0AH
  448.  
  449. JLE BACK
  450.  
  451. HLT
  452.  
  453. Aim: To Check whether the given number is prime or not
  454.  
  455. Code:
  456.  
  457. jmp here
  458.  
  459. num db 11h
  460.  
  461. here:mov al,num
  462.  
  463. mov cl,al
  464.  
  465. mov bl,02h
  466.  
  467. again: div bl
  468.  
  469. cmp ah,00h
  470.  
  471. je notprime
  472.  
  473. inc bl
  474.  
  475. mov al,cl
  476.  
  477. cmp al,bl
  478.  
  479. jl again
  480.  
  481. mov dl,'A'
  482.  
  483. hlt
  484.  
  485. notprime: mov dl,'B'
  486.  
  487. hlt
  488.  
  489.  
  490.  
  491. Aim: To generate the Fibonacci series for N terms.
  492.  
  493.  
  494. Code:
  495.  
  496. mov al, 01h
  497.  
  498. mov dl, 01h
  499.  
  500. mov cl, 06h
  501.  
  502. mov ch, al
  503.  
  504. mov bx, 2000h
  505.  
  506. mov [bx], al
  507.  
  508. dec cl
  509.  
  510. inc bx
  511.  
  512. mov [bx], dl
  513.  
  514. dec cl
  515.  
  516. inc bx
  517.  
  518. start: add al,dl
  519.  
  520. mov [bx],al
  521.  
  522. inc bx
  523.  
  524. mov dl, ch
  525.  
  526. mov ch, al
  527.  
  528. dec cl
  529.  
  530. cmp cl, 00h
  531.  
  532. je finish
  533.  
  534. jmp start
  535.  
  536. finish: hlt
  537.  
  538.  
  539. Aim: To find the factorial of a number with and without using loop instruction
  540.  
  541. Mov al,05h
  542. Mov bl,al
  543. Back: dec bl
  544. Mul bl
  545. Cmp bl,02h
  546. Jne back
  547. Hlt
  548.  
  549. Aim: To perform the following string operations length, reverse and compare.
  550.  
  551. Code:
  552.  
  553. jmp Here
  554.  
  555. msg db 'Try String_1$'
  556.  
  557. msga db 'Try String_2$'
  558.  
  559. msgrev db 20 dup(' ')
  560.  
  561.  
  562.  
  563. Here:
  564.  
  565. Mov SI,Offset msg
  566.  
  567. Mov cx,00h
  568.  
  569. Again:
  570.  
  571. Mov al,[SI]
  572.  
  573. cmp al,'$'
  574.  
  575. je stop
  576.  
  577. inc cx
  578.  
  579. jmp last
  580.  
  581. last:
  582.  
  583. inc SI
  584.  
  585. jmp Again
  586.  
  587. stop:
  588.  
  589. mov di,2000h
  590.  
  591. mov [di],cx
  592. rev:
  593.  
  594. mov bx,cx
  595.  
  596. add cx, -1
  597.  
  598. lea si, msg
  599.  
  600. lea di, msgrev
  601.  
  602. add si, bx
  603.  
  604. add si, -1
  605.  
  606. L1:
  607.  
  608. mov al, [si]
  609.  
  610. mov [di], al
  611.  
  612. dec si
  613.  
  614. inc di
  615.  
  616. loop L1
  617.  
  618. mov al, [si]
  619.  
  620. mov [di], al
  621.  
  622. inc di
  623.  
  624. mov dl, '$'
  625.  
  626. mov [di], dl
  627.  
  628.  
  629.  
  630. Print:
  631.  
  632. mov ah, 09h
  633.  
  634. lea dx, msgrev
  635.  
  636. int 21h
  637.  
  638.  
  639.  
  640. comp:
  641.  
  642. mov bx,00h
  643.  
  644. mov bl,msg+1
  645.  
  646. mov bh,msga+1
  647.  
  648. mov SI,offset msg
  649.  
  650. mov DI,offset msga
  651. L2:
  652.  
  653. mov BL,[SI]
  654.  
  655. cmp [DI],BL
  656.  
  657. jne Lp1
  658.  
  659. inc SI
  660.  
  661. inc DI
  662.  
  663. cmp [DI],"$"
  664.  
  665. jne L2
  666.  
  667. mov ax,00h
  668.  
  669. mov 3000h,ax
  670.  
  671. jmp end
  672.  
  673.  
  674.  
  675. Lp1:
  676.  
  677. mov ax,0Fh
  678.  
  679. mov 3000h,ax
  680. end: hlt
  681.  
  682. Aim: To Count the number of vowels in a given string
  683. Code:
  684.  
  685. jmp Here
  686.  
  687. MSG db 'ChAitanya$'
  688.  
  689. Here: Mov SI,Offset MSG
  690.  
  691. Mov ch,00h
  692.  
  693. Again: Mov al,[SI]
  694.  
  695. cmp al,'$'
  696.  
  697. je stop
  698.  
  699. Casea: cmp al,'a'
  700.  
  701. jne casee
  702.  
  703. inc ch
  704.  
  705. jmp last
  706. Casee: cmp al,'e'
  707.  
  708. jne casei
  709.  
  710. inc ch
  711.  
  712. jmp last
  713.  
  714. Casei: cmp al,'i'
  715.  
  716. jne caseo
  717.  
  718. inc ch
  719.  
  720. jmp last
  721.  
  722. Caseo: cmp al,'o'
  723.  
  724. jne caseu
  725.  
  726. inc ch
  727.  
  728. jmp last
  729.  
  730. Caseu: cmp al,'u'
  731.  
  732. jne Case1
  733.  
  734. inc ch
  735.  
  736. jmp last
  737.  
  738. Case1: cmp al,'A'
  739.  
  740. jne case2
  741.  
  742. inc ch
  743.  
  744. jmp last
  745.  
  746. Case2: cmp al,'E'
  747.  
  748. jne case3
  749.  
  750. inc ch
  751.  
  752. jmp last
  753.  
  754. Case3: cmp al,'I'
  755.  
  756. jne case4
  757.  
  758. inc ch
  759.  
  760. jmp last
  761.  
  762. Case4: cmp al,'O'
  763.  
  764. jne case5
  765.  
  766. inc ch
  767. jmp last
  768.  
  769. Case5: cmp al,'U'
  770.  
  771. jne last
  772.  
  773. inc ch
  774.  
  775. jmp last
  776.  
  777. last: inc SI
  778.  
  779. jmp Again
  780.  
  781. stop: mov di,2000h
  782.  
  783. mov [di],ch
  784.  
  785. hlt
  786.  
  787. Aim: Analyse the string Instruction MOVSB, CMPS, SCAS etc
  788. Code:
  789.  
  790. jmp here
  791.  
  792. msg db 'Hello$'
  793.  
  794. msg1 db 'Bello$'
  795.  
  796. here:
  797.  
  798. mov cx,0006h
  799.  
  800. lea si,msg
  801.  
  802. mov di,0300h
  803.  
  804. rep movsb
  805.  
  806. cld
  807.  
  808. mov cx,0006h
  809.  
  810. lea di,msg
  811.  
  812. mov al,'e'
  813.  
  814. repnz scasb
  815.  
  816. mov cx,0006h
  817.  
  818. lea si,msg
  819.  
  820. lea di,msg1
  821.  
  822. repe cmpsb
  823.  
  824. hlt
  825.  
  826.  
  827. Q2. Smallest element in an array
  828.  
  829. .model small
  830. .data
  831. arr db 0Bh, 02h, 04h, 07h, 06h
  832. .code
  833. start:
  834. mov ax, @data
  835. mov ds, ax
  836. mov si, offset arr
  837. mov bl, [si]
  838. mov cl, 04h
  839. inc si
  840. loop1:
  841. cmp cl, 00h
  842. je ecmp
  843. cmp bl, [si]
  844. jg change_small
  845. inc [si]
  846. dec cl
  847. jmp loop1
  848. change_small:
  849. mov bl, [si]
  850. jmp loop1
  851. ecmp:
  852. mov ah, 4ch
  853. int 21h
  854. end start
  855. end
  856.  
  857.  
  858. Q1. Factorial
  859.  
  860. .MODEL SMALL
  861. .DATA
  862. .CODE
  863. START:
  864. MOV AX, @DATA
  865. MOV DS, AX
  866. MOV AL, 05H
  867. MOV BL, AL
  868. MOV CL, 02H
  869.  
  870. FACT:
  871. CMP CL, BL
  872. JE EF
  873. MUL CL
  874. INC CL
  875. JMP FACT
  876. EF:
  877. MOV AH, 4CH
  878. INT 21H
  879. END START
  880. END
  881.  
  882.  
  883.  
  884. Q3. Fibonacci upto n terms
  885.  
  886. .model small
  887. .data
  888. .code
  889. start:
  890. mov ax, @data
  891. mov ds, ax
  892. mov al, 00h
  893. mov bl, 01h
  894. mov cl, 05h
  895. mov si, 2000h
  896. mov [si], al
  897. inc si
  898. mov [si], bl
  899. inc si
  900. loop1:
  901. add al, bl
  902. mov ah, al
  903. mov [si], ah
  904. inc si
  905. mov al, bl
  906. mov bl, ah
  907. loop loop1
  908. mov ah, 4ch
  909. int 21h
  910. end start
  911. end
  912.  
  913.  
  914. Code:
  915. .MODEL SMALL
  916. .DATA
  917. ; No data defined
  918. .CODE
  919. start:
  920. MOV AX,@DATA MOV DS, AX MOV AL, 09h MOV BL, 04H ADD AL,BL
  921. MOV AH, 4Ch
  922. INT 21h
  923. END start
  924. End
  925. Procedure:
  926. 1. Open DOSBOX and execute the following commands -
  927. Z:\>mount c ~ /desktop
  928. Z:\>c:
  929. C:\>cd desktop
  930. C:\>cd MASM
  931. MASM:\>edit one.asm
  932. 2. Type the code and save.
  933. 3. Now execute the following commands -
  934. MASM:\>Masm one.asm
  935. Press ‘enter’ three times
  936. MASM:\>Link one.obj
  937. Press ‘enter’ three times
  938. Debug one.exe
  939. 4. Use the following commands as required -
  940. -t for line by line execution
  941. -q for quit
  942. -d ds:2000 to display memory content
  943. -e ds:2000 to enter the data in memory
  944.  
  945.  
  946. AIM: SQUARE ROOT OF A NUMBER
  947.  
  948. CODE:
  949.  
  950. mov [1000],09h
  951. mov ax,[1000]
  952. mov bx, 0ffffh
  953. mov cx,00
  954. l1:
  955. inc cx
  956. add bx,02
  957. sub ax,bx
  958. jnz l1
  959. mov [2000],cx
  960. hlt
  961.  
  962.  
  963.  
  964. Q.2) Write an ALP to convert a hexadecimal number to binary pattern and store at 2000:3000h locations.
  965.  
  966. Code:
  967.  
  968. DATA SEGMENT
  969. STR1 DB "BINARY NUMBER IS : $"
  970. STR2 DB "DECIMAL NUMBER IS : $"
  971. BSTR DB 20 DUP("$")
  972. RSTR DB 20 DUP("$")
  973. NEWLINE DB 13,10,"$"
  974. CNT DB 0
  975. N DB 2
  976. H DB 16
  977. D DB 10H
  978. NUM DB ?
  979. SNUM DB ?
  980. HNUM DB 19H
  981. DATA ENDS
  982. CODE SEGMENT
  983. ASSUME CS:CODE,DS:DATA
  984. START:
  985. MOV AX,DATA
  986. MOV DS,AX
  987. ;CONVERT HEXA TO DECIMAL
  988. MOV CX,00
  989. MOV DX,00
  990. L6:MOV AX,00
  991. MOV AL,HNUM
  992. DIV D
  993. MOV HNUM,AL
  994. MOV BX,AX
  995. MOV CL,CNT
  996. MOV AX,1
  997. L5: CMP CL,00
  998. JE L7
  999. MUL H
  1000. SUB CL,1
  1001. JMP L5
  1002. L7: MUL BH
  1003. ADD DX,AX
  1004. ADD CNT,1
  1005. CMP HNUM,0
  1006. JG L6
  1007. MOV NUM,DL
  1008. ;CONVERT DECIMAL TO BINARY
  1009. LEA SI,BSTR
  1010. LEA DI,RSTR
  1011. L1: MOV AX,00
  1012. MOV AL,NUM
  1013. DIV N
  1014. ADD AH,30H
  1015. MOV BYTE PTR[SI],AH
  1016. INC SI
  1017. MOV NUM,AL
  1018. CMP AL,0
  1019. JG L1
  1020. DEC SI
  1021. L2:MOV BL,BYTE PTR[SI]
  1022. MOV BYTE PTR[DI],BL
  1023. DEC SI
  1024. INC DI
  1025. CMP SI,0
  1026. JNE L2
  1027. MOV AH,09H
  1028. LEA DX,STR1
  1029. INT 21H
  1030. MOV AH,09H
  1031. LEA DX,RSTR
  1032. INT 21H
  1033. MOV AH,4CH
  1034. INT 21H
  1035. CODE ENDS
  1036. END START
  1037.  
  1038.  
  1039.  
  1040.  
  1041. Question: Change the sign of element
  1042.  
  1043. MOV DL, -01H; VARIABLE WHOSE SIGN IS TO BE CHANGED
  1044. MOV BL, DL ; STORING THE NUMBER
  1045. MOV AL, DL
  1046. ADD AL, DL
  1047. SUB DL, AL ; THE RESULT, THAT IS THE NUMBER WITH THE CHANGED SIGN IS STORED IN DL
  1048. HLT
  1049. Question: even odd
  1050. MOV AX, 05H
  1051. MOV BL, 02H
  1052. DIV BL
  1053. MOV DL, AH ; IF DL IS 0, THE NUMBER IS EVEN ELSE IT IS ODD
  1054.  
  1055.  
  1056. Question:
  1057. MOV DL, 15H; THE NUMBER WHOSE DIVISORS ARE TO BE FOUND
  1058. MOV SI, 500H; SETTING THE ADDRESS
  1059. MOV BL, 01H
  1060.  
  1061. NEXT:
  1062. MOV AH, 000H
  1063. MOV AL,DL
  1064. DIV BL
  1065. CMP AH, 0H
  1066. JE TRUE
  1067. JMP PART2
  1068.  
  1069. PART2:
  1070. INC BL
  1071. CMP DL, BL
  1072. JE STOP
  1073. LOOP NEXT
  1074.  
  1075. TRUE:
  1076. MOV [SI], BL
  1077. INC SI
  1078. JMP PART2
  1079.  
  1080. STOP:
  1081. MOV [SI], BL
  1082. HLT
  1083.  
  1084.  
  1085. Question: Reverse a number
  1086. MOV DL, 32H
  1087. MOV SI, 500H
  1088. MOV [SI], DL
  1089. MOV AL, DL
  1090. MOV BL, 10H
  1091. MOV BH, 10H
  1092. MOV CL, 0H;CL IS DIGIT
  1093. MOV CH, 0H;CH IS REVERSE
  1094. WLOOP:
  1095. CMP DL, 0
  1096. JLE STOP
  1097. DIV BL
  1098. MOV CL, AH
  1099. ; DIGIT=NUM%10
  1100. MOV DL, AL; NUM=NUM/10
  1101. ;REV=REV*10 + DIGIT
  1102. MOV AH, 000H
  1103. MOV DH, AL
  1104. MOV AL, CH
  1105. MUL BH
  1106. MOV CH, AL
  1107. ADD CH, CL
  1108. MOV AL, DH
  1109. JMP WLOOP; CONTINUE LOOP
  1110.  
  1111. STOP:
  1112. MOV AH, [SI]
  1113. MOV AL, CH
  1114. HLT
  1115.  
  1116.  
  1117.  
  1118. Question 1:
  1119. Find the smallest number among three numbers in registers.
  1120. Code for the execution of the program
  1121. MOV AL, 16H
  1122. MOV BL, 25H
  1123. MOV CL, 47H
  1124. MOV DL, AL
  1125. CMP DL, BL
  1126. JNLE NEXT1
  1127. JMP NEXT2
  1128. NEXT1:
  1129. MOV DL, BL
  1130. JMP NEXT2
  1131. NEXT2:
  1132. CMP DL, CL
  1133. JNLE NEXT3
  1134. HLT
  1135. NEXT3:
  1136. MOV DL, CL
  1137. HLT
  1138.  
  1139. Question 4
  1140. Identify all divisible numbers for a given number
  1141.  
  1142. Code for the execution of the program
  1143. MOV DL, 08H; THE NUMBER WHOSE DIVISORS ARE TO BE FOUND
  1144. MOV SI, 500H; SETTING THE ADDRESS
  1145. MOV BL, 01H
  1146.  
  1147. NEXT:
  1148. MOV AH, 000H
  1149. MOV AL,DL
  1150. DIV BL
  1151. CMP AH, 0H
  1152. JE TRUE
  1153. JMP PART2
  1154.  
  1155. PART2:
  1156. INC BL
  1157. CMP DL, BL
  1158. JE STOP
  1159. LOOP NEXT
  1160.  
  1161. TRUE:
  1162. MOV [SI], BL
  1163. INC SI
  1164. JMP PART2
  1165.  
  1166. STOP:
  1167. MOV [SI], BL
  1168. HLT
  1169.  
  1170.  
  1171. Question 5
  1172. Print the given number in reverse
  1173. Code for the execution of the program
  1174. MOV DL, 15H ; THE NUMBER TO BE REVERSED
  1175. MOV SI, 500H
  1176. MOV [SI], DL
  1177. MOV AL, DL
  1178. MOV BL, 10H
  1179. MOV BH, 10H
  1180. MOV CL, 0H;CL IS DIGIT
  1181. MOV CH, 0H;CH IS REVERSE
  1182. WLOOP:
  1183. CMP DL, 0
  1184. JLE STOP
  1185. DIV BL
  1186. MOV CL, AH
  1187. ; DIGIT=NUM%10
  1188. MOV DL, AL; NUM=NUM/10
  1189. ;REV=REV*10 + DIGIT
  1190. MOV AH, 000H
  1191. MOV DH, AL
  1192. MOV AL, CH
  1193. MUL BH
  1194. MOV CH, AL
  1195. ADD CH, CL
  1196. MOV AL, DH
  1197. JMP WLOOP; CONTINUE LOOP
  1198.  
  1199. STOP:
  1200. MOV AH, [SI]
  1201. MOV AL, CH
  1202. HLT
  1203.  
  1204.  
  1205.  
  1206.  
  1207. ;String, Program to input a string and print it
  1208.  
  1209.  
  1210.  
  1211. .model small
  1212. .stack 100h
  1213.  
  1214. .data
  1215. var1 db 100 dup('$')
  1216. msg1 db 'Enter the password: $'
  1217. msg2 db 'Yes$'
  1218. msg3 db 'No$'
  1219.  
  1220.  
  1221. .code
  1222. main proc
  1223. mov ax, @data
  1224. mov ds, ax
  1225. mov si, offset var1
  1226.  
  1227.  
  1228. mov dx, offset msg1
  1229. mov ah, 9
  1230. int 21h
  1231. mov cl, 0h
  1232.  
  1233.  
  1234. input:
  1235. mov ah,1
  1236. int 21h
  1237. cmp al, 13 ; 13 is ascii for return character
  1238. je check
  1239. mov [si], al
  1240. inc si
  1241. inc cl
  1242. jmp input
  1243.  
  1244. check:
  1245. cmp cl, 6h
  1246. je check2
  1247. jmp false
  1248.  
  1249. check2:
  1250. mov si, offset var1
  1251. mov ah, [si]
  1252. cmp ah,30h ;hex for 0 is 30 and goes on to 39
  1253. jge true0
  1254. jmp false
  1255. true0:
  1256. cmp ah, 39h; hex for 9 is 39
  1257. jle check30 ; checked for first number
  1258. jmp false
  1259.  
  1260. check 30:
  1261. mov ch, 0h; for numbers
  1262. mov cl, 0h; for alphabets
  1263. mov si, offset var1
  1264. check3: ;checking for 4 alphabets and two numbers
  1265. mov ah, [si]
  1266. cmp ah, 30h
  1267. jge number00
  1268. jmp alphabet
  1269. number00:
  1270. cmp ah, 39h
  1271. jle alphabet
  1272. jmp number
  1273.  
  1274. alphabet:
  1275. inc si
  1276. inc cl
  1277. mov ah, [si]
  1278. cmp ah, '$'
  1279. jmp pass0
  1280. jmp check3
  1281.  
  1282. number:
  1283. inc si
  1284. inc ch
  1285. mov ah, [si]
  1286. cmp ah, '$'
  1287. jmp pass0
  1288. jmp check3
  1289.  
  1290. ;Checking count of alphabets and numbers
  1291. pass0:
  1292. cmp cl, 04h
  1293. je pass1
  1294. jmp false
  1295. pass1:
  1296. cmp ch, 02h
  1297. je true
  1298. jmp false
  1299.  
  1300. ;Now printing moment of truth
  1301.  
  1302. true:
  1303. ; new line feed
  1304. mov dx, 10
  1305. mov ah, 2
  1306. int 21h
  1307. ;carriage return
  1308. mov dx, 13
  1309. mov ah, 2
  1310. int 21h
  1311.  
  1312.  
  1313. mov dx, offset msg2
  1314. mov ah, 9
  1315. int 21h
  1316. jmp programend
  1317.  
  1318. false:
  1319. mov dx, 10
  1320. mov ah, 2
  1321. int 21h
  1322. ;carriage return
  1323. mov dx, 13
  1324. mov ah, 2
  1325. int 21h
  1326.  
  1327.  
  1328. mov dx, offset msg3
  1329. mov ah, 9
  1330. int 21h
  1331. jmp programend
  1332.  
  1333.  
  1334.  
  1335. programend:
  1336. mov ah, 4ch
  1337. int 21h
  1338. main endp
  1339. end main
  1340.  
  1341. Pallindrome
  1342. .MODEL SMALL ;Palindrama
  1343. .STACK 100
  1344. .DATA
  1345. STR1 DB 'hannah$'
  1346. .CODE
  1347. MOV AX, @DATA
  1348. MOV DS, AX
  1349. MOV SI, OFFSET STR1
  1350. MOV DI, OFFSET STR1
  1351. MOV BL, '$'
  1352. PHASE1:; THIS PHASE WILL INCREMENT DI TO THE LAST POSITION OF THE STRING
  1353. MOV AL, [DI]
  1354. CMP AL, BL
  1355. JE FLAG1
  1356. INC DI
  1357. JMP PHASE1
  1358. FLAG1:
  1359. DEC DI
  1360. PHASE2:; THIS PHASE WILL COMPARE THE VALUES OF ADDRESSES OF DI WITH SI
  1361. CMP SI, DI
  1362. JE PASS_CASE
  1363. CMP SI, DI
  1364. JGE PASS_CASE
  1365. MOV AL, [SI]
  1366. MOV BL, [DI]
  1367. CMP AL, BL
  1368. JNE FAIL_CASE
  1369. INC SI
  1370. DEC DI
  1371. JMP PHASE2
  1372. FAIL_CASE:; THE STRING IS NOT PALINDROME
  1373. MOV DH, 5
  1374. JMP STOP
  1375. PASS_CASE:
  1376. MOV DH, 10
  1377. JMP STOP
  1378. STOP:
  1379. MOV AH, 4CH
  1380. INT 21H
  1381. END
  1382.  
  1383.  
  1384.  
  1385. 16 bit :
  1386. ADDITION
  1387. DATA SEGMENT
  1388. DATA ENDS
  1389. CODE SEGMENT
  1390. ASSUME CS : CODE, DS : DATA
  1391. MOV AX, DATA
  1392. MOV DS, AX
  1393. MOV AX, 4261H
  1394. ADD AX, 1234H
  1395. HLT
  1396. CODE ENDS
  1397. END
  1398. SUBSTRACTION
  1399. DATA SEGMENT
  1400. DATA ENDS
  1401. CODE SEGMENT
  1402. ASSUME CS : CODE, DS : DATA
  1403. MOV AX, DATA
  1404. MOV DS, AX
  1405. MOV AX, 4261H
  1406. SUB AX, 1234H
  1407. HLT
  1408. CODE ENDS
  1409. END
  1410. MULTIPLICATION
  1411. DATA SEGMENT
  1412. A DW 0105H
  1413. B DW 0210H
  1414. C DW ?
  1415. DATA ENDS
  1416. CODE SEGMENT
  1417. ASSUME CS:CODE, DS:DATA
  1418. START:
  1419. MOV AX,DATA
  1420. MOV DS,AX
  1421. MOV AX,0000H
  1422. MOV BX,0000H
  1423. MOV AX,A
  1424. MOV BX,B
  1425. IMUL B
  1426. MOV C,AX
  1427. INT 3
  1428. CODE ENDS
  1429. END START
  1430. DIVISION
  1431. DATA SEGMENT
  1432. A DW 8844H
  1433. B DW 0004H
  1434. C DW ?
  1435. DATA ENDS
  1436. CODE SEGMENT
  1437. ASSUME DS:DATA, CS:CODE
  1438. START:
  1439. MOV AX,DATA
  1440. MOV DS,AX
  1441. MOV AX,A
  1442. MOV BX,B
  1443. DIV BX
  1444. MOV C,BX
  1445. INT 3
  1446. CODE ENDS
  1447. END START
  1448.  
  1449. Largest:
  1450.  
  1451. data segment
  1452. STRING1 DB 08h,13h,18h,0Fh,09h
  1453. res db ?
  1454. data ends
  1455. code segment
  1456. assume cs:code, ds:data
  1457. start: mov ax, data
  1458. mov ds, ax
  1459. mov cx, 04h
  1460. mov bl, 00h
  1461. LEA SI, STRING1
  1462. up:
  1463. mov al, [SI]
  1464. cmp al, bl
  1465. jl nxt
  1466. mov bl, al
  1467. nxt:
  1468. inc si
  1469. dec cx
  1470. jnz up
  1471. mov res,bl
  1472. code ends
  1473. end start
  1474. Ascending order:
  1475.  
  1476. CODE SEGMENT
  1477. ASSUME CS:CODE
  1478. ORG 1000H
  1479. START:MOV SI,1100H
  1480. MOV CL,[SI]
  1481. DEC CL
  1482. REPEAT: MOV SI,1100H
  1483. MOV CH,[SI]
  1484. DEC DL
  1485. REPCOM: MOV AL,[SI]
  1486. INC SI
  1487. CMP AL,[SI]
  1488. JC AHEAD
  1489. XCHG AL,[SI]
  1490. XCHG AL,[SI-1]
  1491. AHEAD: DEC CH
  1492. JNZ REPCOM
  1493. DEC CL
  1494. JNZ REPEAT
  1495. HLT
  1496. Search element in an array:
  1497. jmp here
  1498. arr db 02h,04h,07h,09h,01h
  1499. here:mov cx,05h
  1500. mov dl,00h
  1501. mov si, offset arr
  1502. again:mov al,[si]
  1503. cmp al,04h
  1504. jne next
  1505. inc dl
  1506. next:inc si
  1507. loop again
  1508. hlt
  1509.  
  1510. Factorial of Hexa Decimal Number
  1511. MOV CX,06h
  1512. MOV AX,01h
  1513. abc: mul CX
  1514. dec CX
  1515. jnz abc
  1516. hlt
  1517.  
  1518. QUESTION: Write an ALP to count no.of positive and negative numbers.
  1519. SOLUTION:
  1520. Code:
  1521. data segment
  1522. num db 9,8,7,6,-3,-5,-6,-7
  1523. len dw $-num
  1524. p_cnt db 0h
  1525. n_cnt db 0h
  1526. data ends
  1527. code segment
  1528. assume cs:code ds:data
  1529. start:
  1530. mov ax,data
  1531. mov ds,ax
  1532. mov cx,len
  1533. lea si,num
  1534. looper:
  1535. mov al,[si]
  1536. cmp al,0
  1537. jg pos
  1538. jl nega
  1539. pos:
  1540. inc bh
  1541. jmp rest
  1542. nega:
  1543. inc dh
  1544. jmp rest
  1545. rest:
  1546. inc si
  1547. dec cx
  1548. cmp cx,0
  1549. jg looper
  1550. mov p_cnt,bh
  1551. mov n_cnt,dh
  1552. mov ah,4ch
  1553. int 21h
  1554. code ends
  1555. end start
  1556.  
  1557. UESTION: Write an ALP for traffic light system and stepper motor.
  1558. SOLUTION:
  1559. TRAFFIC LIGHT:
  1560. CODE:
  1561. #start=Traffic_lights.exe#
  1562. name "traffic"
  1563. mov ax,all_red
  1564. out 4, ax
  1565. mov si,offset situation
  1566. next:
  1567. mov ax,[si]
  1568. out 4 ,ax
  1569. mov cx,4Ch
  1570. mov dx, 4840h
  1571. mov ah, 86h
  1572. int 15h
  1573. add si,2
  1574. cmp si, sit_end
  1575. jb next
  1576. mov si, offset situation
  1577. jmp next
  1578. situation dw 0000-0011_0000_1100b
  1579. s1 dw 0000_0110_1001_1010b
  1580. s2 dw 0000_1000_0110_0001b
  1581. s3 dw 0000_1000_0110_0001b
  1582. s4 dw 0000_0100_1101_0011b
  1583. sit_end=$
  1584. all_red equ 0000_0010_0100_1001b
  1585.  
  1586. STEPPER MOTOR:
  1587. CODE:
  1588. #start=stepper_motor.exe#
  1589. name "stepper"
  1590. #make_bin#
  1591. steps_before_direction_change=20h
  1592. jmp start
  1593. datcw db 0000_0110b
  1594. db 0000_0100b
  1595. db 0000_0011b
  1596. db 0000_0010b
  1597. datccw db 0000_0011b
  1598. db 0000_0001b
  1599. db 0000_0110b
  1600. db 0000_0010b
  1601. datcw_fs db 0000_0001b
  1602. db 0000_0011b
  1603. db 0000_0110b
  1604. db 0000_0000b
  1605. datccw_fs db 0000_0100b
  1606. db 0000_0110b
  1607. db 0000_0011b
  1608. db 0000_0000b
  1609. start:
  1610. mov bx, offset datcw
  1611. mov si,0
  1612. mov cx,0
  1613. next_step:
  1614. wait:in al,7
  1615. test al, 10000000b
  1616. jz wait
  1617. mov al, [bx][si]
  1618. out 7,al
  1619. inc si
  1620. cmp si,4
  1621. jb next_step
  1622. mov si,0
  1623. inc cx
  1624. cmp cx, steps_before_direction_change
  1625. jb next_step
  1626. mov cx,0
  1627. add bx, 4
  1628. cmp bx, offset datccw_fs
  1629. jbe next_step
  1630. mov bx, offset datcw
  1631. jmp next_step
  1632.  
  1633. Smallest:
  1634. data segment
  1635. STRING1 DB 08h,14h,02h,0Fh,04h
  1636. res db ?
  1637. data ends
  1638. code segment
  1639. assume cs:code, ds:data
  1640. start: mov ax, data
  1641. mov ds, ax
  1642. mov cx, 04h
  1643. mov bl, 79h
  1644. LEA SI, STRING1
  1645. up:
  1646. mov al, [SI]
  1647. cmp al, bl
  1648. jge nxt
  1649. mov bl, al
  1650. nxt:
  1651. inc si
  1652. dec cx
  1653. jnz up
  1654. mov res,bl
  1655. int 3
  1656. code ends
  1657. end start
  1658.  
  1659.  
  1660.  
  1661. File handling:
  1662. .stack 100h
  1663. .data
  1664. text db "Hello World$"
  1665. filename db "file.txt",0
  1666. handler dw ?
  1667. .code
  1668. mov ax,@data
  1669. mov ds,ax
  1670. mov ah,3ch
  1671. mov cx,0
  1672. mov dx,offset filename
  1673. int 21h
  1674. mov handler,ax
  1675. mov ah,40h
  1676. mov bx,handler
  1677. mov cx,15
  1678. mov dx, offset text
  1679. int 21h
  1680. mov ah,3eh
  1681. mov bx,handler
  1682. int 21h
  1683. mov ax,4c00h
  1684. int 21h
  1685.  
  1686. delete file:
  1687. .MODEL SMALL
  1688. .DATA
  1689. FILE DB 'C:\emu8086\MyBuild\file.txt',0
  1690. MSG DB 'File Deleted','$'
  1691. .CODE
  1692. START: MOV AX,@DATA
  1693. MOV DS,AX
  1694. LEA DX,FILE
  1695. MOV AH,41H
  1696. INT 21H
  1697. JC EXIT
  1698. LEA DX,MSG
  1699. MOV AH,09H
  1700. INT 21H
  1701. EXIT:MOV AH,4CH
  1702. INT 21H
  1703. END START
  1704.  
  1705. LAB ASSIGNMENT – 6
  1706. Name- Akash Goyal
  1707. Reg. no- 16BCE0592
  1708. Course Code – CSE2006
  1709. Course Title – Microprocessor and Interfacing
  1710. Slot- L21-22
  1711. Q.1 Write the ALP codes for String Manipulation?
  1712. (A) Reading a string from the user:-
  1713. Code:-
  1714. .model small
  1715. .stack 64
  1716. .data
  1717. a db ?
  1718. a1 db ?
  1719. .code
  1720. start:mov ax,@data
  1721. mov ds,ax
  1722. mov al,offset a1
  1723. mov ah,01h
  1724. int 21h
  1725. mov cl,al
  1726. again:mov si,offset a
  1727. mov ah,01h
  1728. int 21h
  1729. dec cl
  1730. jnz again
  1731. Screen Shot of the code:-
  1732. Screen Shot of the output
  1733. (b) Palindrome for numeric string:-
  1734. Code:-
  1735. .model small
  1736. .stack 64
  1737. .data
  1738. m1 db ?
  1739. m2 db 'Pallindrome$'
  1740. m3 db 'Not pallindrome$'
  1741. .code
  1742. .start:mov ax,@data
  1743. mov ds,ax
  1744. mov cl,04h
  1745. mov di,4000h
  1746. again: mov si,offset m1
  1747. mov ah,01h
  1748. int 21h
  1749. inc si
  1750. dec cl
  1751. jnz again
  1752. mov ax,[si]
  1753. mov bl,10
  1754. mov cl,04h
  1755. again1:div bl
  1756. mov di,dx
  1757. mov bl,al
  1758. inc di
  1759. dec cl
  1760. jnz again1
  1761. mov al,[si]
  1762. mov bl,[di]
  1763. cmp bl,al
  1764. je one
  1765. mov dx,offset m3
  1766. mov ah,09h
  1767. int 21h
  1768. one:mov dx,offset m2
  1769. mov ah,09h
  1770. int 21h
  1771. stop:nop
  1772. Screen Shot of the Output:-
  1773. (C) Palindrome for Word string:-
  1774. Code:-
  1775. data segment
  1776. str1 db 'MADAM','$'
  1777. strlen1 dw $-str1
  1778. strrev db 20 dup(' ')
  1779. str_pallin db 'String is pallindrome','$'
  1780. str_not_pallin db 'String not pallindrome','$'
  1781. data ends
  1782. Code segment
  1783. Assume cs:code,ds:data
  1784.  
  1785. Begin:
  1786. mov ax,data
  1787. mov cl,05h
  1788. mov ds,ax
  1789. mov es,ax
  1790. mov cx,strlen1
  1791. mov cx,-2
  1792.  
  1793. lea si,str1
  1794. lea di,strrev
  1795.  
  1796. add si,strlen1
  1797. add si,-2
  1798. L1:mov al,[si]
  1799. mov [di],al
  1800. dec si
  1801. inc di
  1802. dec cl
  1803.  
  1804. mov al,[si]
  1805. mov [di],al
  1806. inc di
  1807. mov dl,'$'
  1808. mov [di],dl
  1809. mov cx,strlen1
  1810. Pallin_check:
  1811. lea si,str1
  1812. lea di,strrev
  1813. repe cmpsb
  1814. jne Not_pallin
  1815.  
  1816. Pallin:
  1817. mov ah,09h
  1818. lea dx,str_not_pallin
  1819. int 21h
  1820. jmp Exit
  1821.  
  1822. Not_pallin:
  1823. mov ah,09h
  1824. lea dx,str_pallin
  1825. int 21h
  1826.  
  1827. Exit:
  1828. mov ax,4c00h
  1829. int 21h
  1830. Code Ends
  1831. End Begin
  1832. Screen Shot of the output:-
  1833. (D) To find the number of vowels present in the string:-
  1834. Code:-
  1835. var db 'abacus$'
  1836. mov bx, 00h
  1837. casea:
  1838. cmp var[bx],'a'
  1839. jne casee
  1840. mov al,[0200h]
  1841. inc al
  1842. mov [0200h],al
  1843. casee:
  1844. cmp var[bx],'e'
  1845. jne casei
  1846. mov al,[0201h]
  1847. inc al
  1848. mov [0201h],al
  1849. casei:
  1850. cmp var[bx],'i'
  1851. jne caseo
  1852. mov al,[0202h]
  1853. inc al
  1854. mov [0202h],al
  1855. caseo:
  1856. cmp var[bx],'o'
  1857. jne caseu
  1858. mov al,[0203h]
  1859. inc al
  1860. mov [0203h],al
  1861. caseu:
  1862. cmp var[bx],'u'
  1863. jne check
  1864. mov al,[0204h]
  1865. inc al
  1866. mov [0204h],al
  1867. check:
  1868. inc bx
  1869. cmp var[bx],'$'
  1870. jne casea
  1871. hlt
  1872. Screen Shot of the output:-
  1873. Q.2 Write the ALP code for LED 7 segment register ?
  1874. (A) Without delay:-
  1875. Code :-
  1876. #start=led_display.exe#
  1877. mov ax,01h
  1878. again:out 199,ax
  1879. inc ax
  1880. jmp again
  1881. mov ah,4ch
  1882. Screen Shot of the code:-
  1883. Screen Shot of the output:-
  1884. (B). With delay:-
  1885. Code:-
  1886. #start=led_display.exe#
  1887. mov ax,01h
  1888. again: out 199,ax
  1889. inc ax
  1890. mov cl,05h
  1891. delay:dec cl
  1892. jnz delay
  1893. jmp again
  1894. mov ah,4ch
  1895. int 21h
  1896. Screen Shot of the code:-
  1897. Screen Shot of the output:-
  1898.  
  1899. (b) ALP for Block transfer of data :-
  1900. Code:-
  1901. .model small
  1902. .stack 64
  1903. .data
  1904. .code
  1905. start:mov ax,@data
  1906. mov si,2000h
  1907. mov [si],12h
  1908. inc si
  1909. mov [si],34h
  1910. inc si
  1911. mov [si],56h
  1912. inc si
  1913. mov [si],74h
  1914. inc si
  1915. mov [si],94h
  1916.  
  1917. mov di,3000h
  1918. mov si,2000h
  1919. mov cl,05h
  1920.  
  1921. again:
  1922. mov bl,[si]
  1923. mov [di],bl
  1924. inc si
  1925. inc di
  1926. dec cl
  1927. jnz again
  1928. int 21h
  1929. end start
  1930. end
  1931. Fibonacci code:
  1932. Code:¬
  1933. jmp here
  1934. x db 00H
  1935. Y db 01H
  1936. n db 05H
  1937. here: mov al,x
  1938. mov cl,n
  1939. mov bl,y
  1940. mov si,2000h
  1941. again: inc si
  1942. add al,bl
  1943. xchg al,bl
  1944. loop again
  1945. mov [si],bl
  1946. hlt
  1947.  
  1948. 2. ALP for NCR and NPR (Note: nCr = n! /r! (n-r)! and
  1949. NPR =
  1950. n!/(n-r)!
  1951. Code:-
  1952. a) NCR
  1953. .model small
  1954. .stack 64
  1955. .data
  1956. .code
  1957. mov al,05h
  1958. mov dl,03h
  1959. mov cl,al
  1960. sub cl,dl
  1961. mov bl,al
  1962. sub bl,01h
  1963. again: mul bl
  1964. dec bl
  1965. Jnz again
  1966.  
  1967. mov bl,dl
  1968. mov dl,al
  1969. mov al,bl
  1970. sub bl,01h
  1971. fac: mul bl
  1972. dec bl
  1973. Jnz fac
  1974. mov bl,cl
  1975. mov cl,al
  1976. mov al,bl
  1977. sub bl,01h
  1978. fact: mul bl
  1979. dec bl
  1980. Jnz fact
  1981. mov bl,cl
  1982. mul bl
  1983. mov bl,al
  1984. mov al,dl
  1985. div bl
  1986. b) NPR
  1987. CODE:
  1988. .model small
  1989. .stack 64
  1990. .data
  1991. .code
  1992. mov al,05h
  1993. mov bl,al
  1994. sub bl,01h
  1995. mov dl,03h
  1996. mov cl,dl
  1997. mov dl,al
  1998. sub dl,cl
  1999. again: mul bl
  2000. dec bl
  2001. Jnz again
  2002. mov bl,dl
  2003. mov dl,al
  2004. mov al,bl
  2005. sub bl,01h
  2006. fac:mul bl
  2007. dec bl
  2008. Jnz
  2009. fac mov bl,al
  2010. mov al,dl
  2011. div bl
  2012. CSE2006 - LAB EXPERIMENT-1
  2013. Simardeep Singh
  2014. 16BCE0198
  2015. Q) Write an ALP using 8086 instructions to generate and add the first 10 even numbers and
  2016. save the numbers and result in memory location Num and Sum.
  2017. CODE:
  2018. MOV CL,10
  2019. MOV AX,0
  2020. MOV BX,0
  2021. BACK:
  2022. ADD BX,2
  2023. ADD AX, BX
  2024. DEC CL
  2025. JNZ BACK
  2026. HLT
  2027. CSE-2006: EXPERIMENT – 2
  2028. Name: Simardeep Singh
  2029. Registration Number: 16BCE0198
  2030. Q). Write an 8086 alp to search for a given 16-bit value using binary search in an array of 16 bit
  2031. numbers, which are in sorted. Display the status in any one of the registers (found or not) .If the
  2032. element is found the position of the element in the array is to be displayed.
  2033. Answer:
  2034. Source code:
  2035. DATA SEGMENT
  2036. ARR DW 0000H,1111H,2222H,3333H,4444H,5555H,6666H,7777H,8888H,9999H
  2037. LEN DW ($-ARR)/2
  2038. KEY EQU 7777H
  2039. MSG1 DB "KEY IS FOUND AT "
  2040. RES DB " POSITION",13,10,"$"
  2041. MSG2 DB "KEY NOT FOUND !!! .$"
  2042. DATA ENDS
  2043. CODE SEGMENT
  2044. ASSUME DS:DATA CS:CODE
  2045. START:
  2046. MOV AX,DATA
  2047. MOV DS,AX
  2048. MOV BX,00
  2049. MOV DX,LEN
  2050. MOV CX,KEY
  2051. AGAIN:CMP BX,DX
  2052. JA FAIL
  2053. MOV AX,BX
  2054. ADD AX,DX
  2055. SHR AX,1
  2056. MOV SI,AX
  2057. ADD SI,SI
  2058. CMP CX,ARR[SI]
  2059. JAE BIG
  2060. DEC AX
  2061. MOV DX,AX
  2062. JMP AGAIN
  2063. BIG: JE SUCCESS
  2064. INC AX
  2065. MOV BX,AX
  2066. JMP AGAIN
  2067. SUCCESS:ADD AL,01
  2068. ADD AL,'0'
  2069. MOV RES,AL
  2070. LEA DX,MSG1
  2071. JMP DISP
  2072. FAIL: LEA DX,MSG2
  2073. DISP: MOV AH,09H
  2074. INT 21H
  2075. MOV AH,4CH
  2076. INT 21H
  2077. CODE ENDS
  2078. END START
  2079. Output:
  2080.  
  2081. CSE -2006 LAB ASSESMENT-3
  2082. Simardeep Singh
  2083. 16BCE0198
  2084. Q) Write an ALP to sort in ascending order using bubble sort algorithm that lets the user type
  2085. a given set of byte sized unsigned numbers in memory. The sorted elements should replace
  2086. the original unsorted elements in memory
  2087. ALP CODE:
  2088. org 100h
  2089. .data
  2090. str db 10,13,"Enter Values: $"
  2091. str1 db 0dh,0ah,"Bubble Sorted: $"
  2092. array db 10dup(0)
  2093. .code
  2094. mov ah,9
  2095. lea dx,str
  2096. int 21h
  2097. mov cx,10
  2098. mov bx,offset array
  2099. mov ah,1
  2100. inputs:
  2101. int 21h
  2102. mov [bx],al
  2103. inc bx
  2104. Loop inputs
  2105. mov cx,10
  2106. dec cx
  2107. nextscan:
  2108. mov bx,cx
  2109. mov si,0
  2110. nextcomp:
  2111. mov al,array[si]
  2112. mov dl,array[si+1]
  2113. cmp al,dl
  2114. jc noswap
  2115. mov array[si],dl
  2116. mov array[si+1],al
  2117. noswap:
  2118. inc si
  2119. dec bx
  2120. jnz nextcomp
  2121. loop nextscan
  2122. mov ah,9
  2123. lea dx,str1
  2124. int 21h
  2125. mov cx,10
  2126. mov bx,offset array
  2127. print:
  2128. mov ah,2
  2129. mov dl,[bx]
  2130. int 21h
  2131. inc bx
  2132. loop print
  2133. ret
  2134. SCREENSHOT:
  2135. OUTPUT:
  2136.  
  2137. LAB ASSESSMENT-04
  2138. NAME: Simardeep Singh
  2139. REG NO: 16BCE0198
  2140. Q-1) Highlights the services provided by various BIOS and DOS Interrupts.
  2141. DOS and BIOS interrupts are used to perform some very useful functions, such as displaying
  2142. data to the monitor, reading data from keyboard, etc. „ They are used by identifying the
  2143. interrupt option type, which is the value stored in register AH and providing, whatever extra
  2144. information that the specific option requires.
  2145. BIOS Interrupt 10H
  2146. Option 0H – Sets video mode.
  2147. Registers used: AH = 0H, AL = Video Mode.
  2148. 3H - CGA Color text of 80X25
  2149. 7H - Monochrome text of 80X25
  2150. Ex: MOV AH,0 MOV AL,7 INT 10H
  2151. Option 2H – Sets the cursor to a specific location.
  2152. Registers used: AH = 2H, BH = 0H selects Page 0.
  2153. DH = Row position. DL = Column position.
  2154. Ex: MOV AH,2
  2155. MOV BH,0
  2156. MOV DH,12
  2157. MOV DL,39
  2158. INT 10H
  2159. Option 6H – Scroll window up. This interrupt is also used to clear the screen when you set AL = 0.
  2160. Registers used:
  2161. AH = 6H
  2162. AL = number of lines to scroll.
  2163. BH = display attribute.
  2164. CH = y coordinate of top left.
  2165. CL = x coordinate of top left.
  2166. DH = y coordinate of lower right.
  2167. DL = x coordinate of lower right
  2168. CLEAR SCREEN EXAMPLES
  2169. MOV AH,6
  2170. MOV AL,0
  2171. MOV BH,7
  2172. MOV CH,0
  2173. MOV CL,0
  2174. MOV DH,24
  2175. MOV DL,79
  2176. INT 10H
  2177. The code above may be shortened by using AX, BX and DX registers to move word size data
  2178. instead of byte size data.
  2179. Option 7H – Scroll window down. This interrupt is also used to clear the screen when you
  2180. set AL = 0. Registers used:
  2181. AH = 7H
  2182. AL = number of lines to scroll.
  2183. BH = display attribute.
  2184. CH = y coordinate of top left.
  2185. CL = x coordinate of top left.
  2186. DH = y coordinate of lower right.
  2187. DL = x coordinate of lower right.
  2188. Option 8H – Read a character and its attribute at the cursor position.
  2189. Registers used:
  2190. AH = 8H and returned attribute value.
  2191. AL = Returned ASCII value.
  2192. BH = display page.
  2193. Option 9H – Write a character and its attribute at the cursor position. „
  2194. Registers used:
  2195. AH = 9H.
  2196. AL = ASCII value.
  2197. BH = display page.
  2198. BL = attribute.
  2199. CX = number of characters to write.
  2200. Attribute Definition
  2201. Monochrome display attributes
  2202. Blinking „ D7 = 0 - Non-blinking
  2203. D7 = 1 - Blinking Intensity
  2204. D3=0 - Normal intensity
  2205. D3=1 - Highlighted intensity
  2206. Background and foreground
  2207. D6 D5 D4 and D2 D1 D0
  2208. White = 0 0 0
  2209. Black = 1 1 1
  2210. DOS Interrupt 21H
  2211. Option 1 – Inputs a single character from keyboard and echoes it to the monitor.
  2212. Registers used:
  2213. AH = 1
  2214. AL = the character inputted from keyboard.
  2215. Ex: MOV AH,1
  2216. INT 21H
  2217. Option 2 – Outputs a single character to the monitor.
  2218. Registers used:
  2219. AH = 2
  2220. DL = the character to be displayed.
  2221. Ex:
  2222. MOV AH,2
  2223. MOV DL,’A’
  2224. INT 21H
  2225. Option 9 – Outputs a string of data, terminated by a $ to the monitor.
  2226. Registers used:
  2227. AH = 9
  2228. DX = the offset address of the data to be displayed.
  2229. Ex:
  2230. MOV AH, 09
  2231. MOV DX, OFFSET MESS1
  2232. INT 21H
  2233. Option 0AH – Inputs a string of data from the keyboard.
  2234. Registers used:
  2235. AH = 9
  2236. DX = the offset address of the location where string will be stored.
  2237. DOS requires that a buffer be defined in the data segment. It should be defined as follows:
  2238. 1st byte contains the size of the buffer.
  2239. 2nd byte is used by DOS to store the number of bytes stored.
  2240. Ex: DATA
  2241. BUFFER1 DB 15,
  2242. 15 DUP (FF)
  2243. MOV AH,0AH
  2244. MOV DX, OFFSET BUFFER1
  2245. INT 21H
  2246. Assume “Go Tigers!” was entered on the keyboard.
  2247. BUFFER1 = 10,10,’Go
  2248. Option 4CH – Terminates a process, by returning control to a parent process or to DOS. „
  2249. Registers used:
  2250. AH = 4CH
  2251. AL = binary return code.
  2252. Ex:
  2253. MOV AH, 4CH
  2254. INT 21H
  2255. Option 4CH – Terminates a process, by returning control to a parent process or to DOS.
  2256. Registers used:
  2257. AH = 4CH
  2258. AL = binary return code.
  2259. Ex:
  2260. MOV AH,4CH
  2261. INT 21H
  2262. Q-2) Convert the following decimal number 178.625 into short real format.
  2263. (178.625)10
  2264. (10110010.101)2
  2265. 1.0110010101 * 107 normalisation
  2266. 111+01111111= 10000110
  2267. Result
  2268. Sign= 0
  2269. Exponent= 10000110
  2270. Significand= 01100101010000000000000
  2271. Short real format=01000011001100101010000000000000 = 4332A000h
  2272. CSE2006: Microprocessors and Interfacing
  2273. Assignment: 6
  2274. Name: Resham
  2275. Reg Number: 16BCE0971
  2276. 1. Write an 8086 ALP which will input the organisation name from the keyboard. If the name is
  2277. 'VIT' it will output “Permission granted” else it will display the message “Wrong details” using
  2278. DOS interrupt.
  2279. Code:
  2280. DATA SEGMENT
  2281. MSG1 DB 10,13,'ENTER ORGANIZATION NAME : $'
  2282. MSG2 DB 10,13,'WRONG DETAILS $'
  2283. MSG3 DB 10,13,'PERMISSION GRANTED $'
  2284. MSG4 DB 10,13,'LENGTH NOT EQUAL $'
  2285. STR1 DB "VIT"
  2286. P1 LABEL BYTE
  2287. M1 DB 0FFH
  2288. L1 DB ?
  2289. P11 DB 0FFH DUP ('$')
  2290. DATA ENDS
  2291. DISPLAY MACRO MSG
  2292. MOV AH,9
  2293. LEA DX,MSG
  2294. INT 21H
  2295. ENDM
  2296. CODE SEGMENT
  2297. ASSUME CS:CODE,DS:DATA
  2298. START:
  2299. MOV AX,DATA
  2300. MOV DS,AX
  2301. DISPLAY MSG1
  2302. LEA DX,P1
  2303. MOV AH,0AH
  2304. INT 21H
  2305. CMP L1,3
  2306. JNE NOTEQUAL
  2307. LEA SI,STR1
  2308. LEA DI,P11
  2309. MOV CX,3
  2310. CHECK:
  2311. MOV AL,[SI]
  2312. CMP [DI],AL
  2313. JNE NOPASWD
  2314. INC SI
  2315. INC DI
  2316. LOOP CHECK
  2317. DISPLAY MSG3
  2318. JMP EXIT
  2319. NOTEQUAL:
  2320. DISPLAY MSG4
  2321. NOPASWD:
  2322. DISPLAY MSG2
  2323. JMP EXIT
  2324. EXIT: MOV AH,4CH
  2325. INT 21H
  2326. CODE ENDS
  2327. END START
  2328. Output:
  2329.  
  2330. 2. Write an ALP to convert the given hexadecimal number to binary and perform the 2's
  2331. complement of the resultant.
  2332. a) 8BE2H
  2333. Code:
  2334. .model small
  2335. .data
  2336. a dw 8BE2H
  2337. .code
  2338. mov ax, @data ; Initialize data section
  2339. mov ds, ax
  2340. mov ax, a ; Load number1 in ax
  2341. Flowchart 2
  2342. neg ax ; find 2's compement. Result
  2343. in ax
  2344. mov ch, 04h ; Count of digits to be displayed
  2345. mov cl, 04h ; Count to roll by 4 bits
  2346. mov bx, ax ; Result in reg bx
  2347. l2: rol bx, cl ; roll bl so that msb comes
  2348. to lsb
  2349. mov dl, bl ; load dl with data to be
  2350. displayed
  2351. and dl, 0fH ; get only lsb
  2352. cmp dl, 09 ; check if digit is 0-9 or
  2353. letter A-F
  2354. jbe l4
  2355. add dl, 07 ; if letter add 37H else only
  2356. add 30H
  2357. l4: add dl, 30H
  2358. mov ah, 02 ; Function 2 under INT 21H
  2359. (Display character)
  2360. int 21H
  2361. dec ch ; Decrement Count
  2362. jnz l2
  2363. mov ah, 4cH ; Terminate Program
  2364. int 21H
  2365. end
  2366. Output:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement