Skip to content

Commit 636994b

Browse files
committed
Corrected the memory load commands for Chapter 5
1 parent ca4f8d3 commit 636994b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Chapter 5/codesnippets.s

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,22 @@ l5: .byte 0x3F
3333
.text
3434

3535
_start:
36-
l6: ADRP X1, helloworld@GOTPAGE
36+
l6: ADRP X1, helloworld@PAGE
37+
ADD X1, X1, helloworld@PAGEOFF
3738
ADR X1, helloworld2
3839

3940
l7: LDR X1, =0x1234ABCD1234ABCD
4041

4142
l8:
4243
// load the address of mynumber into X1
43-
ADRP X1, mynumber@GOTPAGE
44+
ADRP X1, mynumber@PAGE
45+
ADD X1, X1, mynumber@PAGEOFF
4446
// load the word stored at mynumber into X2
4547
LDR X2, [X1]
4648

4749

48-
l9: ADRP X1, arr1@GOTPAGE
50+
l9: ADRP X1, arr1@PAGE
51+
ADD X1, X1, arr1@PAGEOFF
4952

5053
l10: // Load the first element
5154
LDR W2, [X1]
@@ -74,12 +77,14 @@ l13: // Our array is of WORDs. 2 is the index
7477

7578
l14: LDR W2, [X1, #(2 * 4)]!
7679

77-
ADRP X2, arr1@GOTPAGE
80+
ADRP X2, arr1@PAGE
81+
ADD X2, X2, arr1@PAGEOFF
7882
l15: // Load X1 with the memory pointed to by X2
7983
// Then do X2 = X2 + 2
8084
LDR X1, [X2], #2
8185

82-
l16: ADRP X1, myoctaword@GOTPAGE
86+
l16: ADRP X1, myoctaword@PAGE
87+
ADD X1, myoctaword@PAGEOFF
8388
LDP X2, X3, [X1]
8489
STP X2, X3, [X1]
8590

Chapter 5/upper.s

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
.global _start // Provide program starting address to linker
1313
.p2align 2
1414

15-
_start: ADRP X4, instr@GOTPAGE // start of input string
16-
ADRP X3, outstr@GOTPAGE // address of output string
15+
_start: ADRP X4, instr@PAGE // start of input string
16+
ADD X4, X4, instr@PAGEOFF
17+
ADRP X3, outstr@PAGE // address of output string
18+
ADD X3, X3, outstr@PAGEOFF
1719
// The loop is until byte pointed to by X1 is non-zero
1820
loop: LDRB W5, [X4], #1 // load character and increment pointer
1921
// If W5 > 'z' then goto cont
@@ -32,7 +34,8 @@ cont: // end if
3234
// Setup the parameters to print our hex number
3335
// and then call the Kernel to do it.
3436
MOV X0, #1 // 1 = StdOut
35-
ADRP X1, outstr@GOTPAGE // string to print
37+
ADRP X1, outstr@PAGE // string to print
38+
ADD X1, X1, outstr@PAGEOFF
3639
SUB X2, X3, X1 // get the length by subtracting the pointers
3740
MOV X16, #4 // Unix write system call
3841
SVC #0x80 // Call kernel to output the string

0 commit comments

Comments
 (0)