Assembly Language Programming
Assembly Language Programming
Assembly Language
Programming
The different jumps
• Rjmp: +/- 2k words. It can reach 4k words or 8k bytes of
program memory. Example:rjmp go_here
• Ijmp: "Indirect Jump" to (Z). jump to the address pointed
to by the Z index register pair. . Example:
ldi ZL, low(go_there)
ldi ZH, high(go_there)
ijmp
• Jmp: "Jump". While rjmp is limited to +/- 2k words, jmp
can be used to jump anywhere within the code space.
The disadvantage over rjmp is that jmp needs 2 words of
code space, while rjmp needs just one word.
Example: jmp go_far
Subroutine Calls
• Rcall "Relative Call Subroutine“. +/- 2k words. . When
rcall is executed, the return address is pushed onto the
stack. . It needs 1 word of program space.
Example: rcall my_subroutine
• Icall "Indirect Call to (Z)“The return address is pushed
onto the stack. icall needs two words of code space.
Example: ldi ZL, low(my_subroutine)
ldi ZH, high(my_subroutine)
icall
• Call It works just like rcall (regarding the stack) and
needs 2 words of code space.
Example: call my_subroutine
Return Instructions
• Ret and reti: These instructions have to placed
at the end of any subroutine or Interrupt Service
Routine (ISR).
• The return address is popped from the stack and
program execution goes on from there. reti is
used after ISRs. Basically it works like ret, but it
also sets the I Flag (Global Interrupt Enable
Flag) in the status register. When an ISR is
entered, this bit is cleared by hardware.
Indirect Calls/Jumps
ldi ZL, low(led_on) ; load Z with address to call
ldi ZH, high(led_on) ;
icall ; call led_on
;
led_on: ;this is where Z points at and therefore the address to call
ldi r16, 0b11111110
out PortA, r16
ret
Indirect Calls/Jumps
• Indirect jumps/calls can also be used to make big case
structures faster. The value we want to process is
multiplied by the number of words a jmp needs (which is
two) and then added to the base address of our table.
Decrement version:
ldi r16, 10 ; load r16 with desired number of iterations
loop2:
(insert loop code) ; do whatever the loop does...