Skip to content

Commit 454dfba

Browse files
committed
fix: debug format string
The current format string's conversion specifier %c and x1 with '0' added to it do not properly handle cases where reg is x10 to x30. This takes the value passed to x1 as an integer and processes it with the conversion specifier %u.
1 parent daf4340 commit 454dfba

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Chapter 09/debug.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
stp X14, X15, [SP, #-16]!
1515
stp X16, X17, [SP, #-16]!
1616
stp X18, LR, [SP, #-16]!
17+
mov X1, #\reg // for the %u
1718
mov X2, X\reg // for the %d
1819
mov X3, X\reg // for the %x
19-
mov X1, #\reg
20-
add X1, X1, #'0' // for %c
2120
str X1, [SP, #-32]! // Move the stack pointer four doublewords (32 bytes) down and push X1 onto the stack
2221
str X2, [SP, #8] // Push X2 to one doubleword above the current stack pointer
2322
str X3, [SP, #16] // Push X3 to two doublewords above the current stack pointer
@@ -67,6 +66,6 @@
6766
.endm
6867

6968
.data
70-
ptfStr: .asciz "X%c = %32ld, 0x%016lx\n"
69+
ptfStr: .asciz "X%-2u = %32ld, 0x%016lx\n"
7170
.align 4
7271
.text

Chapter 11/debug.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
stp X14, X15, [SP, #-16]!
1515
stp X16, X17, [SP, #-16]!
1616
stp X18, LR, [SP, #-16]!
17+
mov X1, #\reg // for the %c
1718
mov X2, X\reg // for the %d
1819
mov X3, X\reg // for the %x
19-
mov X1, #\reg
20-
add X1, X1, #'0' // for %c
2120
str X1, [SP, #-32]! // Move the stack pointer four doublewords (32 bytes) down and push X1 onto the stack
2221
str X2, [SP, #8] // Push X2 to one doubleword above the current stack pointer
2322
str X3, [SP, #16] // Push X3 to two doublewords above the current stack pointer
@@ -67,6 +66,6 @@
6766
.endm
6867

6968
.data
70-
ptfStr: .asciz "X%c = %32ld, 0x%016lx\n"
69+
ptfStr: .asciz "X%-2u = %32ld, 0x%016lx\n"
7170
.align 4
7271
.text

0 commit comments

Comments
 (0)