【发布时间】:2022-11-12 05:44:39
【问题描述】:
我有这块:
.global main
.data
helloworld: .ascii "Hello world\n"
helloworldend:
goodluck: .asciz "Good Luck!\n"
goodluckend:
.text
main:
# printf(helloworld)
movq $1, %rax
movq $1, %rdi
movq $helloworld, %rsi
movq $helloworldend-helloworld, %rdx
syscall
# printf(goodluck)
movq $1, %rax
movq $1, %rdi
movq $goodluck, %rsi
movq $goodluckend-goodluck, %rdx
syscall
xorq %rax, %rax
ret
而且我必须以某种方式使其也打印“Hello Luck”而不更改数据部分。 我所做的是在主目录中添加一个新的数据部分:
...
main:
.section .data
msg: .ascii "Hello Luck\n"
msgend:
.section .text
start:
movq $1, %rax
movq $1, %rdi
movq $msg, %rsi
movq $msgend-msg, %rdx
syscall
...
显然这有效,但我不确定这是不是这个想法。有没有不同的方式来打印它而不添加新的数据部分并且不改变现有的?
【问题讨论】:
-
您当然可以在运行时从代码中更改字符串。
-
使用商店更改字符串是否算作更改数据部分?您可以打印部分字符串,然后在运行时制作其余部分并打印吗?目前还不清楚我们在玩什么规则。
-
@MargaretBloom 根本无法更改数据
-
@Jester 怎么样?到目前为止,我是使用 C、C++ 和 python 的新手
-
如果您不能真正更改数据(无论是在运行时),那么您必须打印
Good,然后在堆栈上创建day\n并打印它。或者完全制作整个字符串。
标签: assembly intel cpu-architecture