MCDSP 9
MCDSP 9
MOV B,#0AH
DIV AB
SWAP A
ORL A,B
A B
15H 0AH
02 01
20 01 HEX to BCD conversion
21 01
BRANCHING INSTRUCTIONS
Jumps can
1. be conditional or unconditional
2. be relative or absolute short or absolute long (range of jump)
3. test bit or byte
1. Only 1 byte of jump address needs to be specified in the 2's complement form, ie. For jumping
ahead, the range is 0 to 127 and for jumping back, the range is -1 to -128.
2. Specifying only one byte reduces the size of the instruction and speeds up program execution.
3. The program with relative jumps can be relocated without reassembling to generate absolute
jump addresses.
Short jump range (-128 to 127 from the instruction following the jump instruction)
Why would anybody want to use the SJMP or AJMP command which have restrictions as to how
far they can jump if they do the same thing as the LJMP command which can jump anywhere in
memory?"
The LJMP command requires three bytes of code memory whereas both the SJMP and AJMP
commands require only two. Thus, if you are developing an application that has memory
restrictions you can often save quite a bit of memory using the 2-byte AJMP/SJMP instructions
instead of the 3-byte instruction.
Infinite Loops
if (A) < (M)addr then jump to the relative address & CY is set
if (A) > (M)addr then jump to the relative address & CY is reset
• Decrement and Jump if Not Zero – DJNZ
– Decrement the first operand by 1 and jump to
the location identified by the second operand
if the resulting value is not zero.
• No Operation
– NOP
Implementing subroutine:
1. Initialize SP
2. Use CALL instruction in main program
3. Use RETURN instruction in subroutine
Subroutines
call to the subroutine
Main: ...
acall sublabel
...
...
sublabel:... the subroutine
...
ret
Why Subroutines?
• Subroutines allow us to have "structured" assembly language programs.
• This is useful for breaking a large design into manageable parts.
• It saves code space when subroutines can be called many times in the same program.
• Pop the return address (top 2 bytes) from the stack into PC, decrement the SP by 2
and continue execution at this new address.
• Used to return from subroutine previously entered by instructions LCALL or ACALL.
• Pop the return address (top 2 bytes) from the stack into PC, decrement SP by 2 and
continue execution at the new address retrieved from the stack.
• This is used to return from ISR or interrupt handler.
• Restore the interrupt logic to accept additional interrupts at the same priority level
as the one just processed.
• The PSW is not automatically restored.
Thank You
16