# When it is executed on a microprocessor of clock

• Notes
• 22

This preview shows page 16 - 19 out of 22 pages.

When it is executed on a microprocessor of clock frequency 5 Mhz, takes 415 or 0.8 microseconds to complete its execution. The same instruction when run on a microprocessor with 4Mhz clock frequency takes, 414, i.e. 1 microseconds. NOP is used to produce the delay, without effecting the actual running of the program. Consider the following examples, in which you are trying a produce a time delay of 1 ms, over a microprocessor, with a clock frequency of 5 MHz. Time taken for each clock cycle is 1/(5 MHz), which is equal to 0.2 micro seconds. To get a delay of 1 ms, we need to execute 100010.2 or 5000 processor clock cycles. The following program can be used to produce the delay, with the counter value correctly initialized. clock cycles MOV CX,N ; 4 N will vary depending on the ; amount of delay required DELAY: NOP ; 3 NOP ; 3 LOOP DELAY ; 17 or 5 LOOP instruction takes 17 clock cycles when the condition is true and 5 clock cycles otherwise. The condition will be true, 'N' number of times and false only once, when the control comes out of the loop.

Subscribe to view the full document.

To calculate 'N': Total clock cycles (CT) = MOVE clock cycles + N(2*NOP clock- Awmbly Language Programming (Part-I) cycles + 17) - 12 (when CX = 0) 5000 = 4 + N(6 + 17) - 12 N = (5000 + 8)/23 = 218 = ODAh Therefore the counter, CX, should be initialized by ODAh, in order to get the required delay. Example 2 - Array Application This program adds a 5-byte number in one array, called NUMl to a Ebyte number in another array called NUM2 The sum is stored in an array called SUM, with the state of the carry flag stored in byte 6 of SUM. The first value in each array is the LSB of that number. ALGORITHM : Make count = LEN Clear the carry flag Load address of NUMl REPEAT Put byte from N U M l in accumulator Add byte rrom NUM2 to accumula~or + carry Decrement counl Increment to next address UNTIL count = O Rotate carry into LSB of accumulator Mask all but LSB of accumulator Store carry result, address pointer in correct position. ;PORTS : None uscd ;PROCEDURES : None used ;REGISTERS : Uses CS, DS, AX, CX, BX, DX DATA SEGMENT NUMl DB OFFh, 10h , Olh , l l h , 20h NUM2 DB lOh, 2Oh, 30h, 40h , OFFh SUM DB 6DUP(O) DATA ENDS
\lic.roprocessor and A\sernhly 1.11npunp Proprnmnling LEN EUU 05h ; constant for length of thc array CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV MOV MOV MOV MOV CLC AGAIN: MOV ADC MOV I NC LOOP RCL AND MOV FINISH: NOP NOP CODE ENDS END AX, DATA ; 1nitiali;rcdata segment DS, AX ; register BX, 00 ; Load dispIaccment of 1st number CX, 0000 ; Clear counter CL, LEN ; Set up count ; Clear carry. Ready for addition AL, NUMl[BX] ; Get a byte from NUMl AL, NUM2[BX) ; Add to byte from NUM2 SUM[BX], AL ; Store in SUM array BX AGAIN ; Continue until no more bytes AL, Olh ; Move carry into bit 0 of AL AL, Olh ; Mask all but bit 0 of AL SUM[BX],AL ; Put carry into 6th byte START Example 3 - Code Conversion Consider the following program which converts a +digit BCD numbcr into its binary equivalent, The BCD number is srored as a word in memory location cal BCD. The result is stored in location HEX.

Subscribe to view the full document.

You've reached the end of this preview.
• Spring '10
• Ramon
• Assembly Language, X86, Binary numeral system, ........., Binary-coded decimal, ax

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern