Skip to content

Commit 62250eb

Browse files
committed
Add an example of negative offset on "Constant"
1 parent e1992eb commit 62250eb

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
@@ -464,19 +464,25 @@ The following example shows loading a constant using the `%hi` and
464464
`%lo` assembler functions.
465465

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

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

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

482488
Function Calls

0 commit comments

Comments
 (0)