Chapter 3 JUMP, LOOP and CALL Instructions

27
1 Suranaree University Suranaree University Of Technology Of Technology มมม มมม 2002 Anant Oonsivilai 2002 Anant Oonsivilai Chapter 3 Chapter 3 JUMP, LOOP and JUMP, LOOP and CALL Instructions CALL Instructions

description

Chapter 3 JUMP, LOOP and CALL Instructions. Outlines. Loop instructions Conditional jump instructions Conditions determining conditional jump Unconditional long & short jumps Calculate target addresses for jumps Subroutines Using stack in subroutines Crystal frequency vs. machine cycle - PowerPoint PPT Presentation

Transcript of Chapter 3 JUMP, LOOP and CALL Instructions

Page 1: Chapter 3 JUMP, LOOP and CALL Instructions

11

Suranaree UniversitySuranaree UniversityOf TechnologyOf Technologyมทสมทส

2002 Anant Oonsivilai2002 Anant Oonsivilai

Chapter 3Chapter 3JUMP, LOOP and CALL JUMP, LOOP and CALL

InstructionsInstructions

Page 2: Chapter 3 JUMP, LOOP and CALL Instructions

22 2002 Anant Oonsivilai2002 Anant Oonsivilai

OutlinesOutlines

Loop instructionsLoop instructionsConditional jump instructionsConditional jump instructionsConditions determining conditional jumpConditions determining conditional jumpUnconditional long & short jumpsUnconditional long & short jumpsCalculate target addresses for jumpsCalculate target addresses for jumpsSubroutinesSubroutinesUsing stack in subroutinesUsing stack in subroutinesCrystal frequency vs. machine cycleCrystal frequency vs. machine cycleCode programs to generate time delayCode programs to generate time delay

Page 3: Chapter 3 JUMP, LOOP and CALL Instructions

33 2002 Anant Oonsivilai2002 Anant Oonsivilai

LoopingLooping- DJNZ

Page 4: Chapter 3 JUMP, LOOP and CALL Instructions

44 2002 Anant Oonsivilai2002 Anant Oonsivilai

Loop inside a Loop (Nested Loop inside a Loop (Nested Loop)Loop)

Page 5: Chapter 3 JUMP, LOOP and CALL Instructions

55 2002 Anant Oonsivilai2002 Anant Oonsivilai

8051 Conditional Jump Instructions8051 Conditional Jump Instructions

Page 6: Chapter 3 JUMP, LOOP and CALL Instructions

66 2002 Anant Oonsivilai2002 Anant Oonsivilai

Conditional Jump ExampleConditional Jump Example

- JNZ , JNC

Page 7: Chapter 3 JUMP, LOOP and CALL Instructions

77 2002 Anant Oonsivilai2002 Anant Oonsivilai

Conditional Jump ExampleConditional Jump Example

Page 8: Chapter 3 JUMP, LOOP and CALL Instructions

88 2002 Anant Oonsivilai2002 Anant Oonsivilai

Unconditional Jump InstructionsUnconditional Jump Instructions

All conditional jumps are short jumpsAll conditional jumps are short jumps Target address within -128 to +127 of PCTarget address within -128 to +127 of PC

LJMPLJMP (long jump): 3-byte instruction (long jump): 3-byte instruction 2-byte target address: 0000 to FFFFH2-byte target address: 0000 to FFFFH Original 8051 has only 4KB on-chip ROMOriginal 8051 has only 4KB on-chip ROM

SJMPSJMP (short jump): 2-byte instruction (short jump): 2-byte instruction 1-byte relative address: -128 to +1271-byte relative address: -128 to +127

Page 9: Chapter 3 JUMP, LOOP and CALL Instructions

99 2002 Anant Oonsivilai2002 Anant Oonsivilai

Calculating Short Jump AddressesCalculating Short Jump Addresses

Page 10: Chapter 3 JUMP, LOOP and CALL Instructions

1010 2002 Anant Oonsivilai2002 Anant Oonsivilai

Calculating Short Jump AddressesCalculating Short Jump Addresses

Page 11: Chapter 3 JUMP, LOOP and CALL Instructions

1111 2002 Anant Oonsivilai2002 Anant Oonsivilai

Call InstructionsCall Instructions

LCALLLCALL (long call): 3-byte instruction (long call): 3-byte instruction 2-byte address2-byte address Target address within 64K-byte rangeTarget address within 64K-byte range

ACALLACALL (absolute call): 2-byte instruction (absolute call): 2-byte instruction 11-bit address11-bit address Target address within 2K-byte rangeTarget address within 2K-byte range

Page 12: Chapter 3 JUMP, LOOP and CALL Instructions

1212 2002 Anant Oonsivilai2002 Anant Oonsivilai

LCALLLCALL

Page 13: Chapter 3 JUMP, LOOP and CALL Instructions

1313 2002 Anant Oonsivilai2002 Anant Oonsivilai

CALL Instruction & Role of StackCALL Instruction & Role of Stack

Page 14: Chapter 3 JUMP, LOOP and CALL Instructions

1414 2002 Anant Oonsivilai2002 Anant Oonsivilai

CALL Instruction & Role of StackCALL Instruction & Role of Stack

Page 15: Chapter 3 JUMP, LOOP and CALL Instructions

1515 2002 Anant Oonsivilai2002 Anant Oonsivilai

Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines

Page 16: Chapter 3 JUMP, LOOP and CALL Instructions

1616 2002 Anant Oonsivilai2002 Anant Oonsivilai

Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines

Page 17: Chapter 3 JUMP, LOOP and CALL Instructions

1717 2002 Anant Oonsivilai2002 Anant Oonsivilai

Using PUSH & POP in SubroutinesUsing PUSH & POP in Subroutines

Page 18: Chapter 3 JUMP, LOOP and CALL Instructions

1818 2002 Anant Oonsivilai2002 Anant Oonsivilai

Calling SubroutinesCalling Subroutines

Page 19: Chapter 3 JUMP, LOOP and CALL Instructions

1919 2002 Anant Oonsivilai2002 Anant Oonsivilai

Calling SubroutinesCalling Subroutines

Page 20: Chapter 3 JUMP, LOOP and CALL Instructions

2020 2002 Anant Oonsivilai2002 Anant Oonsivilai

ACALL (absolute call)ACALL (absolute call)

Page 21: Chapter 3 JUMP, LOOP and CALL Instructions

2121 2002 Anant Oonsivilai2002 Anant Oonsivilai

Programming EfficientlyProgramming Efficiently

Page 22: Chapter 3 JUMP, LOOP and CALL Instructions

2222 2002 Anant Oonsivilai2002 Anant Oonsivilai

Time Delay Generation & CalculationTime Delay Generation & Calculation

1 instruction = 1 instruction = nn machine cycle machine cycle

1 machine cycle = 12 clock cycles1 machine cycle = 12 clock cycles

Page 23: Chapter 3 JUMP, LOOP and CALL Instructions

2323 2002 Anant Oonsivilai2002 Anant Oonsivilai

Delay CalculationDelay Calculation

Page 24: Chapter 3 JUMP, LOOP and CALL Instructions

2424 2002 Anant Oonsivilai2002 Anant Oonsivilai

Delay Calculation ExampleDelay Calculation Example

Page 25: Chapter 3 JUMP, LOOP and CALL Instructions

2525 2002 Anant Oonsivilai2002 Anant Oonsivilai

Delay Calculation ExampleDelay Calculation Example

Page 26: Chapter 3 JUMP, LOOP and CALL Instructions

2626 2002 Anant Oonsivilai2002 Anant Oonsivilai

Increasing Delay Using NOPIncreasing Delay Using NOP

Page 27: Chapter 3 JUMP, LOOP and CALL Instructions

2727 2002 Anant Oonsivilai2002 Anant Oonsivilai

Large Delay Using Nested LoopLarge Delay Using Nested Loop