0% found this document useful (0 votes)
28 views8 pages

Adobe Scan Sep 27, 2022

Adscan

Uploaded by

karthikbgmi143
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)
28 views8 pages

Adobe Scan Sep 27, 2022

Adscan

Uploaded by

karthikbgmi143
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/ 8
CHAPTER 5 PROGRAMMING EXERCISES INTRODUCTION The exercises discussed in thi apte! microprocessor trainer kit and ase Barina who developed and tested these Programs has the user RAM sa uees the programs. The readers have to refer the operation manual oF thei trainer kits for the user RAM area an : locations. d load the programs at suitable 5.1 EIGHT BIT ADDITION Problem Statement Add the two hexadecimal numbers stored at the consecutive memory locations 2000H and 2001H and leave the result at the next location 2002H. Memory Initialisation Through the kit’s memory access commands load the desired numbers at 2000H and 2001H. Program Listing Mnemonics Comments LXI H,2000 Load HL register with the address of the first 3002 20 number 3003 TE MOV A, M_— Bring data into A reg 3004 23 INX H Point to next location 3005 86 ADD M Add the two numbers 3006 3 INX H Point to next location 77 MOV MA Transfer the result into 3007 71 memory location Stop execution HLT x , s Microprocessor and tts applications x Mi x esult after exe i ie program Result after executing the progra the content of the location 2002 for the sult. Cheek the ec 2 HIGHT BIT SUBTRACTION Problem Statement Subuast the hesadeetmal number stored at 2001 E from the conte, SQOOEL and Teave the result at 20021, tent Memory Initialisation S at 2000H ang 2001 memory access commands, H through th Program Listing Opcode Label Mnemonics Bring data Into A reg ‘oint to next location Subtract the 2nd numbe Point to next location Transfer the Tesult into memory location Stop execution After €xecuting the program, check the content of the location 2002H for the result. 5.3 MULTI- BYTE ADDITION Problem Statement Add 2 multibyte numbers The location of bytes) of the number. The first data is stored Starting from 2001H and the second data is stored Starting from 2010H. Store the result Starting from the location 2001H Replace the first number with the result) 2000H stores the size (number P 19 Programminf pcre memory Initialisation [et us assume that the ne two hex numbers ro be added TAGASE and 42305 size in bytes 0 stored Fhe muunber ny dovlach ay stored in toca mie res sicanoredd in focatie! HH, GA an 200211 and 74 200s {and 42 in So the phe date SE The data C53 stored in location 2010H, 23 10 211k , 231 012H Flow Chart s (HL & DE register PUr? * | e count = Byt x0 Microprocessor and its applications Program Listing Memory Locaton LXI_ H,2000 Load HL regaster with 00 address 2000 3007 20 3008 46 MOV B.M Set byte counter 3009 23 INX H Point first byte of datat 300A 1 LXI.D2010 Load DE regsster with 300B 10 address of 2nd data 300C 20 300D AT ANA A Clear the CY flag. 300E. 1A TOP LDAX D Load Ace with a byte dats) 3008 8E ADC M Add 1 byte of data2 with | cy 3010 7 MOV M, A Transfer the result soll 13 INX D Point to next data byte 3012 3 INX H | 3013 5 DCR B Decrement byte counter wa 2 NZ TOP It the Byte count | 3015 t ts not equal to zero 316 3 repeat addition | MVI A, 00 make Accumulator = 0 | | | wie MW RAR carry 1s brought to bit T MOV M.A transfer to memory HL stop execution IB Result OOLH onwards for the result It N_ bytes Check the contents of location 2 each of the number added had N. bytes, the result would be NAL bytes long Note: ‘The above program adds the two numbers in Hexadecimal § Foe addition in decimal mode, insert DAA instruction at the locat 3010 with op code as 27 too the program, so thar the result as stored: from: the mer » 20101 Lonwards aa Mrogramming Leercive WI FA giock TRANSFER OF DATA problem Statement block of data ts available starting from 20031 Gource tock, Tr that it 15 stored starting from 205011 (aestinanon block block s of data) 1s stored in 200241 er of bytes if the block (Siz the umb Jow Chart B Grart ) v Set HL register pair to Source block address Set DE register pair to Destination block address Set byte counter with C reg il Load Acc. with a byte from Source block |< | Store Acc. content into Destination block Increment the address pointers (HL & DE) | y YX > No- f Yeu GD cations rand 1S applica rys0! tigation cy Initialisatto ory Mem! of specified bytes starting on 2003H onwards. Load the data ber of bytes in location 2002. Load the numbe ram Listing Prog! » Opcode Label = Mnemonics Comments Memory Location 3003 02 address of the size 3004 20 of data 3005 ul LXID, 2050 Load DE register with 3006 50 Destination address 3007 20 | ae * Nee M Set byte counter | 300A TE STAR fon A Pornt t0 source block | 300B 12 STAX 8 M Bring first data to Acc 300C % ANE - Transfer to destination 300D B INK 5 Point to next location | 300E ob DCR c Point to next location | 300F C2 NG ea , Dectement byte counte 3010 OA JNZ STAR Ig byte counter not 0 30114 30 Tepeat transfer. 3 012 76 ALT Stop execution Note Remember that After execution of the program, check th block Starting from 205¢ © content of the Destination JH. Find wi hether itis a Copy of the Source block. 55 PROGRAM To COUNT A “GIVEN VALUE” IN A SET OF DATA Problem Statement Check a block of data and count how many times a given value occu in the data block (How many times the given value is found in the data) T Ls size of data to be checked is stored in 204FH. The data is stored startin? from 2050H. The result (number of occurances) is to be placed in 20751 Flow Chart Vv Initialise the HL regis ‘Bister with DATA block start address ‘| Vv set byte counter] Set number of times counter to (i) ' Load Accumulator with the VALUE to be checked / Vv Compare Acc. = Data byte No Yes Vv Increment number of times counter v > Increment data pointer HL Vv Store 7 | | | | J 84 Microprocessor and its applications Memory Initialisation Store the number of bytes in the data starting from the next location 2050H at 204FH and the data block Program Listing P| $ Comments Memory Opcode Label —§ Mnemonics Cc Location 5 nM LXI H, 204F Load HL register with 3002 ~ address of size of data 3003 4F 3004 20 Sate 46 MOV B, M Set byte counter S00 f= MVI C, 00 Set number of times a _ 00 counter to zero ith VALUE t 3008 3E MVI A, XX _ Load few 3009 xx be chec! 300A 23 INX H Point to ie memory 3008 BE TOP CMPM Check data=GIVEN VALUE C2 JNZ STAR Go to STAR if they do 10 not match 30 oc INR C Increment counter 23 STAR INXH Point to next byte data 05 DCR B Decrement byte counte: C2 JNZ TOP Go to TOP if. byte counter 3013 OB is not equal to Zero 3014 30 . | 3015, 79 MOV A,C Copy C reg to A reg, | 3016 32 STA 2075 Store the A register 3017 75 content to specified 3018 20 memory location. 3019 16 HLT Stop execution Note: Remember that before ex ‘ecuuing, the program data has to be loaded from the memory location 205( JH onwards, and store the number of Replace data to be checked at 204PH XN at address 3009 ith desired value to be checked Result

You might also like