0% found this document useful (0 votes)
30 views

Lab Manual

computer orgainzation labs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
30 views

Lab Manual

computer orgainzation labs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 45
Si LAB #2 , Theory: BasicInstructions sr data between register, between a register The MOV Instruction is used 10 Peete ister or memory location. The syntax jg: ", location, or to move a number directly into MOV. destination, source oo ¢ the contet two regis The XCHG (exchange) operation is used to exchange the contents of two registers, ofa, a memory location. The XCHG destination, source {mn this lab you will practice to leam MOV and XCHNG Instructions in 8086. Task 2.1: Programing Practice 1. Write a complete program to do the following. 4. Write a code that will input a character from user and will display it on the sme ie next position Sample Execution: ENTER A CHARACTER: A i = I) Z3\ mont ¢ c:\MP >) 2:\ c:\ 3) C:\ Edit, (Flename-ASY «Model smal) « Stack 100h « Data Vad DB Yb * Code Main Proc ) Cs\ MASH Filename-ASM | Moy’ Ax, OData 5) C2\ LINK Frlename-chj ; | Mov Ds» Ax Mov Al, yard Mev Ah, INT 2h Mov Ah, 4ch main End P End Main. yes\ Pilename-exe . <9. | b. Write a code that will input an uppercase letter from user and will display it at next position on the same line. model Small astack lool edoha Y AB “entex the chosader-4,” ve eb ” Enter the Uppercase Lelie: § 2 AB lo, 1a“ gs” code Main Proc Mov cx ,@dalq 1 OX Mov dg, ax Mov ah, Mov Ax, oFfsek vi Mov Ax, offset VL ‘Int ally 1 Mov ahd INT 2), dd b Mov bial Ni OV AW) 2 Vov ah, 4 9 Mov lx) of fsek V2 INT WA Mey lah lc) Mov ah) 2 INT a\h 4 Mov al, bd Matin end INT ath End Moir, Mov al ch HY ony Matn end id nap | END Main Comments/Signature (Student & Teacher): -10- es Theory: Programs with Basic Instructions MOW AN, Ls uso for thing input from user and MOV AH, 2 is used for displaying. Task 3.1: Programming Practice 1. Write a Program to that will display a “2” and will input two decimal digits less than 10 and will also display them and their sum on the next line, with aq 4°) message. Sample execution: Le Mov al 9 i Shoe i io va ge “ts $” Mov ah) Main Pace ‘wt a Mov ax ‘@data Mov ah 9 Mov ds, ax Mov AW offset vy Mov ah, malts Mov dx, offset VE TNT aly Mov ah, L wy Oy 2. i ah 4 at io Mov bial Mov ahy ahi 4 cly Mov cl,a4 my aN \tnt ae u > Write a program to input three initials, read first, middle, and last initial of a person's name and display them down the left margin, Sample execution: ENTER THREE INITIALS: JFK kK emodel smal} mov ah, 4 . mov dx offset yd itag eh Tnt a\h mov aly, 2 Hmov Ax, bl int QV Vi dB “Enter Ute $” v2 AB 10113,“ «code mey ania Main Proc wnov AR, af offset V2 Mov ax, Ododta ee Mov dls) ax mov and $Mov ah,4 [Ent 4p, Mov Bx , offset vi ey ah, Ax of fsel v2 Mow abd math ov ' INT 2)H NOV me Ov q Mov “oe Tint wh. 1 Th mn mov ahi Hch ‘ ‘Int al Mov cya ” j 5 Mov ah 4b ain -endP TNT ah End Main ‘ew ch ol ~ Comments/Signature (Student & Teacher): ‘Theory: Add, Sub, Inc and Dec Instructions The ADD and SUB instructions are used for performing simple addition/subtraction gf, byte, word and double word size, ic., for adding or subtracting 8-bit, 16-bit oF 32-bit, orang respectively \ Te INC instruetion is used for inerementing an operand by one. Kl works On a Single opera ) be either in a register or in memory. & The DEC instruction is used for decrementing an operand by one. It works on a single Pea be either in a register or in memory. fy Task 4.1:Programming Practice 1. Write program to input one ofthe hex digits A-F, convert it into decimal and dg the next line. bi Sample exect ENTER A HEX DIGIT: C IN 2 emodel cmall © Stack look ° doka VA SB “Ente A Wek DF 1 V2 dB 10/13, “Sy Seal ah Bal nay *code Main Proc Mov ax, @dala Mov dss ax Mov oh 94 Mov AX, offset vi INT ah Mov ahyt “INT 3) if weg AP Grate (Student & Teacher): LAB#5 theory: Basic Programs task 5.1; Programming Practice 1, Write a program that will display a 10 x 10 solid box of asterisks. Hint: Declare a string in the data segment that specifies the box, and display it with INT 2h. emodel sm © Stack \ooh 2 data, A VE AB “wnseteneet § V2 dB 10,13, “anne saree $” Sample execution: Mov QXx Moy se Baeln Mov ah, 4 now Ax , offset Vi INT Uh Mov oth -4 ss ax , oF eset V- NT alh : TNT Oly TNT Ah Wain Exelp INT Wh End Main TNT ath TNT Ah TINT ally INT 8th “INT ath Mov ah 4ch VJINT 3h q ee | Assignment #1 | “ display them i Jay “2, read three initials and will display them in hey it that will dis fan tt tbe vvalso beep the compuler. ofan LL x 11 box of asterisks. j bho INT 2) i Sample execution: pve al EE uPK TON INT ath seieeats Mov ah 4 ee Mov bx, offic » essed pov dv, ofcset V2 [INT I I PUNT ally y seagectene Mov dx SINT Ih cs nel yamodel small HINT alh TNT A = Tack. (coh INT 2h ate eae oy INT alh INT ah V2 dB (OrtB,"esseanenerg ti” ah) 4 INT alk V3 dB 10,13/°$" oa ax offet Mov ahitch V4 dB “ewes $” ayh INT ah pode 2 Mov Ax offset vy Matn = Nain Psoc INT Uh End Nat Mov ax) @dalq e len as, ay Mov Aly, a Mov dQ, bd ee ahs4 . Int avh Mov dx, offsel v, . INT a\h kg ee vi} i , Mov ah)4 IN rae T ath Mov bh,ab LAB #6 a conditional jump instruction, JNZ destination - JMP (jump) instruction causes an unconditional transfer of control. (Unconditional jump) The syntax is IMP destination Task 6.1: Programming Practice 1, Write a program that will take input a letter from user. If itis an upper case, the program will display it otherwise program will terminated. Sample Execution: ENTER A LETTER: A A ENTER A LETTER: srecle) small "stack \ooh mev dy off sed v2 dota pint 2th Vi dB “Enter a letter: ¢"ECMP BLA, v2 AB 10, 13,°$” JL pe ‘Code Mp BL SBh Moin Proc ay G — AB Mov ax, @data mov cs, ax MoV ah 4 int ath mov Ax ol Fset Vi AG: Int AIK mov ah lich ev ah | L int ath mM ath main endp ov bhal end main 16 2. Write a program that will ake input a fetter from user, ICIS “Y" OF “Y” the pro, display it otherwise program will be terminated. ny Sample Execution: ENTER A LETTER: Y Y ; wy ENTER A LETTER: y i y ENTER A LETTER: A smodd small ce ake : stack \ooh iy tee = : SMP EF "i “ Enter a fetta $"Japo, «code mev ax, @data mov doe mov dS,ax me athe / mov ahd CFs nov dy jortsek yf mov ah,4ch Int alh. nt ath. rnov oh, alts dene int ath end i ‘ NOV bh, af 2 mov ah ;> mov AQ, 10 fot ath mov Ads, tnt alh CMP BL/T4h JE ABC We 4. Weite a program that will display a row of 80 asterisks. Hint: Use count-controlled loop. Tadd gmat sctack \OOW rAdata scode Main Proc mov ax data mov das,ay- mov CxX,8O mov ah,2 - Abs mH OV al ,'#? font alh- Loop AB mov ah ach. ink alh. Main endp end main. ate nn mber of characters in a line in will ct 0 Sere by a rte yy, display it Sample Execution: 5 ENTER ALINE: ASSEBLY Lae ETE oe f NUMBER OF CHARACTERS IN “A we emodel small) © Stack joolh | > DATA VAR DBA * Code Main Proce » Mov ay,o MOV al, a int aly While ¢ CMP ALB ST END While INC VAR INT ath IMP while END_ while Mov ah)Q Mov Abo INT all Mov 8013, INT aly L Moy bf, vAR ADP bI48 Mov AQ, b? ink ath. Mov ah, yeh INT alh Main endp End Nan =. 5. Write a program that will take input from user until user inputs a blank, When user inputs a blank program should terminate, ded small ame » Stack (ooh s data -code ~ Maiyy Proc | Mov ax, @data mov ds, ay, mov ah L- . While s ( CMP al,o ? ( SE End while - int alh ; sue While i End. while + mov “ah uch Wy abh. 5 main endp 3 end main 1 to display the extended ASCII characters (ASCII codes acters per line, separated by blanks. Terminate the Sha, extended characters have been displayed once. TO ae, Small + Stack jooh « data Cio Db apd LA code main Proc ion ax, @data mov ds,ax. emocel mov ah,2 mou bl, 80h |rrey 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 Prints 229- 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_REPEAT2 0.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 Wainy 2 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 cee othe 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 Main Pat “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 main ON -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 Main ee 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 ah 249 ‘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 Mair Task 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 7 251. 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 Peachedy a 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 Pree r 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 alle mov 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 oops LAB #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 en y " 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

You might also like