Fetch and Execute Cycle
Fetch and Execute Cycle
Fetch and Execute Cycle
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Example of <strong>Fetch</strong> <strong>and</strong> <strong>Execute</strong><br />
TASK: Add two numbers FF + 1 = ?<br />
Program Algorithm :<br />
Step 1.<br />
Step 2.<br />
Step 3.<br />
Step 4.<br />
Step 5.<br />
Move number FF into Accumulator (AL)<br />
Move number 01 into register BL<br />
Add BL to AL leave the result in AL<br />
Move contents of AL to memory address 300h<br />
Stop<br />
Machine code in memory (assuming starting location :000) :<br />
Address 0 1 2 3 4 5 6 7<br />
:000 B0 FF B3 01 00 D8 A2 00<br />
:008 03 CD 20 X X X X X<br />
Assembly Program Listing<br />
MOV AL, FF<br />
Machine Code<br />
B0 FF<br />
MOV BL, 01 B3 01<br />
ADD AL, BL<br />
00 D8<br />
MOV [300], AL A2 00 03<br />
INT 20 CD 20
Register <strong>and</strong> Memory Contents Map<br />
PC AX BX :301h :300h<br />
0 0 0 0 X X X X X X X X X X X X<br />
AH AL BH BL<br />
MOV AL, FF<br />
(immediate addressing mode)<br />
0 0 0 2 X X F F X X X X X X X X<br />
MOV BL, 01<br />
(immediate addressing mode)<br />
0 0 0 4 X X F F X X 0 1 X X X X<br />
ADD AL, BL<br />
0 0 0 6 0 1 0 0 X X 0 1 X X X X<br />
MOV [0300], AL<br />
(direct addressing mode)<br />
0 0 0 9 0 1 0 0 X X 0 1 X X 0 0<br />
INT 20
Question : What corrections needed to get the correct<br />
answer in memory locations 300h <strong>and</strong> 301h ?<br />
Use MOV [0301], AH 88 26 00 03<br />
or<br />
16 bit move : MOV [0300], AX A3 00 03<br />
Problem 1: Modify the code to add two arbitrary bytes .<br />
Problem 2: Modify the code to add two arbitrary words<br />
using 16 bit ADD instruction.<br />
Problem 3: As problem 2, but use a 8 bit ADD instruction.<br />
Hint: Need to take into account the carry bit <strong>and</strong> use ADC (add with<br />
carry) instruction for the addition of high bytes.