Lab Manual
Lab Manual
mov ah, vi db 10,13,"You Typed 24" s code Main Proc , mov ax Oat ne este Mov S$) aX XOR bx bx DESPeNE mov ah, ] a ah ‘ oad int oth CMP ol 13 Loep Pring JE ENDL Exit« SHL box, | mov ahi Ych SLB al Ug int ath - Pp hal “ mal? T End Malin END—: mov cx ,}b mov ah/4 mov dx, offset vi int ay h Prints229- 42 Write anassembly language code that will take Hexa input from user and will also display it @ macel small Tnsext ¢ | stack 100 of bhial i sdata vi db 10,13,"You Ty PED. g code mov a4 et v4 ™ | Main auc tak anche . mov ax, @data mov cx, Y Mov ds 7 OR Moy ah, 2d YOR bx bx Print s bom ov chy Mov db b mov ah | SHR cll, | ae ant SHR ht | Inpubs HR AQ | | int Qh R QQ CMP al 13 CMP at, JE UEND_ SLE Dispthumber SHL bx, ef ladd Ass cM f TMP dis P al, ce is PNumber's [ino h SLE Number dal AQ Ug ~ vv ahitch Sob al £€ disp + int all IMP Insect ape th [thn aap N Pe Baty Ach j Bey " Rol bx \ ah \ aoe aL, 48 Rol bx, { i| ‘Omments/Signature (Student & Teacher’ :RoL bali Loeb Print «LAB #9 Theory: Stack A stack is one-dimensional data structure, Items are added and removed from one sinucture; that 1s, it is processed in a "last-in, first-out” manner. The most recent adi siack is called the top of the stack. A familiar example is a stack of dishes; the last cg 1 the stack is the top one, and it's the only one that can be removed easily. {A program must set aside a block of memory to hold the stack. We have been doing 4 declaring a stack segment: For example: -STACK 100H Task 9.1: Programming Practice Q.1_ Write an assembly language code that will input a string from user and will display itig reverse order on next line, Sample Execution: nhGreDeBa mev dl, 13 smodel gmall aa _ *staclke lool wi * data ue = Gole Pop dx Main P dd Gules din Proc Te ai mov ch) Loop Lo Lhe mov ah Uch mov ah)) int alh int ath Main End p alate ne End Mai posh ax —) Loop U4 mov ah,2 mov df,\o 2 Pay, signature (Student & Teacher):| wo. | quae assembly language code that will display 10x10 boxes of asterisks (*) by ing. model small mov of, '® > stack. leoh prot : data int alh uk oth 10,18, °$ * prop print - cocle pop CX yet 7) moy OX @cate Pp int steak endp a ds, aN nl Pao mov CX IO mov al Ovtesr: 2 pet vb a he, Call printstar | ep ath cl nl vel oudet nl end P 10 op mov ah, lich ancl yal) iat ath NE. uy gn P prindstan pr a push cx 7 OV cx JO mov ah) * Signature (Student & Teacher): Comments/:ee LAB #14 Theory: Decimal Vo Decimal Input and Out Put Procedures: Even though the comput nel input and output copreaed Soe Te ning in binary, ie in cial tn thin sean ee rere Convenient for the user to see . Procedures for handling deci 1g decimal Task 11.1: Programming Practice Hint: Use Procedures of DECIN and DECOUT 1 input from user and will display it, emodel sma) CUP al,’ [toy ereby | Aloha: > stack looh ee OY ox yes YOR Cx cx data ™mimnps 3 =. x Imov bactod Cone PAC? Whe XIT wiitee ui ' | ax R dre cb* Main Proc se plus Exits, si ox i Pop dx Us, call Decy ih TMP REPEAT em eS Call Decout minus Rey By eae xo r E Wiitee_ mov aly ich Moy Ex, ( OT_Diait: ad ane ink alh oi ae Main Ende plos- anion Meas ect Decin Proc int ath NT ath tov tls eee Repeat 2: int si ae % push cx Ps my swe bean uae Push Ax ae Decout Pe bop atte Begin ‘ ONGE Not Digi Mew ot ath ‘ . Mov ah, 2 oup Ls! bush, = pai mov AC, “9" JINLE Nol _Oig HRS [Pep cx int ath 2 AND Ax ,000FH CMP Axo | PoP ‘ax Push ax & aipha [PeP_ax XoR bx jbx mov ax lo Push Ax RET 1 [Decout Erdp X R MUL by mov af, SK Cx, cx loop bx inev-ahy> [End teas | Moy ah | ee ane top alh int ah int ath Nits os CMP. oh 0oDh E_REPEAT20.2 Write assembly language code that will ealeulate LC Sample Execution: ENTER FIRST NUMBER: 2 ENTER SECOND NUMBER: 5 LCM= 10 "model small e Stack \ooh 2 data VL aw 30 hr ovi7 dw 4S Duce aw q © LCM dw 2 ecode Main Proc mov ax,@dala ™oV as,ax mov axl Mov bx vb while: mov Adx,O mov cxr/bx div bx mov bx dx mov AX, CX cmp bx,o INE While _ mov tC ax MoV CX,Axn Me M of two numbers and will gy by, mov ox lag mov ax vl whi)at mov x2 | XR dx dy MUL bx div by Niv cx push dy Mav LOM )ax INC C& CALL = Decovt CMP 4x ,0 moy ath ch INE While: mt ath ed oe Main frdp at aIh lo Decout Proc mov A 13 push #x int alh Push bx ov aly. Push cx Poe push dy Dp ah, a CMP Ax, 0 mt alb 5G Alpha Loop print Push Ax POP oly Moy dtc? fheP cA ev ah,2d Pop bx int ath Pop ax pop ax [RET | Neq aX Decovt Endl Nipha. End Wainy2 3 Write ass semb | mmoclel Sy nbly language cod us. Smath le that wi ill ealy culate G ic> estack ; Pata Ooh ey eo ee tH nd VS db ey} wdecout rev att ote oy . y2 ab *& NTE Quy 4” iw aye nc Bs uth ~ m i ‘code Sep . &” cy oe We ay Main Pe Rush by PC JEXE ts CMP fy, o aye oc Push cx ie) Ay SNE while rev Sauda [aes [eb He ™oy ds ae Pop bx ¥ Ate Kyo Nt RET rath. vey ona vA see NOT_digit . mov dO, 13 wt ath, TOR Lby [mov ae it aN Call dec: cy, ©v Lhiop | ey hy cn Cx pint oy ; i Push, NOV ah Vk Vint: ax Te | [ey Lot [PoP Wav dx ig CHP LCD ENT aC [ADD ax Mov ah oe vt [SE mmus bw Begin [Tut Ou nt i PAL? ci the ak 4 de Call deci SE Plus uate Tae? pent wal decin TH repeats. [Pest ox Pop ax Xa nus: Push b fo Pop ax Mov Cx, } push ox iP cK ; ; Push i Pop by x eat + int alk a x Po SR Dx, D Nepeat 2» a P ax tyke Hey LI pha RET cM oe ge wat al beh a Dec + P Dx 0 al, ‘9) it |moy at do cut End FE @En Snle Weta mov als Endl Nain m 4 loop ND A ee | aN yee oy x) 000FH T Ah “4 oy toe a aes Pop ix Vox, ab y mevaxi|q |NE TmMe MUL RB { \ G RX @ @Repesd oP Be Iphas © End too ADD &x KOR oy Mov Ax offset 0D sfx [Mov bx. | ev ue Ve Sa Gute j ae nut | xoR Dx/Dx*Moclel smotl P AX, O mov NS “Oe lool JG, Alpha a gh ar duo Push Ax Print = » OY 100 ,2.00) 300 al ©) 400,500 600 0oJMOV M, - PPol? Ax code ov ah, 2 ADD DLAQ Main Proc Int ah [INT ah Mov ax, data Pop ax loop print Mov Asia x Nes a por ax Mov St) offset ary =4 0p en Moy ex,7 Alpha. \ mn b MV ax,o Xor Cxycy PoP. OX Las Mov Bx,lop Pep ax io. ox, tsi] While_s RET +: tf on! Dec a Loop LL nae Dx Dx a i Cath Decovt Div Bx oun pew ahi ch Push Dy wnt aly INC Cx en ie CMP ax, 6 a yor al, ax SNE While push bx Mov ah, > mov Al jo xX t vsh c hat’ al push ax LL 4 -40- Task 12.1: Programming Practice Task L. Write a code that will add elements of an array and will display their sum,ne code that will calculate average of an array and will also dis “ich aenoll ask 2 m Push ox Pep dx cotack \oah Push dx add Al,48 Jota dd ax,66Sd int ath aera 106 200,220, 400 R ed Joop Print ook J yain Proc pra Pop Ax mov S: Ff seb ay tet ah Pop Ax mov cx, 4 Pep ax RET MOV AKO LA yi ax ecout endp add ax {si | Poa ind Main add si) 2 Hor cx ex loop L4 Mov bx lod} YX Whilee_ ov dx x Xor Ax ch ‘ Mev b Ca 4 vx div bx div bx Call decout Push ay Mov ah 4ch inc cx ath ICMP Ax d Main En Ap P “ig. Recouk Proc NE whilee _ Push ax wey aN sink : Posh bx |Task 3.Write an Assembly Language code to search a number in an Array. *mocdel small Leop Searchin sstack look mov Ax offset Ya, e data Mov ah, avy db 12,35,11,89,4 int ath O16 14 1S IMP Ende vi db “Entey Numbers” Num Found s VQ db 10/131 "Number Found $” mov ax ,offset vd by V3 db '0113, umber Not feunds mov ah) J valve ao 2 int ah * code End_: Main Proc mov ah, Uch Mov ax @data Int ath mov ds ax Main End p mov dx offset vb End Main int alh Mov ah, \ int ath Sub abi ‘o mov value,al inc si mov si,offset ary Mov cx,\O mov al, valve Searching: mov worst CMP al, bd “2 Num Found-43- Task 4.Write an Assembly Language code to Print number of o, urfence ofa number in an Array smodel Simadl he ‘aut CMP ax,0 ee ‘ooh iwe un NE whilee_ Pa dw oO Valin trdp freon thy x dw oo Reeout Prog’ Prov AL ,to ant AY dud 100,200 Boo,hohPOSh Oy — fint xh So- ecode Man Pegg Mov AX @daba mov ds Mov MP ARO HPrink + Ax SS Alpha Si, offset avy pusn ax — badd 4g Mov cK, MoU LA: eae ax, [si] JE vo OX, & 24 Xx ep by Nad st, > A\pha OP ax loop LA HOR ox ,c, RET JmP exit Mov bx j|oJDecout tne LQ: Ww lee. tnd Mais We count YR Ox Dy Ade $i,2 DIV By Senp 4 Push py ay Beebe In ceeothe Jc to print minimum and maximum number in Array emodel smatl Sarge * stack ooh mov La, Vsi] . e data * a ae aw db lols )4,\1)% Sp carp «code main endP Main Proc End main: mov ax @doda mov ds, aX mov Si yof feet ary mov Cx) S mov bl, Lst] Joop’ ‘ cmp {si] pod J Ne small ore Bes pares inc SI loop looptt add b8,48 mov Al, b9 mov ah, 2 int alh smoul z mov b&fst] Jjyep campare Comments/Signature (Student & Teacher):LAB #13 Theory: String Instruction The STOSB Instruction move: is incremented if DF=0 or de contents of AX to the word flag setting. Task 13.1: Programming Practice Task 1, Write assembly language code to take input a strin, Sample Execution: ENTER STRING: ABCDEFGH ABCDEFGH emocde) sstack loah + data vi db “Ente x String -¢" vidb jo dup!) *Code Main Px Be MOV AX, @dloda as ax ah 4 AX) oF Fse4 va Qh Mov $s} offset vr UL: Mov Mov Mov int Mov ah; } int alh CMP al, \3 JE Py eqvam End S the contents o ‘cremented if D} tthe AL Tegister to imilarly, the STOSW ix at address ES:Dy and he byte addressed b ES:DI, DI instruction moves the ‘updates DI by 2, according to the direction ' from user and display it on next line., mov tsi], Tne si IMP \4 Procraménd: mov dx, offset vi int ath mov ah: Yoh int ath ae Main Endp End MainPat “Task 2. Write assembly language code that reverses the string ewodel small * Stack leoh «data vb db “Hellop” *code Main Proc mov ax, @ data mov ds,;ax mov sigoffset vi mov cx, Li: mov ah,t looP Lt mov CXS Lior pop AX mov Ah) 2 int ath Loop L2- mov ahi 4ch int ah Main €Endp End mainON -47- Task 3, Write an assembly language code tha rmoclel smatf ,slack [ooh dole fyler db Oab,Odh, “¢” vb olb 4 dup('g’ v2 olb % dup ( *$) *coole Main Proc mov ax , @date mov ols ax ™Mov X,9 moy ST, of fset ve input Loop é mov ah, 4 int alh Ov Csi, ad EiP al, Odh, je exiz loop NC St loop inputloop exit loop? mov bh, “$ , ay [si J bh * will Vopy the string in same string, moy Si offset vL Mey A offset yr Moy cx, 9 whe mov b9,[s) mov Idi] jb NC ai inc of? bop copy ah/F yo Ax, offset vi int ahh prov ah, ¥ x prov oly 1 ffsed énle int ath rv ah@ ™moy Ax offset - tnt alh mov ah, 4ch int al, Main Exelp Enel Mainee AB rane, Weite an assembly language cove hat wil revorse the Sing 0 SNe Sing mov CX,\7 *stack looh » cata . pop a db “Assembly Jan f mov a 1h “ Assem | ure ay ecack Main Proc loop Ld mov ahj4 ch int alh Main Endp End Main . mov ax, @daba mov as),a xX mov ah, mov dx 1offset vi int alh mov si, offset vi mov ¢x,}7] Li. mov lx , tsi} posh bx We &1 loop EAE mev ah, mov Adio int 2h mov ah, 2 mov AL (3 int ah249 ‘Task 5.Write an assembly language code that finds length ofa string, Sample Execution: omodel Smell «stack lool «lata vl ob “Ey fer String : J] v2 db 400 ‘ v3 olb 13,10, V4 db o »cocke Moin Pye ™mov ax, @dota ™ov dsiax ov lx offset vi OV ah 4 ing alh YrIOVv Si offset v2 UL mov ah, | int alh mov [si] al CMP al, 13 Je Enter inc Si Inc vA ENTER STRING: ABCDEFGHUKL THIS: 12 “Length is +4” Loop 21 Ener « mov oly, o fset v3 ™mov abibich Int alh Main End p Enol MairTask 6.\\ mibly language code that removes spaces in the string, Sample Execution: ENTER STRING: A BC DEFGH HGFEDCBA P ~ t ints ‘Model small Y = . oO Stack jooh Lod sis * dota, mov Ual wh db “AR DEt rn Wh V2 db ay Dop (2) cop Psint + Code mov ah, Yuh Main Proc wt lh mov ax , data Main md p " mov ds, an End Main | Mov E45, AX mov alx voFPset yAL mov Ax, offset v2 CLD mov cx,\| SWAP + Moy Sb | add 3} nel loop SvoppP mM ov oly , of f CLD mov ah ) 2 by cml Set y 7251. rask 7. Write an assembly language code that prints no. of vowels and consonants in string. sample Execution: eet ENTER STRING: ABCDEFGHijklmno VOWELS: 4 CONSOTANTS: LL lid smal mov oxy S Oe REPNE scAsB ax sack ah . JE @Tnoementvowd hee diwv7 ™ ov cx, 2) REPNE ScASQ é @Trrcment.¢ loka cb “Enter Shing « &" db Dah NOE db OdhoPhtonsotants§ 'db £0 dup(? - ' ae “ness? ar oNet : Div Bx “aeiop” | db “beal fat ronp' strange” 5 olb “pp pd HyELMNPGRST VINK v2”, ode : cup AX, Hain Pro. ee Mov ax@dala |p. See ae aint me Dec by mov clio mou oe | INT 2th pax exit: Mev dh (S rev dy offseb ull mov int ath mov ahF Mov ah, L int Mth pov Print = Jen aivy [int ath ens all Fead_sty Xor ax 1A ADD DL,Y WR dade a up lh ea Si py Decout loop Print: % bx iby Sea dx yy Pep dx % @Bat MOV ahyq Pree] WP & ®Count nt lh ae PoP lex Lops XOR ax jay IPeP ax RET Décout Endl p ESD Mom Mov al ych a 8idonts /Signature (Student's Peachedya LAB #14 Theory: Macros and Label Conflict SMP Exit Local Exit Exit : mov AX; PA moy Ax) offs ef v4 cmp AX, PL ee ah, 4 JG Exit tt Ay a Ax, p> Mov ah 4h i int all Naim ° Stack \Ooh Main tndp © data End Matin Vi dab “OK gd? * code Main Or dt Woy Ax @dota Mov Comments /Signature (Student & Teactler);254. LAB #15 Theory: Inline Assembly The inline assembler is a feature of some compilers that allows «very low level code Write, in assembly to be embedded in a high level language. Task 15.1; Programming Practice Task L.Write inline assembly code to print factorial of anumber. emodal smal) | push bx ay Stack loah > Co Dace, Proc H al ,ooDh | Pop ax kas yePecd 2 neq ax call decin mev dit@y” |r ax, ba Alphas me ax§ i . KOR Cro Push ax Mov by /|Op alt factored While_s CU decouf XoR Ox, Dx mov ah) 4ch DIV By Main End factorial Proc , push b ; CMP Ay, 0 mer eat? Rahs ewnp Word Me [bp |mov ex, | » aah PEP ty10 | 3g end- ples: et 3th gow dp we ext) Ue ay iris (a dec cx f ei 4 deci, P ae posh <& Tee nck eh Rett Proc | Pop ay col factoiiad ynge nate) Posh ax |Aelel olf, 18 add Gx; word PIR DpH Temp al, (4 a) weect PTR [bpe4) finle not digit] Leep prin sade , J nd ax ,O06F' Posh ex pap ox ¥ 2 push Push Ay oe cK ep bp se lc op bx ° x : Factorial Endp Pop bx posh ax fee ed decin Preer 35. “i 2 Weis inne assembly code of printing power of number. ask 2. it smectel Smad) sub ee i eotack 100h Wov [base |, cata mov el pores] fox . 1 ole “Enh wes ae a mol Txesult | vi db “ente bases $” nl clb \3 10, $ v3 wb & , an Mm abt, gs mov byt phy vesolt a) ee aw 4 Ne sa Kense ea o oY waiast te . fov-bnd acto! all, 20h. ” am ends ‘ ° mov ah, 2 cole ey ash int ae Main Pxoc Mov ah 4 fs 1M eey ea mo Wt alk int ee V ax@deda Sey al Teak T dhaet Moy AS) ON aaa al, 5a. 5 ov mov ae rolfcet v4 [re ak mt lh mov ahya int ae ah) A! Bie a ‘ Rad (35/4 oye Tpower} a) ay shy 5 uy Upomer'| 30h mov abe, of sen ov dx { offs ye ins ie v4 Mov ahi i mov AL bute te Int Ah Add at ady. F Yesott | " y MPY ah, int ahh byt Sth=56- Task 3. Write inline assembly code of calculating Arithmetic operations with proper Menu, i | “model smotl *stack looh ° Data Main-Menu db ab ab db db alb I db ' db db Numi db NUM? lb Appa lb Supt db wot tb Divi ab EX ob Ans db Continue clb ops db 2 op2 db 2 Operand db 7% Con db 72 “cede oe Main Proc wey Br @dada Bee sls 1a% t ov ath, a A fbr 1 ; jot am } ™ov: ah, | > INT al ODH,OM, “Calewlador”, ODH » OAH “Dyess K fox addlit ion”, ODH, OA “Dress “6” fos Subshraction”, oDH,0AH) “Dyess (N’ for Multiplicabion ” oDH,oM) “Press *D? Por Division ”, oDH,O4H “Pxess E” fe Exit ’ ODH » ohn o “Pres. BR” fox Return the Main Menu’ op ee ok Hee Be Be em eH ZoDHoht “Enter Your choice”, ODH 1 OAH, 'P “Enter First Number +”,ODH, oH “Enter Second Number,” ,0DH, OAH) ODH, OM , “For Addition ”, 0 DH, OAL ODH, OAH, “Fer Subsfsaction”, ODH On DH, OAH For Multiplication” , ODH,OAH)§ ODH, OR) “Foy Division”, ODH, OAH," ODH OMI “Good Bye and Hawe Nice Timepoit moy ah, int allemov dreffsel ans |mov aber \ fnt ale 4S op2, AL y mov CPs in Jrov Ah, 4 i ele opt NI 10k, mov aby mov Ax Offset Angmov Hie nov ah t int ale, tnt us 41 pe mov ola of se ity mov opd Ans fat earn JE foul J mov bhopy re Ay, 80304 mov oy aly ‘E? ADP ALBL Tov Avot | nb alk JE Exit [AAS wrov ahs ly? ‘aa mov ov ah, OR Ax, S080} same Je fe mov alaffet mov ah OEH ™ Og € py i . mt JOR, man EDN ‘“ oe mov ahiq gop @i, ‘y’ mov ah, 4 onov atch. maby . |SE Star mov dxf fsedivt |. , Fae geet enti Emp ol, =) fot ae Yat a wey ahd SE Exit prey ay 9 Main Endp ji / | nt aly eee Tot Hi ealinaald Endl Main | ee al, ty? mov alx,offier MLL \rnov ah] | G Stant, ; INT alla int IK | cour ede? |r Oh wan gt JE Exit tnt ae way ahs) " mov abyl mov aust nom? ink alk. INT 2 ov oft of feet subs [70Y OPL AL mov ah, } mV ah/4 int ah mov axoffsetNan> [raey p> lr ov alm of fset HL jnt alk mov ah) Wey gx! mov lx opyset 3 mov op2iAl Gre Bi Pi mov ah) mov bh gpr mov olx,offsed mi agltet om Ings “moy aly oph OR hx, 30 mov bulges oy of eek "ahs ae a 10h, Dov opr AL oR, 13 3030h, : mov aly, ep ° ‘ YF gsignatey (student & Tea oopsLAB #16 Theory: Recursion from th oper prog rations. So this provides, an opportunity itself, Recursive procedures are important in hi, wat the way the system uses the stack to implement these procedures is hidje, rae in - assembly language, the programmer must actually Program the sagt to see how recursion really works. cedure is a procedure that calls Task 16.1: Programming Practice ssembly language code of calculating factorial of number by using recursive Task 1. Writes at procedures. i H; C Decin ?: mov ah ,/ mo i Fs smell oh by Tat ah, mov ah, > ma [ooh emp eel, 0ODh int alk Main Proc Hine vepeata \PoP Gall dlecin amo ax,bx |v ax mov ax, or CXC X i 3 ‘ posh a / cod fachwial bnov bx,[0 ol ce moy _ahitch Drv Bx Main Endp Wa DA Factoriaf Proc omp dt, ‘P INC cx push bp j CMP Ax<0 mov pS? INE Whilee Comp wr moy ahd j dl, 15 a iat Sin ° mov a prey att j fr oh , a eo a rin bi o0v x [opr4)} Baa jeer cK htt Lt, Wh posh ¢x bt ale, 4 | Call factoriod Loe fe , add Ax; word PTR [bo 4] i 5 ee PS jp. bx : op ay tes Hf Path érAP nel Mow torial eny " e ive k 2. Write assembly language code of calculating sum of a number by using recursi’ ‘Task & procedures. Ret A Ne ax sane Execution: | ANE Sip dp Aloka: mie Decin Proc XOR cxX,cx Mov bx ,|0 whrlee: XOR Dx, DX + Posh bx smecal ofl Posh cx estack (coh Push ax coke Begins DIV Bx Hain Proc = fmev ahd fa Decin \Mev as " fs» Ox mov r a NC cx ey eye, P Ax, 0 Push ax . \mov abit x Colt Addition int Qth NE Whilee fall Decost |fnp ates? Mov ah, 2 Mev ah Uch | Je minus ; 7 mov at ib imt ath cep oly : fade it ‘ f& plus Jrev Sua Main Endp DP vepeat 2 fen ait. peti) Pee |'minus mov ah a Push bp mev ex, | Print: oly bprsp les PoP Sai | int Ta poe eect toe at ye JE, END_IF a, % int otk cane Pnqe notde OP Print TMP. retum emp al’ bor dy End_IF: le not. diqiy: ae wo ex, [BPH] [amd ax QOoer PP ox PYsh ax f P Noy Dec cx mev Lx, 10 Pe Push cx rDeabs Boge Cally ae op & Peciacsy ec PEP PX Sisl. cen add by ax Lag " ote cofgtilie/sipsature (Student & Teacher); Pop Ary