Skip to content

Commit 45d77ea

Browse files
committed
Add an example of negative offset on "Constant"
1 parent 2e6242d commit 45d77ea

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

riscv-asm.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,19 +465,25 @@ The following example shows loading a constant using the `%hi` and
465465
`%lo` assembler functions.
466466

467467
```assembly
468-
.equ UART_BASE, 0x40003080
468+
.equ UART0_BASE, 0x40003080 # positive offset
469+
.equ UART1_BASE, 0x40003880 # negative offset
469470
470-
lui a0, %hi(UART_BASE)
471-
addi a0, a0, %lo(UART_BASE)
471+
lui a0, %hi(UART0_BASE)
472+
addi a0, a0, %lo(UART0_BASE)
473+
474+
lui a0, %hi(UART1_BASE)
475+
addi a0, a0, %lo(UART1_BASE)
472476
```
473477

474478
Which generates the following assembler output
475479
as seen by `objdump`:
476480

477481
```assembly
478482
0000000000000000 <.text>:
479-
0: 40003537 lui a0,0x40003
480-
4: 08050513 addi a0,a0,128 # 40003080 <UART_BASE>
483+
0: 40003537 lui a0,0x40003
484+
4: 08050513 addi a0,a0,128 # 40003080 <UART0_BASE>
485+
8: 40004537 lui a0,0x40004
486+
c: 88050513 addi a0,a0,-1920 # 40003880 <UART1_BASE>
481487
```
482488

483489
Function Calls

0 commit comments

Comments
 (0)