我有這塊:
.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
...
顯然這可行,但我不確定這是不是這個想法。有沒有不同的方式來列印它而不添加新的資料部分并且不更改現有的資料部分?
uj5u.com熱心網友回復:
內核系統呼叫sys_write需要RDX=number of bytes 和RSI=pointer 指向字串,它不必以 null 結尾,所以只需更改這兩個暫存器:
main:
# printf("Hello ")
movq $1, %rax
movq $1, %rdi
movq $helloworld, %rsi ; Pointer to "Hello World\n".
movq $6, %rdx ; Size of "Hello ".
syscall
# printf("Luck\n")
movq $1, %rax
movq $goodluck 5, %rsi ; Pointer to "Luck\n".
movq $5, %rdx ; Size of "Luck\n".
syscall
xorq %rax, %rax
ret
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/530352.html
標籤:Intel Collective 部件英特尔cpu架构
