# `rtd`

[M68K Documentation](https://asm-editor.specy.app/documentation/m68k.md) › [Instructions](https://asm-editor.specy.app/documentation/m68k/instruction.md)

Web page: https://asm-editor.specy.app/documentation/m68k/instruction/rtd

**Return and deallocate** · 68010

Category: Control flow

Returns from a subroutine and removes arguments from the stack.

68010 and 68020 only: select `opt p=68010` before any code or data

## Flags

| Flag | Effect |
| --- | --- |
| X | not changed |
| N | not changed |
| Z | not changed |
| V | not changed |
| C | not changed |

## Forms

- `rtd #imm`

## Operands

- [`#imm`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/immediate.md): A signed 16-bit number of bytes added to the stack pointer once the return address is popped: the size of the arguments, for example `#8`.

## Description

It pops the return address, as [rts](https://asm-editor.specy.app/documentation/m68k/instruction/rts.md) does, then adds a signed 16-bit byte count to the stack pointer. If the caller pushed 8 bytes of arguments, `rtd #8` removes them before returning, so the caller needs no stack adjustment after the call.

## Example

```m68k
opt p=68010
* --- A subroutine that removes its own arguments ---
move.l #5, -(sp) ; first argument
move.l #7, -(sp) ; second argument
bsr add_args
move.l d0, d1 ; d1 = 12, and sp is back where it was before the pushes
bra END

add_args:
    move.l 4(sp), d0 ; the second argument, just above the return address
    add.l 8(sp), d0 ; plus the first
    rtd #8 ; return, then take the 8 bytes of arguments off the stack

END:
```
