0% found this document useful (0 votes)
12 views16 pages

MCDSP 9

Very good morning

Uploaded by

pharjikhata001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views16 pages

MCDSP 9

Very good morning

Uploaded by

pharjikhata001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

EEL531

µ-Controller and Digital


Signal Processor
Assembly Language of 8051
Siba Kumar Patro
Ex. Store the higher nibble of R7 in to both nibbles of R6
MOV A, R7 ; get the content in acc
ANL A, #0F0H; mask lower bit
MOV R6, A ; send it to r6
SWAP A ; xchange upper and lower nibbles of acc
ORL A, R6 ; OR operation
MOV R6, A ; finally load content in r6

Assume A contains 15H. What is the purpose of the program?

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

Jump and Call Instructions


• The 8051 provides four different types of unconditional jump instructions:

– Relative Jump – SJMP raddr


• Uses an 8-bit signed offset relative to the address of 1st byte of the next instruction.
– Absolute Long Jump – LJMP laddr
• Uses a 16-bit address.
• 3 byte instruction capable of referencing any location in the entire 64K of program memory.

– Absolute short Jump – AJMP saddr


• Uses an 11-bit address
• 2 byte instruction
– The upper 3-bits of the address combine with the 5-bit opcode to form the 1st byte
and the lower 8-bits of the address form the 2nd byte.
• The 11-bit address is substituted for the lower 11-bits of the PC to calculate the 16-bit address of
the target.
– The location referenced must be within the 2K Byte memory page containing the
AJMP instruction.
– if the AJMP command is at code memory location 0650h, it can only do a jump to
addresses 0000h through 07FFh

– Indirect Jump – JMP 16bit-addr


• JMP @A + DPTR
The advantages of the relative jump are as follows:

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.

Disadvantages of the absolute jump:

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

Start: mov C, p3.7


mov p1.6, C
sjmp Start
Microcontroller application programs are almost always infinite loops!
• The 8051 supports 5 different conditional
jump instructions.
– ALL conditional jump instructions use an 8-bit
signed offset.

– Jump on Zero – JZ / JNZ raddr


• Jump relative if the A == 0 / A != 0
– Byte Testing (there is no zero flag)

– Jump on Carry – JC / JNC raddr


• Jump relative if the C flag is set / cleared.
• Bit testing
– Jump on Bit –
JB / JNB b, raddr
• Jump if the specified bit is set / cleared.
• Any addressable bit can be specified.

– Jump if the Bit is set then Clear the bit –


JBC b, raddr
• Jump if the specified bit is set.
• Then clear the bit.
• Compare and Jump if Not Equal – CJNE
– Compare the magnitude of the two operands
and jump if they are not equal.
• The values are considered to be unsigned.
• The Carry flag is set / cleared appropriately.

• CJNE A, addr, raddr


• CJNE A, #data, raddr
• CJNE Rn, #data, raddr
• CJNE @Ri, #data, raddr
if (A) ≠ (M)addr then jump to the relative address

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.

• DJNZ Rn, raddr


• DJNZ direct, raddr

• 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.

• The 8051 provides 2 forms for the CALL instruction:


– Absolute short Call – ACALL saddr
• Uses an 11-bit address similar to AJMP
• The subroutine must be within the same 2K page.

– Absolute Long Call – LCALL laddr


• Uses a 16-bit address similar to LJMP
• The subroutine can be anywhere.

– Both forms push the 16-bit address of the next instruction on


the stack and update the stack pointer.
• The 8051 provides 2 forms for the return instruction:
– Return from subroutine – RET

• 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.

– Return from ISR – RETI

• 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

You might also like