# `sub`

[RISC-V Documentation](https://asm-editor.specy.app/documentation/risc-v.md) › [Instructions](https://asm-editor.specy.app/documentation/risc-v/instruction.md)

Web page: https://asm-editor.specy.app/documentation/risc-v/instruction/sub

**Subtraction**

Category: Arithmetic

Subtracts the third register from the second and stores the difference in the first.

[RISC-V manual: sub](https://docs.riscv.org/reference/isa/v20260120/unpriv/rv32.html#norm:sub_op)

Used in: [The RISC-V instruction set](https://asm-editor.specy.app/learn/courses/risc-v/introduction/the-risc-v-instruction-set.md) (RISC-V assembly), [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/risc-v/think-in-assembly/arithmetic-logic-and-bits.md) (RISC-V assembly), [ecall](https://asm-editor.specy.app/learn/courses/risc-v/talking-to-the-outside-world/ecall.md) (RISC-V assembly), [Moving values around](https://asm-editor.specy.app/learn/courses/risc-v/examples/moving-values.md) (RISC-V assembly), [The bigger of two numbers](https://asm-editor.specy.app/learn/courses/risc-v/examples/if-else.md) (RISC-V assembly), [Length of a string](https://asm-editor.specy.app/learn/courses/risc-v/examples/string-length.md) (RISC-V assembly), [A subroutine with its arguments in registers](https://asm-editor.specy.app/learn/courses/risc-v/examples/subroutine-with-register-arguments.md) (RISC-V assembly), [A jump table](https://asm-editor.specy.app/learn/courses/risc-v/examples/jump-table.md) (RISC-V assembly), [Read two numbers and print their sum](https://asm-editor.specy.app/learn/courses/risc-v/examples/sum-of-two-numbers.md) (RISC-V assembly), [Drawing shapes on the screen](https://asm-editor.specy.app/learn/courses/risc-v/examples/drawing-on-the-screen.md) (RISC-V assembly)

## Forms

- `sub t1, t2, t3`

## Operands

- `t1`: Any integer register, `x0` to `x31`, or its named alias, such as `zero`, `t0` or `t6`.
- `t2`: An integer register. It may be the same register as `t1`.
- `t3`: An integer register. It may be the same register as `t1`.

## Example

```riscv
.text
li t0, 13
li t1, 5
# t0=13, t1=5; sub writes 8 to t2.
sub t2, t0, t1
```
