@@ -21,7 +21,8 @@ in the current code model.
2121=== Small code model
2222
2323The small code model, or `medlow`, allows the code to address the whole RV32
24- address space or the lower 2 GiB of the RV64 address space.
24+ address space or the lower 2 GiB and highest 2GiB of the RV64 address space
25+ (`0xFFFFFFFF7FFFF800` ~ `0xFFFFFFFFFFFFFFFF` and `0x0` ~ `0x000000007FFFF7FF`).
2526By using the instructions `lui` and `ld` or `st`, when referring to an object, or
2627`addi`, when calculating an address literal, for example,
2728a 32-bit address literal can be produced.
@@ -44,6 +45,20 @@ an address in the `medlow` code model.
4445 addi a0, a0, %lo(symbol)
4546----
4647
48+ NOTE: The ranges on RV64 are not `0x0` ~ `0x000000007FFFFFFF` and
49+ `0xFFFFFFFF80000000` ~ `0xFFFFFFFFFFFFFFFF` due to RISC-V's sign-extension of
50+ immediates; the following code fragments show where the ranges come from:
51+ [,asm]
52+ ----
53+ # Largest postive number:
54+ lui a0, 0x7ffff # a0 = 0x7ffff000
55+ addi a0, 0x7ff # a0 = a0 + 2047 = 0x000000007FFFF7FF
56+
57+ # Smallest negative number:
58+ lui a0, 0x80000 # a0 = 0xffffffff80000000
59+ addi a0, a0, -0x800 # a0 = a0 + -2048 = 0xFFFFFFFF7FFFF800
60+ ----
61+
4762=== Medium code model
4863
4964The medium code model, or `medany`, allows the code to address the range
0 commit comments